Back to index

lightning-sunbird  0.9+nobinonly
Functions
prsem.c File Reference
#include "primpl.h"
#include "obsolete/prsem.h"

Go to the source code of this file.

Functions

 PR_IMPLEMENT (PRSemaphore *)
 PR_IMPLEMENT (void)
 PR_IMPLEMENT (PRStatus)

Function Documentation

Definition at line 50 of file prsem.c.

{
    PRSemaphore *sem;
    PRCondVar *cvar;
    PRLock *lock;

    sem = PR_NEWZAP(PRSemaphore);
    if (sem) {
#ifdef HAVE_CVAR_BUILT_ON_SEM
        _PR_MD_NEW_SEM(&sem->md, value);
#else
        lock = PR_NewLock();
        if (!lock) {
            PR_DELETE(sem);
            return NULL;
       }

        cvar = PR_NewCondVar(lock);
        if (!cvar) {
            PR_DestroyLock(lock);
            PR_DELETE(sem);
            return NULL;
       }
       sem->cvar = cvar;
       sem->count = value;
#endif
    }
    return sem;
}

Here is the call graph for this function:

Definition at line 85 of file prsem.c.

{
#ifdef HAVE_CVAR_BUILT_ON_SEM
    _PR_MD_DESTROY_SEM(&sem->md);
#else
    PR_ASSERT(sem->waiters == 0);

    PR_DestroyLock(sem->cvar->lock);
    PR_DestroyCondVar(sem->cvar);
#endif
    PR_DELETE(sem);
}

Here is the call graph for this function:

Definition at line 112 of file prsem.c.

{
       PRStatus status = PR_SUCCESS;

#ifdef HAVE_CVAR_BUILT_ON_SEM
       return _PR_MD_WAIT_SEM(&sem->md);
#else
       PR_Lock(sem->cvar->lock);
       while (sem->count == 0) {
              sem->waiters++;
              status = PR_WaitCondVar(sem->cvar, PR_INTERVAL_NO_TIMEOUT);
              sem->waiters--;
              if (status != PR_SUCCESS)
                     break;
       }
       if (status == PR_SUCCESS)
              sem->count--;
       PR_Unlock(sem->cvar->lock);
#endif
       
       return (status);
}

Here is the call graph for this function: