home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / obsolete / prsem.h < prev   
C/C++ Source or Header  |  1998-07-21  |  3KB  |  78 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef prsem_h___
  20. #define prsem_h___
  21.  
  22. /*
  23. ** API for counting semaphores. Semaphores are counting synchronizing 
  24. ** variables based on a lock and a condition variable.  They are lightweight 
  25. ** contention control for a given count of resources.
  26. */
  27. #include "prtypes.h"
  28.  
  29. PR_BEGIN_EXTERN_C
  30.  
  31. typedef struct PRSemaphore PRSemaphore;
  32.  
  33. /*
  34. ** Create a new semaphore object.
  35. */
  36. PR_EXTERN(PRSemaphore*) PR_NewSem(PRUintn value);
  37.  
  38. /*
  39. ** Destroy the given semaphore object.
  40. **
  41. */
  42. PR_EXTERN(void) PR_DestroySem(PRSemaphore *sem);
  43.  
  44. /*
  45. ** Wait on a Semaphore.
  46. ** 
  47. ** This routine allows a calling thread to wait or proceed depending upon the 
  48. ** state of the semahore sem. The thread can proceed only if the counter value 
  49. ** of the semaphore sem is currently greater than 0. If the value of semaphore 
  50. ** sem is positive, it is decremented by one and the routine returns immediately 
  51. ** allowing the calling thread to continue. If the value of semaphore sem is 0, 
  52. ** the calling thread blocks awaiting the semaphore to be released by another 
  53. ** thread.
  54. ** 
  55. ** This routine can return PR_PENDING_INTERRUPT if the waiting thread 
  56. ** has been interrupted.
  57. */
  58. PR_EXTERN(PRStatus) PR_WaitSem(PRSemaphore *sem);
  59.  
  60. /*
  61. ** This routine increments the counter value of the semaphore. If other threads 
  62. ** are blocked for the semaphore, then the scheduler will determine which ONE 
  63. ** thread will be unblocked.
  64. */
  65. PR_EXTERN(void) PR_PostSem(PRSemaphore *sem);
  66.  
  67. /*
  68. ** Returns the value of the semaphore referenced by sem without affecting
  69. ** the state of the semaphore.  The value represents the semaphore vaule
  70. F** at the time of the call, but may not be the actual value when the
  71. ** caller inspects it.
  72. */
  73. PR_EXTERN(PRUintn) PR_GetValueSem(PRSemaphore *sem);
  74.  
  75. PR_END_EXTERN_C
  76.  
  77. #endif /* prsem_h___ */
  78.