home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / nspr30-e.zip / nspr30-e / include / prmon.h < prev    next >
C/C++ Source or Header  |  1998-07-21  |  3KB  |  95 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 prmon_h___
  20. #define prmon_h___
  21.  
  22. #include "prtypes.h"
  23. #include "prinrval.h"
  24.  
  25. PR_BEGIN_EXTERN_C
  26.  
  27. typedef struct PRMonitor PRMonitor;
  28.  
  29. /*
  30. ** Create a new monitor. Monitors are re-entrant locks with a single built-in
  31. ** condition variable.
  32. **
  33. ** This may fail if memory is tight or if some operating system resource
  34. ** is low.
  35. */
  36. PR_EXTERN(PRMonitor*) PR_NewMonitor(void);
  37.  
  38. /*
  39. ** Destroy a monitor. The caller is responsible for guaranteeing that the
  40. ** monitor is no longer in use. There must be no thread waiting on the monitor's
  41. ** condition variable and that the lock is not held.
  42. **
  43. */
  44. PR_EXTERN(void) PR_DestroyMonitor(PRMonitor *mon);
  45.  
  46. /*
  47. ** Enter the lock associated with the monitor. If the calling thread currently
  48. ** is in the monitor, the call to enter will silently succeed. In either case,
  49. ** it will increment the entry count by one.
  50. */
  51. PR_EXTERN(void) PR_EnterMonitor(PRMonitor *mon);
  52.  
  53. /*
  54. ** Decrement the entry count associated with the monitor. If the decremented
  55. ** entry count is zero, the monitor is exited. Returns PR_FAILURE if the
  56. ** calling thread has not entered the monitor.
  57. */
  58. PR_EXTERN(PRStatus) PR_ExitMonitor(PRMonitor *mon);
  59.  
  60. /*
  61. ** Wait for a notify on the monitor's condition variable. Sleep for "ticks"
  62. ** amount of time (if "ticks" is PR_INTERVAL_NO_TIMEOUT then the sleep is
  63. ** indefinite).
  64. **
  65. ** While the thread is waiting it exits the monitor (as if it called
  66. ** PR_ExitMonitor as many times as it had called PR_EnterMonitor).  When
  67. ** the wait has finished the thread regains control of the monitors lock
  68. ** with the same entry count as before the wait began.
  69. **
  70. ** The thread waiting on the monitor will be resumed when the monitor is
  71. ** notified (assuming the thread is the next in line to receive the
  72. ** notify) or when the "ticks" timeout elapses.
  73. **
  74. ** Returns PR_FAILURE if the caller has not entered the monitor.
  75. */
  76. PR_EXTERN(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime ticks);
  77.  
  78. /*
  79. ** Notify a thread waiting on the monitor's condition variable. If a thread
  80. ** is waiting on the condition variable (using PR_Wait) then it is awakened
  81. ** and attempts to reenter the monitor.
  82. */
  83. PR_EXTERN(PRStatus) PR_Notify(PRMonitor *mon);
  84.  
  85. /*
  86. ** Notify all of the threads waiting on the monitor's condition variable.
  87. ** All of threads waiting on the condition are scheduled to reenter the
  88. ** monitor.
  89. */
  90. PR_EXTERN(PRStatus) PR_NotifyAll(PRMonitor *mon);
  91.  
  92. PR_END_EXTERN_C
  93.  
  94. #endif /* prmon_h___ */
  95.