andre@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: #ifndef prsem_h___ andre@0: #define prsem_h___ andre@0: andre@0: /* andre@0: ** API for counting semaphores. Semaphores are counting synchronizing andre@0: ** variables based on a lock and a condition variable. They are lightweight andre@0: ** contention control for a given count of resources. andre@0: */ andre@0: #include "prtypes.h" andre@0: andre@0: PR_BEGIN_EXTERN_C andre@0: andre@0: typedef struct PRSemaphore PRSemaphore; andre@0: andre@0: /* andre@0: ** Create a new semaphore object. andre@0: */ andre@0: NSPR_API(PRSemaphore*) PR_NewSem(PRUintn value); andre@0: andre@0: /* andre@0: ** Destroy the given semaphore object. andre@0: ** andre@0: */ andre@0: NSPR_API(void) PR_DestroySem(PRSemaphore *sem); andre@0: andre@0: /* andre@0: ** Wait on a Semaphore. andre@0: ** andre@0: ** This routine allows a calling thread to wait or proceed depending upon the andre@0: ** state of the semahore sem. The thread can proceed only if the counter value andre@0: ** of the semaphore sem is currently greater than 0. If the value of semaphore andre@0: ** sem is positive, it is decremented by one and the routine returns immediately andre@0: ** allowing the calling thread to continue. If the value of semaphore sem is 0, andre@0: ** the calling thread blocks awaiting the semaphore to be released by another andre@0: ** thread. andre@0: ** andre@0: ** This routine can return PR_PENDING_INTERRUPT if the waiting thread andre@0: ** has been interrupted. andre@0: */ andre@0: NSPR_API(PRStatus) PR_WaitSem(PRSemaphore *sem); andre@0: andre@0: /* andre@0: ** This routine increments the counter value of the semaphore. If other threads andre@0: ** are blocked for the semaphore, then the scheduler will determine which ONE andre@0: ** thread will be unblocked. andre@0: */ andre@0: NSPR_API(void) PR_PostSem(PRSemaphore *sem); andre@0: andre@0: /* andre@0: ** Returns the value of the semaphore referenced by sem without affecting andre@0: ** the state of the semaphore. The value represents the semaphore vaule andre@0: F** at the time of the call, but may not be the actual value when the andre@0: ** caller inspects it. andre@0: */ andre@0: NSPR_API(PRUintn) PR_GetValueSem(PRSemaphore *sem); andre@0: andre@0: PR_END_EXTERN_C andre@0: andre@0: #endif /* prsem_h___ */