1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-12 06:41:13 +02:00

* coop.c (coop_mutex_init, coop_mutex_lock, coop_mutex_unlock,

coop_condition_variable_init, coop_condition_variable_wait,
coop_condition_variable_signal): Changed return type from `void'
to `int'.  This is to adhere closer to the pthreads interface.
This, in turn, is part of an attempt to provide C versions of the
mutex and condition variable primitives which can be part of a
frontend to COOP or pthreads.

* coop.c (coop_mutex_destroy, coop_condition_variable_wait_mutex,
coop_condition_variable_destroy): New functions.

* coop-threads.c (scm_wait_condition_variable): Use
coop_condition_variable_wait_mutex.

* coop-threads.h, coop-defs.h (coop_q_t, coop_m, coop_c):
Definitions moved to coop-defs.h.

* coop-defs.h (scm_mutex_init, scm_mutex_lock, scm_mutex_unlock,
scm_mutex_destroy, scm_cond_init, scm_cond_wait, scm_cond_signal,
scm_cond_destroy): New C interface to mutecis and cond vars.
This commit is contained in:
Mikael Djurfeldt 1998-01-26 01:43:16 +00:00
parent 3237b129f7
commit c8bf4ecd10
4 changed files with 114 additions and 43 deletions

View file

@ -108,6 +108,55 @@ typedef struct coop_t {
} coop_t; } coop_t;
/* A queue is a circular list of threads. The queue head is a
designated list element. If this is a uniprocessor-only
implementation we can store the `main' thread in this, but in a
multiprocessor there are several `heavy' threads but only one run
queue. A fancier implementation might have private run queues,
which would lead to a simpler (trivial) implementation */
typedef struct coop_q_t {
coop_t t;
coop_t *tail;
} coop_q_t;
/* A Mutex variable is made up of a owner thread, and a queue of threads
waiting on the mutex */
typedef struct coop_m {
coop_t *owner; /* Mutex owner */
coop_q_t waiting; /* Queue of waiting threads */
} coop_m;
typedef coop_m scm_mutex_t;
extern int coop_mutex_init (coop_m*);
extern int coop_mutex_lock (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_unlock coop_mutex_unlock
#define scm_mutex_destroy coop_mutex_destroy
/* A Condition variable is made up of a list of threads waiting on the
condition. */
typedef struct coop_c {
coop_q_t waiting; /* Queue of waiting threads */
} coop_c;
typedef coop_c scm_cond_t;
extern int coop_condition_variable_init (coop_c*);
extern int coop_condition_variable_wait_mutex (coop_c*, coop_m*);
extern int coop_condition_variable_signal (coop_c*);
extern int coop_condition_variable_destroy (coop_c*);
#define scm_cond_init(cond, attr) coop_condition_variable_init (cond)
#define scm_cond_wait coop_condition_variable_wait_mutex
#define scm_cond_signal coop_condition_variable_signal
#define scm_cond_destroy coop_condition_variable_destroy
extern coop_t *coop_global_curr; /* Currently-executing thread. */ extern coop_t *coop_global_curr; /* Currently-executing thread. */
extern void coop_yield (void); extern void coop_yield (void);

View file

@ -501,9 +501,8 @@ scm_wait_condition_variable (c, m)
m, m,
SCM_ARG2, SCM_ARG2,
s_wait_condition_variable); s_wait_condition_variable);
coop_mutex_unlock (SCM_MUTEX_DATA (m)); coop_condition_variable_wait_mutex (SCM_CONDVAR_DATA (c),
coop_condition_variable_wait (SCM_CONDVAR_DATA (c)); SCM_MUTEX_DATA (m));
coop_mutex_lock (SCM_MUTEX_DATA (m));
return SCM_BOOL_T; return SCM_BOOL_T;
} }

View file

@ -74,33 +74,6 @@
* purpose. * purpose.
*/ */
/* A queue is a circular list of threads. The queue head is a
designated list element. If this is a uniprocessor-only
implementation we can store the `main' thread in this, but in a
multiprocessor there are several `heavy' threads but only one run
queue. A fancier implementation might have private run queues,
which would lead to a simpler (trivial) implementation */
typedef struct coop_q_t {
coop_t t;
coop_t *tail;
} coop_q_t;
/* A Mutex variable is made up of a owner thread, and a queue of threads
waiting on the mutex */
typedef struct coop_m {
coop_t *owner; /* Mutex owner */
coop_q_t waiting; /* Queue of waiting threads */
} coop_m;
/* A Condition variable is made up of a list of threads waiting on the
condition. */
typedef struct coop_c {
coop_q_t waiting; /* Queue of waiting threads */
} coop_c;
/* Each thread starts by calling a user-supplied function of this /* Each thread starts by calling a user-supplied function of this
type. */ type. */

View file

@ -40,7 +40,7 @@
* If you do not wish that, delete this exception notice. */ * If you do not wish that, delete this exception notice. */
/* $Id: coop.c,v 1.3 1997-11-27 18:04:53 mdj Exp $ */ /* $Id: coop.c,v 1.4 1998-01-26 01:43:16 mdj Exp $ */
/* Cooperative thread library, based on QuickThreads */ /* Cooperative thread library, based on QuickThreads */
@ -262,23 +262,24 @@ coop_starthelp (old, ignore0, ignore1)
} }
#ifdef __STDC__ #ifdef __STDC__
void int
coop_mutex_init (coop_m *m) coop_mutex_init (coop_m *m)
#else #else
void int
coop_mutex_init (m) coop_mutex_init (m)
coop_m *m; coop_m *m;
#endif #endif
{ {
m->owner = NULL; m->owner = NULL;
coop_qinit(&(m->waiting)); coop_qinit(&(m->waiting));
return 0;
} }
#ifdef __STDC__ #ifdef __STDC__
void int
coop_mutex_lock (coop_m *m) coop_mutex_lock (coop_m *m)
#else #else
void int
coop_mutex_lock () coop_mutex_lock ()
coop_m *m; coop_m *m;
#endif #endif
@ -303,14 +304,15 @@ coop_mutex_lock ()
coop_global_curr = newthread; coop_global_curr = newthread;
QT_BLOCK (coop_yieldhelp, old, &(m->waiting), newthread->sp); QT_BLOCK (coop_yieldhelp, old, &(m->waiting), newthread->sp);
} }
return 0;
} }
#ifdef __STDC__ #ifdef __STDC__
void int
coop_mutex_unlock (coop_m *m) coop_mutex_unlock (coop_m *m)
#else #else
void int
coop_mutex_unlock (m) coop_mutex_unlock (m)
coop_m *m; coop_m *m;
#endif #endif
@ -332,26 +334,41 @@ coop_mutex_unlock (m)
{ {
m->owner = NULL; m->owner = NULL;
} }
return 0;
} }
#ifdef __STDC__ #ifdef __STDC__
void int
coop_mutex_destroy (coop_m *m)
#else
int
coop_mutex_destroy (m)
coop_m *m;
#endif
{
return 0;
}
#ifdef __STDC__
int
coop_condition_variable_init (coop_c *c) coop_condition_variable_init (coop_c *c)
#else #else
void int
coop_condition_variable_init (c) coop_condition_variable_init (c)
coop_c *c; coop_c *c;
#endif #endif
{ {
coop_qinit(&(c->waiting)); coop_qinit(&(c->waiting));
return 0;
} }
#ifdef __STDC__ #ifdef __STDC__
void int
coop_condition_variable_wait (coop_c *c) coop_condition_variable_wait (coop_c *c)
#else #else
void int
coop_condition_variable_wait (c) coop_condition_variable_wait (c)
coop_c *c; coop_c *c;
#endif #endif
@ -366,13 +383,32 @@ coop_condition_variable_wait (c)
old = coop_global_curr; old = coop_global_curr;
coop_global_curr = newthread; coop_global_curr = newthread;
QT_BLOCK (coop_yieldhelp, old, &(c->waiting), newthread->sp); QT_BLOCK (coop_yieldhelp, old, &(c->waiting), newthread->sp);
return 0;
} }
#ifdef __STDC__ #ifdef __STDC__
void int
coop_condition_variable_wait_mutex (coop_c *c, coop_m *m)
#else
int
coop_condition_variable_wait_mutex (c, m)
coop_c *c;
coop_m *m;
#endif
{
coop_mutex_unlock (m);
coop_condition_variable_wait (c);
coop_mutex_lock (m);
return 0;
}
#ifdef __STDC__
int
coop_condition_variable_signal (coop_c *c) coop_condition_variable_signal (coop_c *c)
#else #else
void int
coop_condition_variable_signal (c) coop_condition_variable_signal (c)
coop_c *c; coop_c *c;
#endif #endif
@ -383,6 +419,20 @@ coop_condition_variable_signal (c)
{ {
coop_qput (&coop_global_runq, newthread); coop_qput (&coop_global_runq, newthread);
} }
return 0;
}
#ifdef __STDC__
int
coop_condition_variable_destroy (coop_c *c)
#else
int
coop_condition_variable_destroy (c)
coop_c *c;
#endif
{
return 0;
} }