1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #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_t *sem)
- {
- int result = 0;
-
- lll_lock (__sem_mappings_lock, LLL_PRIVATE);
-
- 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, LLL_PRIVATE);
- return result;
- }
|