1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/src/cplus/rccv.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,65 @@ 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 + 1.13 +#include "rccv.h" 1.14 + 1.15 +#include <prlog.h> 1.16 +#include <prerror.h> 1.17 +#include <prcvar.h> 1.18 + 1.19 +RCCondition::RCCondition(class RCLock *lock): RCBase() 1.20 +{ 1.21 + cv = PR_NewCondVar(lock->lock); 1.22 + PR_ASSERT(NULL != cv); 1.23 + timeout = PR_INTERVAL_NO_TIMEOUT; 1.24 +} /* RCCondition::RCCondition */ 1.25 + 1.26 +RCCondition::~RCCondition() 1.27 +{ 1.28 + if (NULL != cv) PR_DestroyCondVar(cv); 1.29 +} /* RCCondition::~RCCondition */ 1.30 + 1.31 +PRStatus RCCondition::Wait() 1.32 +{ 1.33 + PRStatus rv; 1.34 + PR_ASSERT(NULL != cv); 1.35 + if (NULL == cv) 1.36 + { 1.37 + SetError(PR_INVALID_ARGUMENT_ERROR, 0); 1.38 + rv = PR_FAILURE; 1.39 + } 1.40 + else 1.41 + rv = PR_WaitCondVar(cv, timeout.interval); 1.42 + return rv; 1.43 +} /* RCCondition::Wait */ 1.44 + 1.45 +PRStatus RCCondition::Notify() 1.46 +{ 1.47 + return PR_NotifyCondVar(cv); 1.48 +} /* RCCondition::Notify */ 1.49 + 1.50 +PRStatus RCCondition::Broadcast() 1.51 +{ 1.52 + return PR_NotifyAllCondVar(cv); 1.53 +} /* RCCondition::Broadcast */ 1.54 + 1.55 +PRStatus RCCondition::SetTimeout(const RCInterval& tmo) 1.56 +{ 1.57 + if (NULL == cv) 1.58 + { 1.59 + SetError(PR_INVALID_ARGUMENT_ERROR, 0); 1.60 + return PR_FAILURE; 1.61 + } 1.62 + timeout = tmo; 1.63 + return PR_SUCCESS; 1.64 +} /* RCCondition::SetTimeout */ 1.65 + 1.66 +RCInterval RCCondition::GetTimeout() const { return timeout; } 1.67 + 1.68 +/* rccv.cpp */