From 76193d7cb0457807b2f0b95f909ab5de19480cd7 Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 30 Sep 2003 17:47:42 +0000 Subject: Initial revision --- src/libthread/id.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 src/libthread/id.c (limited to 'src/libthread/id.c') diff --git a/src/libthread/id.c b/src/libthread/id.c new file mode 100644 index 00000000..727798d3 --- /dev/null +++ b/src/libthread/id.c @@ -0,0 +1,135 @@ +#include "threadimpl.h" + +int +threadid(void) +{ + return _threadgetproc()->thread->id; +} + +int +threadpid(int id) +{ + int pid; + Proc *p; + Thread *t; + + if (id < 0) + return -1; + if (id == 0) + return _threadgetproc()->pid; + lock(&_threadpq.lock); + for (p = _threadpq.head; p->next; p = p->next){ + lock(&p->lock); + for (t = p->threads.head; t; t = t->nextt) + if (t->id == id){ + pid = p->pid; + unlock(&p->lock); + unlock(&_threadpq.lock); + return pid; + } + unlock(&p->lock); + } + unlock(&_threadpq.lock); + return -1; +} + +int +threadsetgrp(int ng) +{ + int og; + Thread *t; + + t = _threadgetproc()->thread; + og = t->grp; + t->grp = ng; + return og; +} + +int +threadgetgrp(void) +{ + return _threadgetproc()->thread->grp; +} + +void +threadsetname(char *name) +{ +/* + int fd, n; + char buf[128], *s; +*/ + Proc *p; + Thread *t; + + p = _threadgetproc(); + t = p->thread; + if (t->cmdname) + free(t->cmdname); + t->cmdname = strdup(name); +/* Plan 9 only + if(p->nthreads == 1){ + snprint(buf, sizeof buf, "#p/%d/args", getpid()); + if((fd = open(buf, OWRITE)) >= 0){ + snprint(buf, sizeof buf, "%s [%s]", argv0, name); + n = strlen(buf)+1; + s = strchr(buf, ' '); + if(s) + *s = '\0'; + write(fd, buf, n); + close(fd); + } + } +*/ +} + +char* +threadgetname(void) +{ + return _threadgetproc()->thread->cmdname; +} + +void** +threaddata(void) +{ + return &_threadgetproc()->thread->udata[0]; +} + +void** +procdata(void) +{ + return &_threadgetproc()->udata; +} + +static Lock privlock; +static int privmask = 1; + +int +tprivalloc(void) +{ + int i; + + lock(&privlock); + for(i=0; i= NPRIV) + abort(); + lock(&privlock); + privmask &= ~(1<thread->udata[i]; +} -- cgit v1.2.3