nsprpub/pr/include/prcvar.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/nsprpub/pr/include/prcvar.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#ifndef prcvar_h___
    1.10 +#define prcvar_h___
    1.11 +
    1.12 +#include "prlock.h"
    1.13 +#include "prinrval.h"
    1.14 +
    1.15 +PR_BEGIN_EXTERN_C
    1.16 +
    1.17 +typedef struct PRCondVar PRCondVar;
    1.18 +
    1.19 +/*
    1.20 +** Create a new condition variable.
    1.21 +**
    1.22 +** 	"lock" is the lock used to protect the condition variable.
    1.23 +**
    1.24 +** Condition variables are synchronization objects that threads can use
    1.25 +** to wait for some condition to occur.
    1.26 +**
    1.27 +** This may fail if memory is tight or if some operating system resource
    1.28 +** is low. In such cases, a NULL will be returned.
    1.29 +*/
    1.30 +NSPR_API(PRCondVar*) PR_NewCondVar(PRLock *lock);
    1.31 +
    1.32 +/*
    1.33 +** Destroy a condition variable. There must be no thread
    1.34 +** waiting on the condvar. The caller is responsible for guaranteeing
    1.35 +** that the condvar is no longer in use.
    1.36 +**
    1.37 +*/
    1.38 +NSPR_API(void) PR_DestroyCondVar(PRCondVar *cvar);
    1.39 +
    1.40 +/*
    1.41 +** The thread that waits on a condition is blocked in a "waiting on
    1.42 +** condition" state until another thread notifies the condition or a
    1.43 +** caller specified amount of time expires. The lock associated with
    1.44 +** the condition variable will be released, which must have be held
    1.45 +** prior to the call to wait.
    1.46 +**
    1.47 +** Logically a notified thread is moved from the "waiting on condition"
    1.48 +** state and made "ready." When scheduled, it will attempt to reacquire
    1.49 +** the lock that it held when wait was called.
    1.50 +**
    1.51 +** The timeout has two well known values, PR_INTERVAL_NO_TIMEOUT and
    1.52 +** PR_INTERVAL_NO_WAIT. The former value requires that a condition be
    1.53 +** notified (or the thread interrupted) before it will resume from the
    1.54 +** wait. If the timeout has a value of PR_INTERVAL_NO_WAIT, the effect
    1.55 +** is to release the lock, possibly causing a rescheduling within the
    1.56 +** runtime, then immediately attempting to reacquire the lock and resume.
    1.57 +**
    1.58 +** Any other value for timeout will cause the thread to be rescheduled
    1.59 +** either due to explicit notification or an expired interval. The latter
    1.60 +** must be determined by treating time as one part of the monitored data
    1.61 +** being protected by the lock and tested explicitly for an expired
    1.62 +** interval.
    1.63 +**
    1.64 +** Returns PR_FAILURE if the caller has not locked the lock associated
    1.65 +** with the condition variable or the thread was interrupted (PR_Interrupt()).
    1.66 +** The particular reason can be extracted with PR_GetError().
    1.67 +*/
    1.68 +NSPR_API(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout);
    1.69 +
    1.70 +/*
    1.71 +** Notify ONE thread that is currently waiting on 'cvar'. Which thread is
    1.72 +** dependent on the implementation of the runtime. Common sense would dictate
    1.73 +** that all threads waiting on a single condition have identical semantics,
    1.74 +** therefore which one gets notified is not significant. 
    1.75 +**
    1.76 +** The calling thead must hold the lock that protects the condition, as
    1.77 +** well as the invariants that are tightly bound to the condition, when
    1.78 +** notify is called.
    1.79 +**
    1.80 +** Returns PR_FAILURE if the caller has not locked the lock associated
    1.81 +** with the condition variable.
    1.82 +*/
    1.83 +NSPR_API(PRStatus) PR_NotifyCondVar(PRCondVar *cvar);
    1.84 +
    1.85 +/*
    1.86 +** Notify all of the threads waiting on the condition variable. The order
    1.87 +** that the threads are notified is indeterminant. The lock that protects
    1.88 +** the condition must be held.
    1.89 +**
    1.90 +** Returns PR_FAILURE if the caller has not locked the lock associated
    1.91 +** with the condition variable.
    1.92 +*/
    1.93 +NSPR_API(PRStatus) PR_NotifyAllCondVar(PRCondVar *cvar);
    1.94 +
    1.95 +PR_END_EXTERN_C
    1.96 +
    1.97 +#endif /* prcvar_h___ */

mercurial