[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Thread Plug-in Support #6
From: |
NIIBE Yutaka |
Subject: |
[PATCH] Thread Plug-in Support #6 |
Date: |
Thu, 12 Apr 2001 11:38:08 +0900 (JST) |
Patch piece #6. This patch requires #2 and #3.
This piece is interface cleanup. I guess that I just follow how Dirk
did his work, next comes method table. Basically, this is the work
done by Dirk. I make more verbose ChangeLog entries.
No regression with "make check".
Please watch out the patch format is different, you need to -p1 to
apply.
guile-readline/ChangeLog
* readline.c (reentry_barrier_mutex): Make it the pointer
to the mutex.
(reentry_barrier): Follow the change of reentry_barrier_mutex.
(scm_init_readline): Likewise.
diff -rupN guile-core.u/guile-readline/readline.c
guile-core/guile-readline/readline.c
--- guile-core.u/guile-readline/readline.c Thu Apr 12 11:06:10 2001
+++ guile-core/guile-readline/readline.c Thu Apr 12 11:06:25 2001
@@ -147,7 +147,7 @@ redisplay ()
static int in_readline = 0;
#ifdef USE_THREADS
-static scm_mutex_t reentry_barrier_mutex;
+static scm_mutex_t *reentry_barrier_mutex;
#endif
static SCM internal_readline (SCM text);
@@ -226,14 +226,14 @@ reentry_barrier ()
int reentryp = 0;
#ifdef USE_THREADS
/* We should rather use scm_mutex_try_lock when it becomes available */
- scm_c_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_c_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 @@ scm_init_readline ()
#endif
#ifdef USE_THREADS
- scm_c_mutex_init (&reentry_barrier_mutex);
+ reentry_barrier_mutex = scm_c_mutex_init (NULL);
#endif
scm_init_opts (scm_readline_options,
scm_readline_opts,
libguile/ChangeLog
* coop-defs.h (scm_mutexattr_t): Typedefed.
(coop_mutex_init, coop_new_mutex_init, coop_mutex_destroy):
Removed declarations.
(coop_make_mutex, coop_mutex_free): New declarations.
(scm_c_mutex_init): Defined as coop_make_mutex, it was
coop_mutex_init.
(scm_c_mutex_destroy): Defined as coop_mutex_free, it was
coop_mutex_destroy.
(scm_condattr_t): Typedefed.
(coop_condition_variable_init, coop_new_condition_variable_init,
coop_condition_variable_destroy): Removed declarations.
(coop_make_condition_variable, coop_condition_variable_free):
New declarations.
(scm_c_cond_init): Defined as coop_make_condition_variable, it was
coop_new_condition_variable_init.
(scm_c_cond_destroy): Defined as coop_condition_variable_free, it was
coop_condition_variable_destroy.
(coop_timeout_qinsert): Removed declaration.
* coop-threads.h (coop_qget, coop_qput): Removed declarations.
* coop.c ("libguile/async.h"): Included.
(coop_qget, coop_qput, coop_timeout_qinsert, coop_global_runq,
coop_global_sleepq, coop_tmp_queue, coop_global_allq): Make them
static.
(coop_start, coop_starthelp): Removed.
(coop_next_runnable_thread, coop_new_mutex_init, coop_mutex_init,
coop_mutex_destroy): Make them static.
(coop_make_mutex, coop_mutex_free): New functions.
(coop_new_condition_variable_init, coop_condition_variable_init,
coop_condition_variable_destroy): Make them static.
(coop_make_condition_variable, coop_condition_variable_free):
New functions.
* goops.c (hell_mutex): Make it the pointer to the mutex.
(go_to_hell, go_to_heaven): Follow the change of hell_mutex.
(scm_init_goops): Likewise.
diff -rupN guile-core.u/libguile/coop-defs.h guile-core/libguile/coop-defs.h
--- guile-core.u/libguile/coop-defs.h Thu Apr 12 11:06:10 2001
+++ guile-core/libguile/coop-defs.h Thu Apr 12 11:06:25 2001
@@ -144,18 +144,18 @@ typedef struct coop_m {
typedef int coop_mattr;
typedef coop_m scm_mutex_t;
+typedef coop_mattr scm_mutexattr_t;
-extern int coop_mutex_init (coop_m*);
-extern int coop_new_mutex_init (coop_m*, coop_mattr*);
+extern scm_mutex_t *coop_make_mutex (const scm_mutexattr_t * mutexattr);
extern int coop_mutex_lock (coop_m*);
extern int coop_mutex_trylock (coop_m*);
extern int coop_mutex_unlock (coop_m*);
-extern int coop_mutex_destroy (coop_m*);
-#define scm_c_mutex_init coop_mutex_init
+extern size_t coop_mutex_free (scm_mutex_t * mutex);
+#define scm_c_mutex_init coop_make_mutex
#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
+#define scm_c_mutex_destroy coop_mutex_free
/* A Condition variable is made up of a list of threads waiting on the
condition. */
@@ -167,6 +167,7 @@ typedef struct coop_c {
typedef int coop_cattr;
typedef coop_c scm_cond_t;
+typedef coop_cattr scm_condattr_t;
#ifndef HAVE_STRUCT_TIMESPEC
/* POSIX.4 structure for a time value. This is like a `struct timeval' but
@@ -178,20 +179,19 @@ struct timespec
};
#endif
-extern int coop_condition_variable_init (coop_c*);
-extern int coop_new_condition_variable_init (coop_c*, coop_cattr*);
+extern scm_cond_t *coop_make_condition_variable (const scm_condattr_t
*cond_attr);
extern int coop_condition_variable_wait_mutex (coop_c*, coop_m*);
extern int coop_condition_variable_timed_wait_mutex (coop_c*,
coop_m*,
const struct timespec
*abstime);
extern int coop_condition_variable_signal (coop_c*);
-extern int coop_condition_variable_destroy (coop_c*);
-#define scm_c_cond_init coop_new_condition_variable_init
+extern size_t coop_condition_variable_free (scm_cond_t * cond);
+#define scm_c_cond_init coop_make_condition_variable
#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
+#define scm_c_cond_destroy coop_condition_variable_free
typedef int coop_k;
@@ -217,15 +217,6 @@ extern size_t scm_thread_count;
/* Some iselect functions. */
-/* I'm not sure whether these three declarations should be here.
- They're really defined in iselect.c, so you'd think they'd go in
- iselect.h, but they use coop_t, defined above, which uses things
- defined in iselect.h. Basically, we're making at best a flailing
- (and failing) attempt at modularity here, and I don't have time to
- rethink this at the moment. This code awaits a Hero. --JimB */
-#ifdef GUILE_ISELECT
-void coop_timeout_qinsert (coop_q_t *, coop_t *);
-#endif
extern coop_t *coop_next_runnable_thread (void);
extern coop_t *coop_wait_for_runnable_thread_now (struct timeval *);
extern coop_t *coop_wait_for_runnable_thread (void);
diff -rupN guile-core.u/libguile/coop-threads.h
guile-core/libguile/coop-threads.h
--- guile-core.u/libguile/coop-threads.h Thu Apr 12 11:04:54 2001
+++ guile-core/libguile/coop-threads.h Thu Apr 12 11:06:25 2001
@@ -107,8 +107,6 @@ extern void coop_abort (void);
/* The following are needed in iselect.c */
-extern coop_t *coop_qget (coop_q_t *);
-extern void coop_qput (coop_q_t *, coop_t *);
extern void *coop_sleephelp (qt_t *, void *, void *);
#ifdef GUILE_ISELECT
diff -rupN guile-core.u/libguile/coop.c guile-core/libguile/coop.c
--- guile-core.u/libguile/coop.c Thu Apr 12 11:06:06 2001
+++ guile-core/libguile/coop.c Thu Apr 12 11:06:25 2001
@@ -53,6 +53,7 @@
#include <errno.h>
#include "qt/qt.h"
+#include "libguile/async.h"
#include "libguile/eval.h"
/* #define COOP_STKSIZE (0x10000) */
@@ -156,7 +157,7 @@ coop_qinit (coop_q_t *q)
}
-coop_t *
+static coop_t *
coop_qget (coop_q_t *q)
{
coop_t *t;
@@ -175,7 +176,7 @@ coop_qget (coop_q_t *q)
}
-void
+static void
coop_qput (coop_q_t *q, coop_t *t)
{
q->tail->next = t;
@@ -208,7 +209,7 @@ coop_all_qremove (coop_q_t *q, coop_t *t
/* Insert thread t into the ordered queue q.
q is ordered after wakeup_time. Threads which aren't sleeping but
waiting for I/O go last into the queue. */
-void
+static void
coop_timeout_qinsert (coop_q_t *q, coop_t *t)
{
coop_t *pred = &q->t;
@@ -260,10 +261,10 @@ init_iselect ()
/* Thread routines. */
-coop_q_t coop_global_runq; /* A queue of runable threads. */
-coop_q_t coop_global_sleepq; /* A queue of sleeping threads. */
-coop_q_t coop_tmp_queue; /* A temp working queue */
-coop_q_t coop_global_allq; /* A queue of all threads. */
+static coop_q_t coop_global_runq; /* A queue of runable threads. */
+static coop_q_t coop_global_sleepq; /* A queue of sleeping threads. */
+static coop_q_t coop_tmp_queue; /* A temp working queue */
+static coop_q_t coop_global_allq; /* A queue of all threads. */
static coop_t coop_global_main; /* Thread for the process. */
coop_t *coop_global_curr; /* Currently-executing thread. */
@@ -277,7 +278,6 @@ static pthread_t coop_mother;
static coop_t *coop_child;
#endif
-static void *coop_starthelp (qt_t *old, void *ignore0, void *ignore1);
static void coop_only (void *pu, void *pt, qt_userf_t *f);
static void *coop_aborthelp (qt_t *sp, void *old, void *null);
static void *coop_yieldhelp (qt_t *sp, void *old, void *blockq);
@@ -338,7 +338,7 @@ coop_init ()
return NULL. */
#ifndef GUILE_ISELECT
-coop_t *
+static coop_t *
coop_next_runnable_thread()
{
int sleepers;
@@ -369,39 +369,26 @@ coop_next_runnable_thread()
}
#endif
-void
-coop_start()
-{
- coop_t *next;
-
- while ((next = coop_qget (&coop_global_runq)) != NULL) {
- coop_global_curr = next;
- QT_BLOCK (coop_starthelp, 0, 0, next->sp);
- }
-}
-
-
-static void *
-coop_starthelp (qt_t *old, void *ignore0, void *ignore1)
+static int
+coop_new_mutex_init (coop_m *m, coop_mattr *attr)
{
- coop_global_main.sp = old;
- coop_global_main.joining = NULL;
- coop_qput (&coop_global_runq, &coop_global_main);
- return NULL; /* not used, but keeps compiler happy */
+ m->owner = NULL;
+ coop_qinit(&(m->waiting));
+ return 0;
}
-int
+static int
coop_mutex_init (coop_m *m)
{
return coop_new_mutex_init (m, NULL);
}
-int
-coop_new_mutex_init (coop_m *m, coop_mattr *attr)
+scm_mutex_t *
+coop_make_mutex (const scm_mutexattr_t *mutexattr)
{
- m->owner = NULL;
- coop_qinit(&(m->waiting));
- return 0;
+ coop_m * data = (coop_m *) scm_must_malloc (sizeof (coop_m), "mutex");
+ coop_mutex_init (data);
+ return (scm_mutex_t *) data;
}
int
@@ -471,26 +458,41 @@ coop_mutex_unlock (coop_m *m)
}
-int
+static int
coop_mutex_destroy (coop_m *m)
{
return 0;
}
-
-int
-coop_condition_variable_init (coop_c *c)
+size_t
+coop_mutex_free (scm_mutex_t *mutex)
{
- return coop_new_condition_variable_init (c, NULL);
+ coop_mutex_destroy ((coop_m *) mutex);
+ scm_must_free ((coop_m *) mutex);
+ return sizeof (coop_m);
}
-int
+static int
coop_new_condition_variable_init (coop_c *c, coop_cattr *a)
{
coop_qinit(&(c->waiting));
return 0;
}
+static int
+coop_condition_variable_init (coop_c *c)
+{
+ return coop_new_condition_variable_init (c, NULL);
+}
+
+scm_cond_t *
+coop_make_condition_variable (const scm_condattr_t * cond_attr)
+{
+ coop_c * data = (coop_c *) scm_must_malloc (sizeof (coop_c), "condvar");
+ coop_condition_variable_init (data);
+ return (scm_cond_t *) data;
+}
+
int
coop_condition_variable_wait_mutex (coop_c *c, coop_m *m)
{
@@ -651,10 +653,18 @@ coop_key_delete (coop_k key)
}
-int
+static int
coop_condition_variable_destroy (coop_c *c)
{
return 0;
+}
+
+size_t
+coop_condition_variable_free (scm_cond_t * cond)
+{
+ coop_condition_variable_destroy ((coop_c *) cond);
+ scm_must_free ((coop_c *) cond);
+ return sizeof (coop_c);
}
#ifdef GUILE_PTHREAD_COMPAT
diff -rupN guile-core.u/libguile/goops.c guile-core/libguile/goops.c
--- guile-core.u/libguile/goops.c Thu Apr 12 11:06:10 2001
+++ guile-core/libguile/goops.c Thu Apr 12 11:06:25 2001
@@ -1466,7 +1466,7 @@ static SCM **hell;
static int n_hell = 1; /* one place for the evil one himself */
static int hell_size = 4;
#ifdef USE_THREADS
-static scm_mutex_t hell_mutex;
+static scm_mutex_t *hell_mutex;
#endif
static int
@@ -1484,7 +1484,7 @@ go_to_hell (void *o)
{
SCM obj = (SCM) o;
#ifdef USE_THREADS
- scm_c_mutex_lock (&hell_mutex);
+ scm_c_mutex_lock (hell_mutex);
#endif
if (n_hell == hell_size)
{
@@ -1494,7 +1494,7 @@ go_to_hell (void *o)
}
hell[n_hell++] = SCM_INST (obj);
#ifdef USE_THREADS
- scm_c_mutex_unlock (&hell_mutex);
+ scm_c_mutex_unlock (hell_mutex);
#endif
}
@@ -1502,11 +1502,11 @@ static void
go_to_heaven (void *o)
{
#ifdef USE_THREADS
- scm_c_mutex_lock (&hell_mutex);
+ scm_c_mutex_lock (hell_mutex);
#endif
hell[burnin ((SCM) o)] = hell[--n_hell];
#ifdef USE_THREADS
- scm_c_mutex_unlock (&hell_mutex);
+ scm_c_mutex_unlock (hell_mutex);
#endif
}
@@ -2673,7 +2673,7 @@ scm_init_goops (void)
hell = scm_must_malloc (hell_size, "hell");
#ifdef USE_THREADS
- scm_c_mutex_init (&hell_mutex);
+ hell_mutex = scm_c_mutex_init (NULL);
#endif
create_basic_classes ();
--