PageRenderTime 68ms CodeModel.GetById 62ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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 *
  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 ***** */
 38#ifndef prcvar_h___
 39#define prcvar_h___
 41#include "prlock.h"
 42#include "prinrval.h"
 46typedef struct PRCondVar PRCondVar;
 49** Create a new condition variable.
 51** 	"lock" is the lock used to protect the condition variable.
 53** Condition variables are synchronization objects that threads can use
 54** to wait for some condition to occur.
 56** This may fail if memory is tight or if some operating system resource
 57** is low. In such cases, a NULL will be returned.
 59NSPR_API(PRCondVar*) PR_NewCondVar(PRLock *lock);
 62** Destroy a condition variable. There must be no thread
 63** waiting on the condvar. The caller is responsible for guaranteeing
 64** that the condvar is no longer in use.
 67NSPR_API(void) PR_DestroyCondVar(PRCondVar *cvar);
 70** The thread that waits on a condition is blocked in a "waiting on
 71** condition" state until another thread notifies the condition or a
 72** caller specified amount of time expires. The lock associated with
 73** the condition variable will be released, which must have be held
 74** prior to the call to wait.
 76** Logically a notified thread is moved from the "waiting on condition"
 77** state and made "ready." When scheduled, it will attempt to reacquire
 78** the lock that it held when wait was called.
 80** The timeout has two well known values, PR_INTERVAL_NO_TIMEOUT and
 81** PR_INTERVAL_NO_WAIT. The former value requires that a condition be
 82** notified (or the thread interrupted) before it will resume from the
 83** wait. If the timeout has a value of PR_INTERVAL_NO_WAIT, the effect
 84** is to release the lock, possibly causing a rescheduling within the
 85** runtime, then immediately attempting to reacquire the lock and resume.
 87** Any other value for timeout will cause the thread to be rescheduled
 88** either due to explicit notification or an expired interval. The latter
 89** must be determined by treating time as one part of the monitored data
 90** being protected by the lock and tested explicitly for an expired
 91** interval.
 93** Returns PR_FAILURE if the caller has not locked the lock associated
 94** with the condition variable or the thread was interrupted (PR_Interrupt()).
 95** The particular reason can be extracted with PR_GetError().
 97NSPR_API(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout);
100** Notify ONE thread that is currently waiting on 'cvar'. Which thread is
101** dependent on the implementation of the runtime. Common sense would dictate
102** that all threads waiting on a single condition have identical semantics,
103** therefore which one gets notified is not significant. 
105** The calling thead must hold the lock that protects the condition, as
106** well as the invariants that are tightly bound to the condition, when
107** notify is called.
109** Returns PR_FAILURE if the caller has not locked the lock associated
110** with the condition variable.
112NSPR_API(PRStatus) PR_NotifyCondVar(PRCondVar *cvar);
115** Notify all of the threads waiting on the condition variable. The order
116** that the threads are notified is indeterminant. The lock that protects
117** the condition must be held.
119** Returns PR_FAILURE if the caller has not locked the lock associated
120** with the condition variable.
122NSPR_API(PRStatus) PR_NotifyAllCondVar(PRCondVar *cvar);
126#endif /* prcvar_h___ */