| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 3 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 5 |
|
| 6 |
/* |
| 7 |
** RCCondition - C++ wrapper around NSPR's PRCondVar |
| 8 |
** |
| 9 |
** Conditions have a notion of timeouts. A thread that waits on a condition |
| 10 |
** will resume execution when the condition is notified OR when a specified |
| 11 |
** interval of time has expired. |
| 12 |
** |
| 13 |
** Most applications don't adjust the timeouts on conditions. The literature |
| 14 |
** would argue that all threads waiting on a single condition must have the |
| 15 |
** same semantics. But if an application wishes to modify the timeout with |
| 16 |
** (perhaps) each wait call, that modification should be done consistantly |
| 17 |
** and under protection of the condition's associated lock. |
| 18 |
** |
| 19 |
** The default timeout is infinity. |
| 20 |
*/ |
| 21 |
|
| 22 |
#if defined(_RCCOND_H) |
| 23 |
#else |
| 24 |
#define _RCCOND_H |
| 25 |
|
| 26 |
#include "rclock.h" |
| 27 |
#include "rcbase.h" |
| 28 |
#include "rcinrval.h" |
| 29 |
|
| 30 |
struct PRCondVar; |
| 31 |
|
| 32 |
class PR_IMPLEMENT(RCCondition): public RCBase |
| 33 |
{ |
| 34 |
public: |
| 35 |
RCCondition(RCLock*); /* associates CV with a lock and infinite tmo */ |
| 36 |
virtual ~RCCondition(); |
| 37 |
|
| 38 |
virtual PRStatus Wait(); /* applies object's current timeout */ |
| 39 |
|
| 40 |
virtual PRStatus Notify(); /* perhaps ready one thread */ |
| 41 |
virtual PRStatus Broadcast(); /* perhaps ready many threads */ |
| 42 |
|
| 43 |
virtual PRStatus SetTimeout(const RCInterval&); |
| 44 |
/* set object's current timeout value */ |
| 45 |
|
| 46 |
private: |
| 47 |
PRCondVar *cv; |
| 48 |
RCInterval timeout; |
| 49 |
|
| 50 |
RCCondition(); |
| 51 |
RCCondition(const RCCondition&); |
| 52 |
void operator=(const RCCondition&); |
| 53 |
|
| 54 |
public: |
| 55 |
RCInterval GetTimeout() const; |
| 56 |
}; /* RCCondition */ |
| 57 |
|
| 58 |
inline RCCondition::RCCondition(): RCBase() { } |
| 59 |
inline RCCondition::RCCondition(const RCCondition&): RCBase() { } |
| 60 |
inline void RCCondition::operator=(const RCCondition&) { } |
| 61 |
|
| 62 |
#endif /* defined(_RCCOND_H) */ |
| 63 |
|
| 64 |
/* RCCond.h */ |