#include #include #include #include pthread_mutex_t pm_rendlock; enum { NHLOG = 7, NHASH = (1<hash) { if(t->tag == tag) { rval = t->val; t->val = value; t->tag = 0; pm_fprint(2, "%d leaving rend-pthread to sleep, perchance to dream\n", getpid()); if(pthread_mutex_unlock(&pm_rendlock)) pm_panic("pthread_mutex_unlock failed"); pm_splx(s); if(pthread_cond_signal(&(t->cv))) pm_panic("pthread_cond_signal failed"); return rval; } } t = ft; if(t == 0) t = malloc(sizeof(Tag)); else ft = t->free; t->tag = tag; t->val = value; t->hash = *l; if(pthread_cond_init(&(t->cv), NULL)) pm_panic("pthread_cond_init failed"); *l = t; while(t->tag){ pthread_mutex_unlock(&pm_rendlock); pm_splx(s); pthread_cond_wait(&(t->cv), NULL); s = pm_splhi(); pthread_mutex_lock(&pm_rendlock); } rval = t->val; for(f = *l; f; f = f->hash){ if(f == t) { *l = f->hash; break; } l = &f->hash; } t->free = ft; ft = t; pm_fprint(2, "%d leaving rend-pthread\n",getpid()); if(pthread_mutex_unlock(&pm_rendlock)) pm_panic("pthread_mutex_unlock failed"); pm_splx(s); return rval; }