guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Thread Plug-in Support #3


From: NIIBE Yutaka
Subject: [PATCH] Thread Plug-in Support #3
Date: Wed, 11 Apr 2001 11:19:23 +0900 (JST)

Patch piece #3.

This piece includes interface cleanup.  I guess that this cleanup was
designed by Mikael and done by Dirk, right?  All the work has beeen
done by Dirk, last year.  I just apply his work to current code base.

Well, I did only one actually, the change of goops.c, just following
Dirk's change of readline.

No regression with "make check".  

guile-readline/ChangeLog

        Follow the rename of thread interface in C (_c_ is inserted).
        * readline.c (reentry_barrier): Call scm_c_mutex_lock/unlock.
        (scm_init_readline): Call scm_c_mutex_init.

Index: guile-readline/readline.c
===================================================================
RCS file: /cvs/guile/guile-core/guile-readline/readline.c,v
retrieving revision 1.31
diff -u -r1.31 readline.c
--- guile-readline/readline.c   2001/04/10 23:48:27     1.31
+++ guile-readline/readline.c   2001/04/11 02:10:13
@@ -226,14 +226,14 @@
   int reentryp = 0;
 #ifdef USE_THREADS
   /* We should rather use scm_mutex_try_lock when it becomes available */
-  scm_mutex_lock (&reentry_barrier_mutex);
+  scm_c_mutex_lock (&reentry_barrier_mutex);
 #endif
   if (in_readline)
     reentryp = 1;
   else
     ++in_readline;
 #ifdef USE_THREADS
-  scm_mutex_unlock (&reentry_barrier_mutex);
+  scm_c_mutex_unlock (&reentry_barrier_mutex);
 #endif
   if (reentryp)
     scm_misc_error (s_scm_readline, "readline is not reentrant", SCM_EOL);
@@ -553,7 +553,7 @@
 #endif
 
 #ifdef USE_THREADS
-  scm_mutex_init (&reentry_barrier_mutex);
+  scm_c_mutex_init (&reentry_barrier_mutex);
 #endif
   scm_init_opts (scm_readline_options,
                 scm_readline_opts,
------------------------

libguile/ChangeLog

        Follow the rename of thread interface of C, and of Scheme.
        * goops.c (go_to_hell, go_to_heaven): Call
        scm_c_mutex_lock/unlock.
        (scm_init_goops): Call scm_c_mutex_init.
        (lock_cache_mutex): Call scm_mutex_lock.
        (unlock_cache_mutex): Call scm_mutex_unlock.

        * coop-defs.h (scm_c_mutex_init, scm_c_mutex_lock,
        scm_c_mutex_trylock, scm_c_mutex_unlock, scm_c_mutex_destroy,
        scm_c_cond_init, scm_c_cond_wait, scm_c_cond_timedwait,
        scm_c_cond_signal, scm_c_cond_broadcast, scm_c_cond_destroy,
        scm_c_key_create, scm_c_setspecific, scm_c_getspecific,
        scm_c_key_delete): Rename of thread interface in C (_c_ is
        inserted).

        * threads.h (scm_thread_p, scm_mutex_p, scm_cond_p): New
        declarations.
        (scm_thread_yield, scm_thread_join, scm_mutex_lock, scm_mutex_unlock, 
        scm_make_cond, scm_cond_wait, scm_cond_signal): Rename.

        * threads.c (scm_thread_p, scm_mutex_p, scm_cond_p): New
        functions.
        (s_yield, s_join_thread, s_lock_mutex, s_unlock_mutex,
        s_make_condition_variable, s_wait_condition_variable,
        s_signal_condition_variable): Deprecated.

        * coop-threads.c (scm_thread_join): Renamed from scm_join_thread.
        Define with SCM_DEFINE.
        (scm_thread_yield): Renamed from scm_yield. Define with
        SCM_DEFINE.  Define with SCM_DEFINE.
        (scm_make_mutex): Renamed from scm_lock_mutex.  Define with
        SCM_DEFINE.
        (scm_mutex_lock): Renamed from scm_lock_mutex.  Define with
        SCM_DEFINE.
        (scm_mutex_unlock): Renamed from scm_unlock_mutex.  Define with
        SCM_DEFINE.
        (scm_make_cond): Renamed from scm_make_condition_variable.  Define
        with SCM_DEFINE.
        (scm_cond_wait): Renamed from scm_wait_condition_variable.  Define
        with SCM_DEFINE.
        (scm_cond_signal): Renamed from scm_signal_condition_variable.
        Define with SCM_DEFINE.

Index: libguile/coop-defs.h
===================================================================
RCS file: /cvs/guile/guile-core/libguile/coop-defs.h,v
retrieving revision 1.18
diff -u -r1.18 coop-defs.h
--- libguile/coop-defs.h        2000/10/02 21:32:57     1.18
+++ libguile/coop-defs.h        2001/04/11 02:10:14
@@ -151,11 +151,11 @@
 extern int coop_mutex_trylock (coop_m*);
 extern int coop_mutex_unlock (coop_m*);
 extern int coop_mutex_destroy (coop_m*);
-#define scm_mutex_init coop_mutex_init
-#define scm_mutex_lock coop_mutex_lock
-#define scm_mutex_trylock coop_mutex_lock
-#define scm_mutex_unlock coop_mutex_unlock
-#define scm_mutex_destroy coop_mutex_destroy
+#define scm_c_mutex_init coop_mutex_init
+#define scm_c_mutex_lock coop_mutex_lock
+#define scm_c_mutex_trylock coop_mutex_lock
+#define scm_c_mutex_unlock coop_mutex_unlock
+#define scm_c_mutex_destroy coop_mutex_destroy
 
 /* A Condition variable is made up of a list of threads waiting on the
    condition. */
@@ -186,12 +186,12 @@
                                                     const struct timespec 
*abstime);
 extern int coop_condition_variable_signal (coop_c*);
 extern int coop_condition_variable_destroy (coop_c*);
-#define scm_cond_init coop_new_condition_variable_init
-#define scm_cond_wait coop_condition_variable_wait_mutex
-#define scm_cond_timedwait coop_condition_variable_timed_wait_mutex
-#define scm_cond_signal coop_condition_variable_signal
-#define scm_cond_broadcast coop_condition_variable_signal /* yes */
-#define scm_cond_destroy coop_condition_variable_destroy
+#define scm_c_cond_init coop_new_condition_variable_init
+#define scm_c_cond_wait coop_condition_variable_wait_mutex
+#define scm_c_cond_timedwait coop_condition_variable_timed_wait_mutex
+#define scm_c_cond_signal coop_condition_variable_signal
+#define scm_c_cond_broadcast coop_condition_variable_signal /* yes */
+#define scm_c_cond_destroy coop_condition_variable_destroy
 
 typedef int coop_k;
 
@@ -201,10 +201,10 @@
 extern int coop_setspecific (coop_k key, const void *value);
 extern void *coop_getspecific (coop_k key);
 extern int coop_key_delete (coop_k);
-#define scm_key_create coop_key_create
-#define scm_setspecific coop_setspecific
-#define scm_getspecific coop_getspecific
-#define scm_key_delete coop_key_delete
+#define scm_c_key_create coop_key_create
+#define scm_c_setspecific coop_setspecific
+#define scm_c_getspecific coop_getspecific
+#define scm_c_key_delete coop_key_delete
 
 extern coop_t *coop_global_curr;               /* Currently-executing thread. 
*/
 
Index: libguile/coop-threads.c
===================================================================
RCS file: /cvs/guile/guile-core/libguile/coop-threads.c,v
retrieving revision 1.28
diff -u -r1.28 coop-threads.c
--- libguile/coop-threads.c     2001/03/17 12:20:36     1.28
+++ libguile/coop-threads.c     2001/04/11 02:10:14
@@ -376,9 +376,12 @@
   return thread;
 }
 
-SCM
-scm_join_thread (SCM thread)
-#define FUNC_NAME s_join_thread
+SCM_DEFINE(scm_thread_join, "thread-join", 1, 0, 0,
+          (SCM thread),
+          "Suspend execution of the calling thread until the target\n"
+          "@var{thread} terminates, unless the target @var{thread} has\n"
+          "already terminated.")
+#define FUNC_NAME s_scm_thread_join
 {
   coop_t *thread_data;
   SCM_VALIDATE_THREAD (1, thread);
@@ -399,8 +402,12 @@
 }
 #undef FUNC_NAME
 
-SCM
-scm_yield (void)
+SCM_DEFINE(scm_thread_yield, "thread-yield", 0, 0, 0,
+          (void),
+          "If one or more threads are waiting to execute, calling\n"
+          "thread-yield forces an immediate context switch to one of them.\n"
+          "Otherwise, thread-yield has no effect.")
+#define FUNC_NAME s_scm_thread_yield
 {
   /* Yield early */
   scm_switch_counter = SCM_THREAD_SWITCH_COUNT;
@@ -408,6 +415,7 @@
 
   return SCM_BOOL_T;
 }
+#undef FUNC_NAME
 
 SCM
 scm_single_thread_p (void)
@@ -417,8 +425,10 @@
          : SCM_BOOL_F);
 }
 
-SCM
-scm_make_mutex (void)
+SCM_DEFINE(scm_make_mutex, "make-mutex", 0, 0, 0,
+          (void),
+          "Create a new mutex object.")
+#define FUNC_NAME s_scm_make_mutex
 {
   SCM m;
   coop_m *data = (coop_m *) scm_must_malloc (sizeof (coop_m), "mutex");
@@ -427,17 +437,29 @@
   coop_mutex_init (data);
   return m;
 }
+#undef FUNC_NAME
 
-SCM
-scm_lock_mutex (SCM m)
+SCM_DEFINE(scm_mutex_lock, "mutex-lock", 1, 0, 0, 
+          (SCM m),
+          "Lock @var{mutex}. If the mutex is already locked, the calling\n"
+          "thread blocks until the mutex becomes available. The function\n"
+          "returns when the calling thread owns the lock on @var{mutex}.")
+#define FUNC_NAME s_scm_mutex_lock
 {
   SCM_ASSERT (SCM_MUTEXP (m), m, SCM_ARG1, s_lock_mutex);
   coop_mutex_lock (SCM_MUTEX_DATA (m));
   return SCM_BOOL_T;
 }
+#undef FUNC_NAME
 
-SCM
-scm_unlock_mutex (SCM m)
+SCM_DEFINE(scm_mutex_unlock, "mutex-unlock", 1, 0, 0, 
+          (SCM m),
+          "Unlocks @var{mutex} if the calling thread owns the lock on\n"
+          "@var{mutex}.  Calling unlock-mutex on a mutex not owned by the\n"
+          "current thread results in undefined behaviour.  Once a mutex\n"
+          "has been unlocked, one thread blocked on @var{mutex} is\n"
+          "awakened and grabs the mutex lock.")
+#define FUNC_NAME s_scm_mutex_unlock
 {
   SCM_ASSERT (SCM_MUTEXP (m), m, SCM_ARG1, s_unlock_mutex);
   coop_mutex_unlock(SCM_MUTEX_DATA (m));
@@ -448,9 +470,12 @@
 
   return SCM_BOOL_T;
 }
+#undef FUNC_NAME
 
-SCM
-scm_make_condition_variable (void)
+SCM_DEFINE(scm_make_cond, "make-cond", 0, 0, 0, 
+          (void),
+          "")
+#define FUNC_NAME s_scm_make_cond
 {
   SCM c;
   coop_c *data = (coop_c *) scm_must_malloc (sizeof (coop_c), "condvar");
@@ -458,9 +483,12 @@
   coop_condition_variable_init (SCM_CONDVAR_DATA (c));
   return c;
 }
+#undef FUNC_NAME
 
-SCM
-scm_wait_condition_variable (SCM c, SCM m)
+SCM_DEFINE(scm_cond_wait, "cond-wait", 2, 0, 0, 
+          (SCM c, SCM m),
+          "")
+#define FUNC_NAME s_scm_cond_wait
 {
   SCM_ASSERT (SCM_CONDVARP (c),
              c,
@@ -474,9 +502,12 @@
                                      SCM_MUTEX_DATA (m));
   return SCM_BOOL_T;
 }
+#undef FUNC_NAME
 
-SCM
-scm_signal_condition_variable (SCM c)
+SCM_DEFINE(scm_cond_signal, "cond-signal", 1, 0, 0, 
+          (SCM c),
+          "")
+#define FUNC_NAME s_scm_cond_signal
 {
   SCM_ASSERT (SCM_CONDVARP (c),
              c,
@@ -485,6 +516,7 @@
   coop_condition_variable_signal (SCM_CONDVAR_DATA (c));
   return SCM_BOOL_T;
 }
+#undef FUNC_NAME
 
 /*
   Local Variables:
Index: libguile/goops.c
===================================================================
RCS file: /cvs/guile/guile-core/libguile/goops.c,v
retrieving revision 1.26
diff -u -r1.26 goops.c
--- libguile/goops.c    2001/03/30 02:50:38     1.26
+++ libguile/goops.c    2001/04/11 02:10:14
@@ -1484,7 +1484,7 @@
 {
   SCM obj = (SCM) o;
 #ifdef USE_THREADS
-  scm_mutex_lock (&hell_mutex);
+  scm_c_mutex_lock (&hell_mutex);
 #endif
   if (n_hell == hell_size)
     {
@@ -1494,7 +1494,7 @@
     }
   hell[n_hell++] = SCM_INST (obj);
 #ifdef USE_THREADS
-  scm_mutex_unlock (&hell_mutex);
+  scm_c_mutex_unlock (&hell_mutex);
 #endif
 }
 
@@ -1502,11 +1502,11 @@
 go_to_heaven (void *o)
 {
 #ifdef USE_THREADS
-  scm_mutex_lock (&hell_mutex);
+  scm_c_mutex_lock (&hell_mutex);
 #endif
   hell[burnin ((SCM) o)] = hell[--n_hell];
 #ifdef USE_THREADS
-  scm_mutex_unlock (&hell_mutex);
+  scm_c_mutex_unlock (&hell_mutex);
 #endif
 }
 
@@ -1924,14 +1924,14 @@
 lock_cache_mutex (void *m)
 {
   SCM mutex = (SCM) m;
-  scm_lock_mutex (mutex);
+  scm_mutex_lock (mutex);
 }
 
 static void
 unlock_cache_mutex (void *m)
 {
   SCM mutex = (SCM) m;
-  scm_unlock_mutex (mutex);
+  scm_mutex_unlock (mutex);
 }
 #endif
 
@@ -2673,7 +2673,7 @@
 
   hell = scm_must_malloc (hell_size, "hell");
 #ifdef USE_THREADS
-  scm_mutex_init (&hell_mutex);
+  scm_c_mutex_init (&hell_mutex);
 #endif
 
   create_basic_classes ();
Index: libguile/threads.c
===================================================================
RCS file: /cvs/guile/guile-core/libguile/threads.c,v
retrieving revision 1.20
diff -u -r1.20 threads.c
--- libguile/threads.c  2001/03/09 23:33:41     1.20
+++ libguile/threads.c  2001/04/11 02:10:14
@@ -84,11 +84,6 @@
 /* GJB:FIXME:DOC: SCM_REGISTER_PROC needs to permit a docstring,
    or these need to move into the file where the proc is defined. */
 
-SCM_REGISTER_PROC(s_yield, "yield", 0, 0, 0, scm_yield);
-/* If one or more threads are waiting to execute, calling yield forces an
-immediate context switch to one of them. Otherwise, yield has no effect.
-*/
-
 SCM_REGISTER_PROC(s_call_with_new_thread, "call-with-new-thread", 0, 0, 1, 
scm_call_with_new_thread);
 /* Evaluate @var{(thunk)} in a new thread, and new dynamic context,
 returning a new thread object representing the thread.
@@ -102,32 +97,22 @@
 
 All the evaluation rules for dynamic roots apply to threads.
 */
-
-SCM_REGISTER_PROC(s_join_thread, "join-thread", 1, 0, 0, scm_join_thread);
-/* Suspend execution of the calling thread until the target @var{thread}
-terminates, unless the target @var{thread} has already terminated.
-*/
 
-SCM_REGISTER_PROC(s_make_mutex, "make-mutex", 0, 0, 0, scm_make_mutex);
-/* Create a new mutex object. */
+#if (SCM_DEBUG_DEPRECATED == 0)
+SCM_REGISTER_PROC(s_yield, "yield", 0, 0, 0, scm_thread_yield);
 
-SCM_REGISTER_PROC(s_lock_mutex, "lock-mutex", 1, 0, 0, scm_lock_mutex);
-/* Lock @var{mutex}. If the mutex is already locked, the calling thread
-blocks until the mutex becomes available. The function returns when
-the calling thread owns the lock on @var{mutex}. */
+SCM_REGISTER_PROC(s_join_thread, "join-thread", 1, 0, 0, scm_thread_join);
 
-SCM_REGISTER_PROC(s_unlock_mutex, "unlock-mutex", 1, 0, 0, scm_unlock_mutex);
-/* Unlocks @var{mutex} if the calling thread owns the lock on @var{mutex}.
-Calling unlock-mutex on a mutex not owned by the current thread results
-in undefined behaviour. Once a mutex has been unlocked, one thread
-blocked on @var{mutex} is awakened and grabs the mutex lock. */
+SCM_REGISTER_PROC(s_lock_mutex, "lock-mutex", 1, 0, 0, scm_mutex_lock);
 
-SCM_REGISTER_PROC(s_make_condition_variable, "make-condition-variable", 0, 0, 
0, scm_make_condition_variable);
+SCM_REGISTER_PROC(s_unlock_mutex, "unlock-mutex", 1, 0, 0, scm_mutex_unlock);
 
-SCM_REGISTER_PROC(s_wait_condition_variable, "wait-condition-variable", 2, 0, 
0, scm_wait_condition_variable);
+SCM_REGISTER_PROC(s_make_condition_variable, "make-condition-variable", 0, 0, 
0, scm_make_cond);
 
-SCM_REGISTER_PROC(s_signal_condition_variable, "signal-condition-variable", 1, 
0, 0, scm_signal_condition_variable);
+SCM_REGISTER_PROC(s_wait_condition_variable, "wait-condition-variable", 2, 0, 
0, scm_cond_wait);
 
+SCM_REGISTER_PROC(s_signal_condition_variable, "signal-condition-variable", 1, 
0, 0, scm_cond_signal);
+#endif  /* SCM_DEBUG_DEPRECATED == 0 */
 
 
 #ifdef USE_COOP_THREADS
@@ -135,6 +120,32 @@
 #endif
 
 
+SCM_DEFINE(scm_thread_p, "thread?", 1, 0, 0,
+          (SCM obj),
+          "Return #t iff OBJ is a thread object.")
+#define FUNC_NAME s_scm_thread_p
+{
+  return SCM_BOOL (SCM_THREADP (obj));
+}
+#undef FUNC_NAME
+
+SCM_DEFINE(scm_mutex_p, "mutex?", 1, 0, 0,
+          (SCM obj),
+          "Return #t iff OBJ is a mutex object.")
+#define FUNC_NAME s_scm_mutex_p
+{
+  return SCM_BOOL (SCM_MUTEXP (obj));
+}
+#undef FUNC_NAME
+
+SCM_DEFINE(scm_cond_p, "cond?", 1, 0, 0,
+          (SCM obj),
+          "Return #t iff OBJ is a condition variable object.")
+#define FUNC_NAME s_scm_cond_p
+{
+  return SCM_BOOL (SCM_CONDVARP (obj));
+}
+#undef FUNC_NAME
 
 void
 scm_init_threads (SCM_STACKITEM *i)
Index: libguile/threads.h
===================================================================
RCS file: /cvs/guile/guile-core/libguile/threads.h,v
retrieving revision 1.15
diff -u -r1.15 threads.h
--- libguile/threads.h  2000/12/10 20:34:01     1.15
+++ libguile/threads.h  2001/04/11 02:10:14
@@ -92,15 +92,19 @@
 #ifdef USE_COOP_THREADS
 extern SCM scm_single_thread_p (void);
 #endif
-extern SCM scm_yield (void);
+extern SCM scm_thread_p (SCM obj);
+extern SCM scm_mutex_p (SCM obj);
+extern SCM scm_cond_p (SCM obj);
+
+extern SCM scm_thread_yield (void);
 extern SCM scm_call_with_new_thread (SCM argl);
-extern SCM scm_join_thread (SCM t);
+extern SCM scm_thread_join (SCM t);
 extern SCM scm_make_mutex (void);
-extern SCM scm_lock_mutex (SCM m);
-extern SCM scm_unlock_mutex (SCM m);
-extern SCM scm_make_condition_variable (void);
-extern SCM scm_wait_condition_variable (SCM cond, SCM mutex);
-extern SCM scm_signal_condition_variable (SCM cond);
+extern SCM scm_mutex_lock (SCM m);
+extern SCM scm_mutex_unlock (SCM m);
+extern SCM scm_make_cond (void);
+extern SCM scm_cond_wait (SCM cond, SCM mutex);
+extern SCM scm_cond_signal (SCM cond);
 
 #ifdef USE_COOP_THREADS
 #include "libguile/coop-defs.h"
-- 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]