PageRenderTime 138ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/gecko_api/include/prcvar.h

http://firefox-mac-pdf.googlecode.com/
C++ Header | 126 lines | 13 code | 11 blank | 102 comment | 0 complexity | fc2b1e3ac96e37753a2a6a01a6704f17 MD5 | raw file
  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * The Original Code is the Netscape Portable Runtime (NSPR).
  16. *
  17. * The Initial Developer of the Original Code is
  18. * Netscape Communications Corporation.
  19. * Portions created by the Initial Developer are Copyright (C) 1998-2000
  20. * the Initial Developer. All Rights Reserved.
  21. *
  22. * Contributor(s):
  23. *
  24. * Alternatively, the contents of this file may be used under the terms of
  25. * either the GNU General Public License Version 2 or later (the "GPL"), or
  26. * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  27. * in which case the provisions of the GPL or the LGPL are applicable instead
  28. * of those above. If you wish to allow use of your version of this file only
  29. * under the terms of either the GPL or the LGPL, and not to allow others to
  30. * use your version of this file under the terms of the MPL, indicate your
  31. * decision by deleting the provisions above and replace them with the notice
  32. * and other provisions required by the GPL or the LGPL. If you do not delete
  33. * the provisions above, a recipient may use your version of this file under
  34. * the terms of any one of the MPL, the GPL or the LGPL.
  35. *
  36. * ***** END LICENSE BLOCK ***** */
  37. #ifndef prcvar_h___
  38. #define prcvar_h___
  39. #include "prlock.h"
  40. #include "prinrval.h"
  41. PR_BEGIN_EXTERN_C
  42. typedef struct PRCondVar PRCondVar;
  43. /*
  44. ** Create a new condition variable.
  45. **
  46. ** "lock" is the lock used to protect the condition variable.
  47. **
  48. ** Condition variables are synchronization objects that threads can use
  49. ** to wait for some condition to occur.
  50. **
  51. ** This may fail if memory is tight or if some operating system resource
  52. ** is low. In such cases, a NULL will be returned.
  53. */
  54. NSPR_API(PRCondVar*) PR_NewCondVar(PRLock *lock);
  55. /*
  56. ** Destroy a condition variable. There must be no thread
  57. ** waiting on the condvar. The caller is responsible for guaranteeing
  58. ** that the condvar is no longer in use.
  59. **
  60. */
  61. NSPR_API(void) PR_DestroyCondVar(PRCondVar *cvar);
  62. /*
  63. ** The thread that waits on a condition is blocked in a "waiting on
  64. ** condition" state until another thread notifies the condition or a
  65. ** caller specified amount of time expires. The lock associated with
  66. ** the condition variable will be released, which must have be held
  67. ** prior to the call to wait.
  68. **
  69. ** Logically a notified thread is moved from the "waiting on condition"
  70. ** state and made "ready." When scheduled, it will attempt to reacquire
  71. ** the lock that it held when wait was called.
  72. **
  73. ** The timeout has two well known values, PR_INTERVAL_NO_TIMEOUT and
  74. ** PR_INTERVAL_NO_WAIT. The former value requires that a condition be
  75. ** notified (or the thread interrupted) before it will resume from the
  76. ** wait. If the timeout has a value of PR_INTERVAL_NO_WAIT, the effect
  77. ** is to release the lock, possibly causing a rescheduling within the
  78. ** runtime, then immediately attempting to reacquire the lock and resume.
  79. **
  80. ** Any other value for timeout will cause the thread to be rescheduled
  81. ** either due to explicit notification or an expired interval. The latter
  82. ** must be determined by treating time as one part of the monitored data
  83. ** being protected by the lock and tested explicitly for an expired
  84. ** interval.
  85. **
  86. ** Returns PR_FAILURE if the caller has not locked the lock associated
  87. ** with the condition variable or the thread was interrupted (PR_Interrupt()).
  88. ** The particular reason can be extracted with PR_GetError().
  89. */
  90. NSPR_API(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout);
  91. /*
  92. ** Notify ONE thread that is currently waiting on 'cvar'. Which thread is
  93. ** dependent on the implementation of the runtime. Common sense would dictate
  94. ** that all threads waiting on a single condition have identical semantics,
  95. ** therefore which one gets notified is not significant.
  96. **
  97. ** The calling thead must hold the lock that protects the condition, as
  98. ** well as the invariants that are tightly bound to the condition, when
  99. ** notify is called.
  100. **
  101. ** Returns PR_FAILURE if the caller has not locked the lock associated
  102. ** with the condition variable.
  103. */
  104. NSPR_API(PRStatus) PR_NotifyCondVar(PRCondVar *cvar);
  105. /*
  106. ** Notify all of the threads waiting on the condition variable. The order
  107. ** that the threads are notified is indeterminant. The lock that protects
  108. ** the condition must be held.
  109. **
  110. ** Returns PR_FAILURE if the caller has not locked the lock associated
  111. ** with the condition variable.
  112. */
  113. NSPR_API(PRStatus) PR_NotifyAllCondVar(PRCondVar *cvar);
  114. PR_END_EXTERN_C
  115. #endif /* prcvar_h___ */