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: michael@0: #include "rccv.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: RCCondition::RCCondition(class RCLock *lock): RCBase() michael@0: { michael@0: cv = PR_NewCondVar(lock->lock); michael@0: PR_ASSERT(NULL != cv); michael@0: timeout = PR_INTERVAL_NO_TIMEOUT; michael@0: } /* RCCondition::RCCondition */ michael@0: michael@0: RCCondition::~RCCondition() michael@0: { michael@0: if (NULL != cv) PR_DestroyCondVar(cv); michael@0: } /* RCCondition::~RCCondition */ michael@0: michael@0: PRStatus RCCondition::Wait() michael@0: { michael@0: PRStatus rv; michael@0: PR_ASSERT(NULL != cv); michael@0: if (NULL == cv) michael@0: { michael@0: SetError(PR_INVALID_ARGUMENT_ERROR, 0); michael@0: rv = PR_FAILURE; michael@0: } michael@0: else michael@0: rv = PR_WaitCondVar(cv, timeout.interval); michael@0: return rv; michael@0: } /* RCCondition::Wait */ michael@0: michael@0: PRStatus RCCondition::Notify() michael@0: { michael@0: return PR_NotifyCondVar(cv); michael@0: } /* RCCondition::Notify */ michael@0: michael@0: PRStatus RCCondition::Broadcast() michael@0: { michael@0: return PR_NotifyAllCondVar(cv); michael@0: } /* RCCondition::Broadcast */ michael@0: michael@0: PRStatus RCCondition::SetTimeout(const RCInterval& tmo) michael@0: { michael@0: if (NULL == cv) michael@0: { michael@0: SetError(PR_INVALID_ARGUMENT_ERROR, 0); michael@0: return PR_FAILURE; michael@0: } michael@0: timeout = tmo; michael@0: return PR_SUCCESS; michael@0: } /* RCCondition::SetTimeout */ michael@0: michael@0: RCInterval RCCondition::GetTimeout() const { return timeout; } michael@0: michael@0: /* rccv.cpp */