Back to index

glibc  2.9
Functions | Variables
sem_close.c File Reference
#include <errno.h>
#include <search.h>
#include <sys/mman.h>
#include "semaphoreP.h"

Go to the source code of this file.


static void walker (const void *inodep, const VISIT which, const int depth)
int sem_close (sem_t *sem)


static sem_tthe_sem
static struct inuse_semrec

Function Documentation

int sem_close ( sem_t sem)

Definition at line 44 of file sem_close.c.

  int result = 0;

  /* Get the lock.  */
  lll_lock (__sem_mappings_lock, LLL_PRIVATE);

  /* Locate the entry for the mapping the caller provided.  */
  rec = NULL;
  the_sem = sem;
  twalk (__sem_mappings, walker);
  if  (rec != NULL)
      /* Check the reference counter.  If it is going to be zero, free
        all the resources.  */
      if (--rec->refcnt == 0)
         /* Remove the record from the tree.  */
         (void) tdelete (rec, &__sem_mappings, __sem_search);

         result = munmap (rec->sem, sizeof (sem_t));

         free (rec);
      /* This is no valid semaphore.  */
      result = -1;
      __set_errno (EINVAL);

  /* Release the lock.  */
  lll_unlock (__sem_mappings_lock, LLL_PRIVATE);

  return result;

Here is the call graph for this function:

static void walker ( const void *  inodep,
const VISIT  which,
const int  depth 
) [static]

Definition at line 34 of file sem_close.c.

  struct inuse_sem *nodep = *(struct inuse_sem **) inodep;

  if (nodep->sem == the_sem)
    rec = nodep;

Here is the caller graph for this function:

Variable Documentation

struct inuse_sem* rec [static]

Definition at line 31 of file sem_close.c.

sem_t* the_sem [static]

Definition at line 30 of file sem_close.c.