From c6687d4591964cb13df87f55ec4770e778a4a55c Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 21 Sep 2004 01:11:28 +0000 Subject: Continue the pthreads torture. --- src/lib9/_p9proc-getpid.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/lib9/_p9proc-getpid.c (limited to 'src/lib9/_p9proc-getpid.c') diff --git a/src/lib9/_p9proc-getpid.c b/src/lib9/_p9proc-getpid.c new file mode 100644 index 00000000..9543bf24 --- /dev/null +++ b/src/lib9/_p9proc-getpid.c @@ -0,0 +1,113 @@ +/* + * This needs to be callable from a signal handler, so it has been + * written to avoid locks. The only lock is the one used to acquire + * an entry in the table, and we make sure that acquiring is done + * when not in a handler. Lookup and delete do not need locks. + * It's a scan-forward hash table. To avoid breaking chains, + * T ((void*)-1) is used as a non-breaking nil. + */ + +#include +#include +#include "9proc.h" + +enum { PIDHASH = 1021 }; + +#define T ((void*)-1) +static Uproc *alluproc[PIDHASH]; +static int allupid[PIDHASH]; +static Lock uproclock; + +void +_clearuproc(void) +{ + int i; + + /* called right after fork - no locking needed */ + for(i=0; ipid = pid; + lock(&uproclock); + h = pid%PIDHASH; + for(i=0; i