nsprpub/pr/include/obsolete/prsem.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef prsem_h___
     7 #define prsem_h___
     9 /*
    10 ** API for counting semaphores. Semaphores are counting synchronizing 
    11 ** variables based on a lock and a condition variable.  They are lightweight 
    12 ** contention control for a given count of resources.
    13 */
    14 #include "prtypes.h"
    16 PR_BEGIN_EXTERN_C
    18 typedef struct PRSemaphore PRSemaphore;
    20 /*
    21 ** Create a new semaphore object.
    22 */
    23 NSPR_API(PRSemaphore*) PR_NewSem(PRUintn value);
    25 /*
    26 ** Destroy the given semaphore object.
    27 **
    28 */
    29 NSPR_API(void) PR_DestroySem(PRSemaphore *sem);
    31 /*
    32 ** Wait on a Semaphore.
    33 ** 
    34 ** This routine allows a calling thread to wait or proceed depending upon the 
    35 ** state of the semahore sem. The thread can proceed only if the counter value 
    36 ** of the semaphore sem is currently greater than 0. If the value of semaphore 
    37 ** sem is positive, it is decremented by one and the routine returns immediately 
    38 ** allowing the calling thread to continue. If the value of semaphore sem is 0, 
    39 ** the calling thread blocks awaiting the semaphore to be released by another 
    40 ** thread.
    41 ** 
    42 ** This routine can return PR_PENDING_INTERRUPT if the waiting thread 
    43 ** has been interrupted.
    44 */
    45 NSPR_API(PRStatus) PR_WaitSem(PRSemaphore *sem);
    47 /*
    48 ** This routine increments the counter value of the semaphore. If other threads 
    49 ** are blocked for the semaphore, then the scheduler will determine which ONE 
    50 ** thread will be unblocked.
    51 */
    52 NSPR_API(void) PR_PostSem(PRSemaphore *sem);
    54 /*
    55 ** Returns the value of the semaphore referenced by sem without affecting
    56 ** the state of the semaphore.  The value represents the semaphore vaule
    57 F** at the time of the call, but may not be the actual value when the
    58 ** caller inspects it.
    59 */
    60 NSPR_API(PRUintn) PR_GetValueSem(PRSemaphore *sem);
    62 PR_END_EXTERN_C
    64 #endif /* prsem_h___ */

mercurial