1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/cplus/rccv.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 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 +/* 1.10 +** RCCondition - C++ wrapper around NSPR's PRCondVar 1.11 +** 1.12 +** Conditions have a notion of timeouts. A thread that waits on a condition 1.13 +** will resume execution when the condition is notified OR when a specified 1.14 +** interval of time has expired. 1.15 +** 1.16 +** Most applications don't adjust the timeouts on conditions. The literature 1.17 +** would argue that all threads waiting on a single condition must have the 1.18 +** same semantics. But if an application wishes to modify the timeout with 1.19 +** (perhaps) each wait call, that modification should be done consistantly 1.20 +** and under protection of the condition's associated lock. 1.21 +** 1.22 +** The default timeout is infinity. 1.23 +*/ 1.24 + 1.25 +#if defined(_RCCOND_H) 1.26 +#else 1.27 +#define _RCCOND_H 1.28 + 1.29 +#include "rclock.h" 1.30 +#include "rcbase.h" 1.31 +#include "rcinrval.h" 1.32 + 1.33 +struct PRCondVar; 1.34 + 1.35 +class PR_IMPLEMENT(RCCondition): public RCBase 1.36 +{ 1.37 +public: 1.38 + RCCondition(RCLock*); /* associates CV with a lock and infinite tmo */ 1.39 + virtual ~RCCondition(); 1.40 + 1.41 + virtual PRStatus Wait(); /* applies object's current timeout */ 1.42 + 1.43 + virtual PRStatus Notify(); /* perhaps ready one thread */ 1.44 + virtual PRStatus Broadcast(); /* perhaps ready many threads */ 1.45 + 1.46 + virtual PRStatus SetTimeout(const RCInterval&); 1.47 + /* set object's current timeout value */ 1.48 + 1.49 +private: 1.50 + PRCondVar *cv; 1.51 + RCInterval timeout; 1.52 + 1.53 + RCCondition(); 1.54 + RCCondition(const RCCondition&); 1.55 + void operator=(const RCCondition&); 1.56 + 1.57 +public: 1.58 + RCInterval GetTimeout() const; 1.59 +}; /* RCCondition */ 1.60 + 1.61 +inline RCCondition::RCCondition(): RCBase() { } 1.62 +inline RCCondition::RCCondition(const RCCondition&): RCBase() { } 1.63 +inline void RCCondition::operator=(const RCCondition&) { } 1.64 + 1.65 +#endif /* defined(_RCCOND_H) */ 1.66 + 1.67 +/* RCCond.h */