Wed, 31 Dec 2014 06:55:46 +0100
Added tag TORBROWSER_REPLICA for changeset 6474c204b198
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 /*
7 ** RCCondition - C++ wrapper around NSPR's PRCondVar
8 */
10 #include "rccv.h"
12 #include <prlog.h>
13 #include <prerror.h>
14 #include <prcvar.h>
16 RCCondition::RCCondition(class RCLock *lock): RCBase()
17 {
18 cv = PR_NewCondVar(lock->lock);
19 PR_ASSERT(NULL != cv);
20 timeout = PR_INTERVAL_NO_TIMEOUT;
21 } /* RCCondition::RCCondition */
23 RCCondition::~RCCondition()
24 {
25 if (NULL != cv) PR_DestroyCondVar(cv);
26 } /* RCCondition::~RCCondition */
28 PRStatus RCCondition::Wait()
29 {
30 PRStatus rv;
31 PR_ASSERT(NULL != cv);
32 if (NULL == cv)
33 {
34 SetError(PR_INVALID_ARGUMENT_ERROR, 0);
35 rv = PR_FAILURE;
36 }
37 else
38 rv = PR_WaitCondVar(cv, timeout.interval);
39 return rv;
40 } /* RCCondition::Wait */
42 PRStatus RCCondition::Notify()
43 {
44 return PR_NotifyCondVar(cv);
45 } /* RCCondition::Notify */
47 PRStatus RCCondition::Broadcast()
48 {
49 return PR_NotifyAllCondVar(cv);
50 } /* RCCondition::Broadcast */
52 PRStatus RCCondition::SetTimeout(const RCInterval& tmo)
53 {
54 if (NULL == cv)
55 {
56 SetError(PR_INVALID_ARGUMENT_ERROR, 0);
57 return PR_FAILURE;
58 }
59 timeout = tmo;
60 return PR_SUCCESS;
61 } /* RCCondition::SetTimeout */
63 RCInterval RCCondition::GetTimeout() const { return timeout; }
65 /* rccv.cpp */