123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- #include <errno.h>
- #include <search.h>
- #include <sys/mman.h>
- #include "semaphoreP.h"
- static sem_t *the_sem;
- static struct inuse_sem *rec;
- static void
- walker (const void *inodep, const VISIT which, const int depth)
- {
- struct inuse_sem *nodep = *(struct inuse_sem **) inodep;
- if (nodep->sem == the_sem)
- rec = nodep;
- }
- int
- sem_close (sem)
- sem_t *sem;
- {
- int result = 0;
-
- lll_lock (__sem_mappings_lock);
-
- rec = NULL;
- the_sem = sem;
- twalk (__sem_mappings, walker);
- if (rec != NULL)
- {
-
- if (--rec->refcnt == 0)
- {
-
- (void) tdelete (rec, &__sem_mappings, __sem_search);
- result = munmap (rec->sem, sizeof (sem_t));
- free (rec);
- }
- }
- else
- {
-
- result = -1;
- __set_errno (EINVAL);
- }
-
- lll_unlock (__sem_mappings_lock);
- return result;
- }
|