diff options
author | rsc <devnull@localhost> | 2004-09-17 00:38:29 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2004-09-17 00:38:29 +0000 |
commit | 06bb4ed20d855b60e39c1125d8d715ba8892265b (patch) | |
tree | 8294b537f5b81809671985903e31c4835c41cd04 /include | |
parent | 984e353160593b20d1e2944e1f2e9ce2117c8490 (diff) | |
download | plan9port-06bb4ed20d855b60e39c1125d8d715ba8892265b.tar.gz plan9port-06bb4ed20d855b60e39c1125d8d715ba8892265b.tar.bz2 plan9port-06bb4ed20d855b60e39c1125d8d715ba8892265b.zip |
Rewrite to remove dependence on rendezvous and its bizarre
data structures. Makes it easier to use pthreads too.
Still need to add code for non-pthreads systems.
Just a checkpoint to switch work to another machine.
Diffstat (limited to 'include')
-rw-r--r-- | include/libc.h | 43 | ||||
-rw-r--r-- | include/thread.h | 2 | ||||
-rw-r--r-- | include/u.h | 7 |
3 files changed, 43 insertions, 9 deletions
diff --git a/include/libc.h b/include/libc.h index 93a9104a..1db39606 100644 --- a/include/libc.h +++ b/include/libc.h @@ -425,22 +425,49 @@ extern void needstack(int); /* * synchronization */ -typedef -struct Lock { - int val; -} Lock; - -extern int _tas(int*); +typedef struct Lock Lock; +struct Lock +{ +#ifdef PLAN9_PTHREADS + int init; + pthread_mutex_t mutex; +#else + int val; +#endif +}; extern void lock(Lock*); extern void unlock(Lock*); extern int canlock(Lock*); +/* + * Used to implement process sleep and wakeup, + * either in terms of pthreads or our own primitives. + * This will be more portable than writing our own + * per-system implementations, and on some systems + * non-pthreads threading implementations break libc + * (cough, Linux, cough). + */ +typedef struct _Procrend _Procrend; +struct _Procrend +{ + int asleep; + Lock *l; + void *arg; +#ifdef PLAN9_PTHREADS + pthread_cond_t cond; +#endif +}; + +extern void _procsleep(_Procrend*); +extern void _procwakeup(_Procrend*); + typedef struct QLp QLp; struct QLp { - int inuse; + Lock inuse; QLp *next; + _Procrend rend; char state; }; @@ -456,7 +483,7 @@ struct QLock extern void qlock(QLock*); extern void qunlock(QLock*); extern int canqlock(QLock*); -extern void _qlockinit(ulong (*)(ulong, ulong)); /* called only by the thread library */ +extern void _qlockinit(void(*)(_Procrend*), void(*)(_Procrend*)); /* called only by the thread library */ typedef struct RWLock diff --git a/include/thread.h b/include/thread.h index ce2d73bb..f2a12599 100644 --- a/include/thread.h +++ b/include/thread.h @@ -55,7 +55,7 @@ struct Alt { /* the next variables are used internally to alt * they need not be initialized */ - Channel **tag; /* pointer to rendez-vous tag */ + struct Thread *thread; /* thread waiting on this alt */ int entryno; /* entry number */ }; diff --git a/include/u.h b/include/u.h index a7f97fc6..0cd8e397 100644 --- a/include/u.h +++ b/include/u.h @@ -41,6 +41,8 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; # undef _NEEDUSHORT # undef _NEEDUINT # undef _NEEDULONG +# include <pthread.h> +# define PLAN9_PTHREADS # endif #endif #if defined(__sun__) @@ -48,6 +50,8 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; # undef _NEEDUSHORT # undef _NEEDUINT # undef _NEEDULONG +# include <pthread.h> +# define PLAN9_PTHREADS #endif #if defined(__FreeBSD__) # include <sys/types.h> @@ -61,8 +65,11 @@ typedef long p9jmp_buf[sizeof(sigjmp_buf)/sizeof(long)]; # undef _NEEDUSHORT # undef _NEEDUINT # define _NEEDLL 1 +# include <pthread.h> +# define PLAN9_PTHREADS #endif + typedef signed char schar; typedef unsigned int u32int; typedef int s32int; |