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