Back to index

lightning-sunbird  0.9+nobinonly
prcvar.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is the Netscape Portable Runtime (NSPR).
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #ifndef prcvar_h___
00039 #define prcvar_h___
00040 
00041 #include "prlock.h"
00042 #include "prinrval.h"
00043 
00044 PR_BEGIN_EXTERN_C
00045 
00046 typedef struct PRCondVar PRCondVar;
00047 
00048 /*
00049 ** Create a new condition variable.
00050 **
00051 **     "lock" is the lock used to protect the condition variable.
00052 **
00053 ** Condition variables are synchronization objects that threads can use
00054 ** to wait for some condition to occur.
00055 **
00056 ** This may fail if memory is tight or if some operating system resource
00057 ** is low. In such cases, a NULL will be returned.
00058 */
00059 NSPR_API(PRCondVar*) PR_NewCondVar(PRLock *lock);
00060 
00061 /*
00062 ** Destroy a condition variable. There must be no thread
00063 ** waiting on the condvar. The caller is responsible for guaranteeing
00064 ** that the condvar is no longer in use.
00065 **
00066 */
00067 NSPR_API(void) PR_DestroyCondVar(PRCondVar *cvar);
00068 
00069 /*
00070 ** The thread that waits on a condition is blocked in a "waiting on
00071 ** condition" state until another thread notifies the condition or a
00072 ** caller specified amount of time expires. The lock associated with
00073 ** the condition variable will be released, which must have be held
00074 ** prior to the call to wait.
00075 **
00076 ** Logically a notified thread is moved from the "waiting on condition"
00077 ** state and made "ready." When scheduled, it will attempt to reacquire
00078 ** the lock that it held when wait was called.
00079 **
00080 ** The timeout has two well known values, PR_INTERVAL_NO_TIMEOUT and
00081 ** PR_INTERVAL_NO_WAIT. The former value requires that a condition be
00082 ** notified (or the thread interrupted) before it will resume from the
00083 ** wait. If the timeout has a value of PR_INTERVAL_NO_WAIT, the effect
00084 ** is to release the lock, possibly causing a rescheduling within the
00085 ** runtime, then immediately attempting to reacquire the lock and resume.
00086 **
00087 ** Any other value for timeout will cause the thread to be rescheduled
00088 ** either due to explicit notification or an expired interval. The latter
00089 ** must be determined by treating time as one part of the monitored data
00090 ** being protected by the lock and tested explicitly for an expired
00091 ** interval.
00092 **
00093 ** Returns PR_FAILURE if the caller has not locked the lock associated
00094 ** with the condition variable or the thread was interrupted (PR_Interrupt()).
00095 ** The particular reason can be extracted with PR_GetError().
00096 */
00097 NSPR_API(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout);
00098 
00099 /*
00100 ** Notify ONE thread that is currently waiting on 'cvar'. Which thread is
00101 ** dependent on the implementation of the runtime. Common sense would dictate
00102 ** that all threads waiting on a single condition have identical semantics,
00103 ** therefore which one gets notified is not significant. 
00104 **
00105 ** The calling thead must hold the lock that protects the condition, as
00106 ** well as the invariants that are tightly bound to the condition, when
00107 ** notify is called.
00108 **
00109 ** Returns PR_FAILURE if the caller has not locked the lock associated
00110 ** with the condition variable.
00111 */
00112 NSPR_API(PRStatus) PR_NotifyCondVar(PRCondVar *cvar);
00113 
00114 /*
00115 ** Notify all of the threads waiting on the condition variable. The order
00116 ** that the threads are notified is indeterminant. The lock that protects
00117 ** the condition must be held.
00118 **
00119 ** Returns PR_FAILURE if the caller has not locked the lock associated
00120 ** with the condition variable.
00121 */
00122 NSPR_API(PRStatus) PR_NotifyAllCondVar(PRCondVar *cvar);
00123 
00124 PR_END_EXTERN_C
00125 
00126 #endif /* prcvar_h___ */