summaryrefslogtreecommitdiff
path: root/libguile/async.c
diff options
context:
space:
mode:
Diffstat (limited to 'libguile/async.c')
-rw-r--r--libguile/async.c114
1 files changed, 57 insertions, 57 deletions
diff --git a/libguile/async.c b/libguile/async.c
index fc03078e7..e10bc562b 100644
--- a/libguile/async.c
+++ b/libguile/async.c
@@ -1,47 +1,48 @@
-/* Copyright (C) 1995,1996,1997,1998,2000,2001, 2002, 2004, 2006, 2008,
- * 2009, 2010, 2011, 2014 Free Software Foundation, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3 of
- * the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
+/* Copyright 1995-1998,2000-2002,2004,2006,2008-2011,2014,2018-2019
+ Free Software Foundation, Inc.
+
+ This file is part of Guile.
+
+ Guile is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ Guile is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with Guile. If not, see
+ <https://www.gnu.org/licenses/>. */
+
#ifdef HAVE_CONFIG_H
-# include <config.h>
+# include <config.h>
#endif
-#include "libguile/_scm.h"
-#include "libguile/atomics-internal.h"
-#include "libguile/eval.h"
-#include "libguile/throw.h"
-#include "libguile/smob.h"
-#include "libguile/dynwind.h"
-#include "libguile/deprecation.h"
-
-#include "libguile/validate.h"
-#include "libguile/async.h"
-
-#ifdef HAVE_STRING_H
+#include <full-write.h>
#include <string.h>
-#endif
#include <unistd.h>
-#include <full-write.h>
+#include "atomics-internal.h"
+#include "deprecation.h"
+#include "dynwind.h"
+#include "eval.h"
+#include "gsubr.h"
+#include "list.h"
+#include "pairs.h"
+#include "smob.h"
+#include "throw.h"
+
+#include "async.h"
+
+
/* {Asynchronous Events}
*
* Asyncs are used to run arbitrary code at the next safe point in a
@@ -55,7 +56,7 @@
*/
void
-scm_i_async_push (scm_i_thread *t, SCM proc)
+scm_i_async_push (scm_thread *t, SCM proc)
{
SCM asyncs;
@@ -85,7 +86,7 @@ scm_i_async_push (scm_i_thread *t, SCM proc)
disable that newly-severed tail by setting its cdr to #f. Not so
nice, but oh well. */
asyncs = scm_atomic_ref_scm (&t->pending_asyncs);
- do
+ while (1)
{
/* Traverse the asyncs list atomically. */
SCM walk;
@@ -94,14 +95,18 @@ scm_i_async_push (scm_i_thread *t, SCM proc)
walk = scm_atomic_ref_scm (SCM_CDRLOC (walk)))
if (scm_is_eq (SCM_CAR (walk), proc))
return;
+
+ SCM expected = asyncs;
+ asyncs = scm_atomic_compare_and_swap_scm
+ (&t->pending_asyncs, asyncs, scm_cons (proc, asyncs));
+ if (scm_is_eq (asyncs, expected))
+ return;
}
- while (!scm_atomic_compare_and_swap_scm (&t->pending_asyncs, &asyncs,
- scm_cons (proc, asyncs)));
}
/* Precondition: there are pending asyncs. */
SCM
-scm_i_async_pop (scm_i_thread *t)
+scm_i_async_pop (scm_thread *t)
{
while (1)
{
@@ -122,8 +127,9 @@ scm_i_async_pop (scm_i_thread *t)
/* Sever the tail. */
if (scm_is_false (penultimate_pair))
{
- if (!scm_atomic_compare_and_swap_scm (&t->pending_asyncs, &asyncs,
- SCM_EOL))
+ if (!scm_is_eq (asyncs,
+ scm_atomic_compare_and_swap_scm (&t->pending_asyncs,
+ asyncs, SCM_EOL)))
continue;
}
else
@@ -139,7 +145,7 @@ scm_i_async_pop (scm_i_thread *t)
void
scm_async_tick (void)
{
- scm_i_thread *t = SCM_I_CURRENT_THREAD;
+ scm_thread *t = SCM_I_CURRENT_THREAD;
if (t->block_asyncs)
return;
@@ -162,7 +168,7 @@ struct scm_thread_wake_data {
};
int
-scm_i_prepare_to_wait (scm_i_thread *t,
+scm_i_prepare_to_wait (scm_thread *t,
struct scm_thread_wake_data *wake)
{
if (t->block_asyncs)
@@ -182,13 +188,13 @@ scm_i_prepare_to_wait (scm_i_thread *t,
}
void
-scm_i_wait_finished (scm_i_thread *t)
+scm_i_wait_finished (scm_thread *t)
{
scm_atomic_set_pointer ((void **)&t->wake, NULL);
}
int
-scm_i_prepare_to_wait_on_fd (scm_i_thread *t, int fd)
+scm_i_prepare_to_wait_on_fd (scm_thread *t, int fd)
{
struct scm_thread_wake_data *wake;
wake = scm_gc_typed_calloc (struct scm_thread_wake_data);
@@ -204,7 +210,7 @@ scm_c_prepare_to_wait_on_fd (int fd)
}
int
-scm_i_prepare_to_wait_on_cond (scm_i_thread *t,
+scm_i_prepare_to_wait_on_cond (scm_thread *t,
scm_i_pthread_mutex_t *m,
scm_i_pthread_cond_t *c)
{
@@ -241,7 +247,7 @@ SCM_DEFINE (scm_system_async_mark_for_thread, "system-async-mark", 1, 1, 0,
"signal handlers.")
#define FUNC_NAME s_scm_system_async_mark_for_thread
{
- scm_i_thread *t;
+ scm_thread *t;
struct scm_thread_wake_data *wake;
if (SCM_UNBNDP (thread))
@@ -320,14 +326,14 @@ SCM_DEFINE (scm_noop, "noop", 0, 0, 1,
static void
increase_block (void *data)
{
- scm_i_thread *t = data;
+ scm_thread *t = data;
t->block_asyncs++;
}
static void
decrease_block (void *data)
{
- scm_i_thread *t = data;
+ scm_thread *t = data;
if (--t->block_asyncs == 0)
scm_async_tick ();
}
@@ -335,7 +341,7 @@ decrease_block (void *data)
void
scm_dynwind_block_asyncs (void)
{
- scm_i_thread *t = SCM_I_CURRENT_THREAD;
+ scm_thread *t = SCM_I_CURRENT_THREAD;
scm_dynwind_rewind_handler (increase_block, t, SCM_F_WIND_EXPLICITLY);
scm_dynwind_unwind_handler (decrease_block, t, SCM_F_WIND_EXPLICITLY);
}
@@ -343,7 +349,7 @@ scm_dynwind_block_asyncs (void)
void
scm_dynwind_unblock_asyncs (void)
{
- scm_i_thread *t = SCM_I_CURRENT_THREAD;
+ scm_thread *t = SCM_I_CURRENT_THREAD;
if (t->block_asyncs == 0)
scm_misc_error ("scm_with_unblocked_asyncs",
"asyncs already unblocked", SCM_EOL);
@@ -426,11 +432,5 @@ scm_c_call_with_unblocked_asyncs (void *(*proc) (void *data), void *data)
void
scm_init_async ()
{
-#include "libguile/async.x"
+#include "async.x"
}
-
-/*
- Local Variables:
- c-file-style: "gnu"
- End:
-*/