Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | |
michael@0 | 10 | #include "rccv.h" |
michael@0 | 11 | |
michael@0 | 12 | #include <prlog.h> |
michael@0 | 13 | #include <prerror.h> |
michael@0 | 14 | #include <prcvar.h> |
michael@0 | 15 | |
michael@0 | 16 | RCCondition::RCCondition(class RCLock *lock): RCBase() |
michael@0 | 17 | { |
michael@0 | 18 | cv = PR_NewCondVar(lock->lock); |
michael@0 | 19 | PR_ASSERT(NULL != cv); |
michael@0 | 20 | timeout = PR_INTERVAL_NO_TIMEOUT; |
michael@0 | 21 | } /* RCCondition::RCCondition */ |
michael@0 | 22 | |
michael@0 | 23 | RCCondition::~RCCondition() |
michael@0 | 24 | { |
michael@0 | 25 | if (NULL != cv) PR_DestroyCondVar(cv); |
michael@0 | 26 | } /* RCCondition::~RCCondition */ |
michael@0 | 27 | |
michael@0 | 28 | PRStatus RCCondition::Wait() |
michael@0 | 29 | { |
michael@0 | 30 | PRStatus rv; |
michael@0 | 31 | PR_ASSERT(NULL != cv); |
michael@0 | 32 | if (NULL == cv) |
michael@0 | 33 | { |
michael@0 | 34 | SetError(PR_INVALID_ARGUMENT_ERROR, 0); |
michael@0 | 35 | rv = PR_FAILURE; |
michael@0 | 36 | } |
michael@0 | 37 | else |
michael@0 | 38 | rv = PR_WaitCondVar(cv, timeout.interval); |
michael@0 | 39 | return rv; |
michael@0 | 40 | } /* RCCondition::Wait */ |
michael@0 | 41 | |
michael@0 | 42 | PRStatus RCCondition::Notify() |
michael@0 | 43 | { |
michael@0 | 44 | return PR_NotifyCondVar(cv); |
michael@0 | 45 | } /* RCCondition::Notify */ |
michael@0 | 46 | |
michael@0 | 47 | PRStatus RCCondition::Broadcast() |
michael@0 | 48 | { |
michael@0 | 49 | return PR_NotifyAllCondVar(cv); |
michael@0 | 50 | } /* RCCondition::Broadcast */ |
michael@0 | 51 | |
michael@0 | 52 | PRStatus RCCondition::SetTimeout(const RCInterval& tmo) |
michael@0 | 53 | { |
michael@0 | 54 | if (NULL == cv) |
michael@0 | 55 | { |
michael@0 | 56 | SetError(PR_INVALID_ARGUMENT_ERROR, 0); |
michael@0 | 57 | return PR_FAILURE; |
michael@0 | 58 | } |
michael@0 | 59 | timeout = tmo; |
michael@0 | 60 | return PR_SUCCESS; |
michael@0 | 61 | } /* RCCondition::SetTimeout */ |
michael@0 | 62 | |
michael@0 | 63 | RCInterval RCCondition::GetTimeout() const { return timeout; } |
michael@0 | 64 | |
michael@0 | 65 | /* rccv.cpp */ |