From 3286afda88e1446d5763d2fbf11d37c843f2a997 Mon Sep 17 00:00:00 2001 From: rsc Date: Sat, 25 Dec 2004 22:00:11 +0000 Subject: new thread library --- include/libc.h | 126 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 64 insertions(+), 62 deletions(-) (limited to 'include/libc.h') diff --git a/include/libc.h b/include/libc.h index c4c40e46..ff6fd4bc 100644 --- a/include/libc.h +++ b/include/libc.h @@ -422,80 +422,75 @@ extern void needstack(int); #define pow10 p9pow10 #endif +/* + * just enough information so that libc can be + * properly locked without dragging in all of libthread + */ +typedef struct _Thread _Thread; +typedef struct _Threadlist _Threadlist; +struct _Threadlist +{ + _Thread *head; + _Thread *tail; +}; + +extern _Thread *(*threadnow)(void); + /* * synchronization */ typedef struct Lock Lock; struct Lock { -#ifdef PLAN9_PTHREADS +#ifdef PLAN9PORT_USING_PTHREADS int init; pthread_mutex_t mutex; -#else - int val; #endif + int held; }; -extern int _tas(int*); extern void lock(Lock*); extern void unlock(Lock*); extern int canlock(Lock*); +extern int (*_lock)(Lock*, int, ulong); +extern void (*_unlock)(Lock*, ulong); -/* - * 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 +typedef struct QLock QLock; +struct QLock { - int asleep; - Lock *l; - void *arg; - int pid; -#ifdef PLAN9_PTHREADS - pthread_cond_t cond; -#endif + Lock l; + _Thread *owner; + _Threadlist waiting; }; -extern void _procsleep(_Procrend*); -extern void _procwakeup(_Procrend*); +extern void qlock(QLock*); +extern void qunlock(QLock*); +extern int canqlock(QLock*); +extern int (*_qlock)(QLock*, int, ulong); /* do not use */ +extern void (*_qunlock)(QLock*, ulong); -typedef struct QLp QLp; -struct QLp +typedef struct Rendez Rendez; +struct Rendez { - Lock inuse; - QLp *next; - _Procrend rend; - char state; + QLock *l; + _Threadlist waiting; }; -typedef -struct QLock -{ - Lock lock; - int locked; - QLp *head; - QLp *tail; -} QLock; - -extern void qlock(QLock*); -extern void qunlock(QLock*); -extern int canqlock(QLock*); -extern void _qlockinit(void(*)(_Procrend*), void(*)(_Procrend*)); /* called only by the thread library */ +extern void rsleep(Rendez*); /* unlocks r->l, sleeps, locks r->l again */ +extern int rwakeup(Rendez*); +extern int rwakeupall(Rendez*); +extern void (*_rsleep)(Rendez*, ulong); /* do not use */ +extern int (*_rwakeup)(Rendez*, int, ulong); -typedef +typedef struct RWLock RWLock; struct RWLock { - Lock lock; - int readers; /* number of readers */ - int writer; /* number of writers */ - QLp *head; /* list of waiting processes */ - QLp *tail; -} RWLock; + Lock l; + int readers; + _Thread *writer; + _Threadlist rwaiting; + _Threadlist wwaiting; +}; extern void rlock(RWLock*); extern void runlock(RWLock*); @@ -503,18 +498,14 @@ extern int canrlock(RWLock*); extern void wlock(RWLock*); extern void wunlock(RWLock*); extern int canwlock(RWLock*); +extern int (*_rlock)(RWLock*, int, ulong); /* do not use */ +extern int (*_wlock)(RWLock*, int, ulong); +extern void (*_runlock)(RWLock*, ulong); +extern void (*_wunlock)(RWLock*, ulong); -typedef -struct Rendez -{ - QLock *l; - QLp *head; - QLp *tail; -} Rendez; - -extern void rsleep(Rendez*); /* unlocks r->l, sleeps, locks r->l again */ -extern int rwakeup(Rendez*); -extern int rwakeupall(Rendez*); +/* + * per-process private data + */ extern void** privalloc(void); extern void privfree(void**); @@ -589,7 +580,7 @@ extern void freenetconninfo(NetConnInfo*); #define OTRUNC 16 /* or'ed in (except for exec), truncate file first */ #define OCEXEC 32 /* or'ed in, close on exec */ #define ORCLOSE 64 /* or'ed in, remove on close */ -#define ODIRECT 128 /* or'ed in, bypass the cache */ +#define ODIRECT 128 /* or'ed in, direct access */ #define OEXCL 0x1000 /* or'ed in, exclusive use (create only) */ #define OLOCK 0x2000 /* or'ed in, lock after opening */ @@ -724,6 +715,10 @@ extern int unmount(char*, char*); */ extern int noted(int); extern int notify(void(*)(void*, char*)); +extern void notifyenable(char*); +extern void notifydisable(char*); +extern void notifyon(char*); +extern void notifyoff(char*); extern int p9open(char*, int); extern int fd2path(int, char*, int); extern int p9pipe(int*); @@ -772,6 +767,7 @@ extern ulong rendezvous(ulong, ulong); #define rfork p9rfork /* #define access p9access */ #define create p9create +#undef open #define open p9open #define pipe p9pipe #endif @@ -801,8 +797,14 @@ extern int post9pservice(int, char*); #endif /* compiler directives on plan 9 */ -#define USED(x) if(x){}else{} #define SET(x) ((x)=0) +#define USED(x) if(x){}else{} +#ifdef __GNUC__ +# if __GNUC__ >= 3 +# undef USED +# define USED(x) { ulong __y __attribute__ ((unused)); __y = (ulong)(x); } +# endif +#endif /* command line */ extern char *argv0; -- cgit v1.2.3