2 * This needs to be callable from a signal handler, so it has been
3 * written to avoid locks. The only lock is the one used to acquire
4 * an entry in the table, and we make sure that acquiring is done
5 * when not in a handler. Lookup and delete do not need locks.
6 * It's a scan-forward hash table. To avoid breaking chains,
7 * T ((void*)-1) is used as a non-breaking nil.
14 enum { PIDHASH = 1021 };
17 static Uproc *alluproc[PIDHASH];
18 static int allupid[PIDHASH];
19 static Lock uproclock;
22 _p9uproc(int inhandler)
27 /* for now, assume getpid is fast or cached */
31 * this part - the lookup - needs to run without locks
32 * so that it can safely be called from within the notify handler.
33 * notify calls _p9uproc, and fork and rfork call _p9uproc
34 * in both parent and child, so if we're in a signal handler,
35 * we should find something in the table.
38 for(i=0; i<PIDHASH; i++){
49 sysfatal("did not find uproc in signal handler");
51 /* need to allocate */
52 while((up = mallocz(sizeof(Uproc), 1)) == nil)
55 up = mallocz(sizeof(Uproc), 1);
58 for(i=0; i<PIDHASH; i++){
59 if(alluproc[h]==T || alluproc[h]==nil){
71 sysfatal("too many processes in uproc table");
83 for(i=0; i<PIDHASH; i++){
89 if(allupid[h] == pid){