michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** RCCondition - C++ wrapper around NSPR's PRCondVar michael@0: ** michael@0: ** Conditions have a notion of timeouts. A thread that waits on a condition michael@0: ** will resume execution when the condition is notified OR when a specified michael@0: ** interval of time has expired. michael@0: ** michael@0: ** Most applications don't adjust the timeouts on conditions. The literature michael@0: ** would argue that all threads waiting on a single condition must have the michael@0: ** same semantics. But if an application wishes to modify the timeout with michael@0: ** (perhaps) each wait call, that modification should be done consistantly michael@0: ** and under protection of the condition's associated lock. michael@0: ** michael@0: ** The default timeout is infinity. michael@0: */ michael@0: michael@0: #if defined(_RCCOND_H) michael@0: #else michael@0: #define _RCCOND_H michael@0: michael@0: #include "rclock.h" michael@0: #include "rcbase.h" michael@0: #include "rcinrval.h" michael@0: michael@0: struct PRCondVar; michael@0: michael@0: class PR_IMPLEMENT(RCCondition): public RCBase michael@0: { michael@0: public: michael@0: RCCondition(RCLock*); /* associates CV with a lock and infinite tmo */ michael@0: virtual ~RCCondition(); michael@0: michael@0: virtual PRStatus Wait(); /* applies object's current timeout */ michael@0: michael@0: virtual PRStatus Notify(); /* perhaps ready one thread */ michael@0: virtual PRStatus Broadcast(); /* perhaps ready many threads */ michael@0: michael@0: virtual PRStatus SetTimeout(const RCInterval&); michael@0: /* set object's current timeout value */ michael@0: michael@0: private: michael@0: PRCondVar *cv; michael@0: RCInterval timeout; michael@0: michael@0: RCCondition(); michael@0: RCCondition(const RCCondition&); michael@0: void operator=(const RCCondition&); michael@0: michael@0: public: michael@0: RCInterval GetTimeout() const; michael@0: }; /* RCCondition */ michael@0: michael@0: inline RCCondition::RCCondition(): RCBase() { } michael@0: inline RCCondition::RCCondition(const RCCondition&): RCBase() { } michael@0: inline void RCCondition::operator=(const RCCondition&) { } michael@0: michael@0: #endif /* defined(_RCCOND_H) */ michael@0: michael@0: /* RCCond.h */