X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fthread%2Fsem_open.c;h=6fff71a8512090eb588bb0329e30a51917ca8242;hp=55d5ef6b7808bae8e070e1d979d0b67083407375;hb=81af503610761a69476a3adbe8341fa8b6d078aa;hpb=6fc5fdbdc70dd17ea8e681a361fb4dae541ee953 diff --git a/src/thread/sem_open.c b/src/thread/sem_open.c index 55d5ef6b..6fff71a8 100644 --- a/src/thread/sem_open.c +++ b/src/thread/sem_open.c @@ -9,32 +9,32 @@ #include #include #include +#include +#include -static void *find_map(int fd) +static struct { + ino_t ino; + sem_t *sem; + int refcnt; +} *semtab; + +static int semcnt; +static pthread_spinlock_t lock; +static pthread_once_t once; + +static void init() { - char c; - struct stat st; - FILE *f; - void *addr; - unsigned long long off, ino; - char buf[100]; + semtab = calloc(sizeof *semtab, SEM_NSEMS_MAX); +} - if (fstat(fd, &st) < 0) return 0; - if (!(f = fopen("/proc/self/maps", "rb"))) return 0; - - while (fgets(buf, sizeof buf, f)) { - sscanf(buf, "%lx-%*lx %*s %llx %*x:%*x %llu /dev/shm%c", - (long *)&addr, &off, &ino, &c); - while (!strchr(buf, '\n') && fgets(buf, sizeof buf, f)); - if (c!='/') continue; - c = 0; - if (!off && st.st_ino == ino) { - fclose(f); - return addr; - } - } - fclose(f); - return 0; +static sem_t *find_map(ino_t ino) +{ + int i; + for (i=0; i