|
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/. */ |
|
5 |
|
6 /* |
|
7 ** RCCondition - C++ wrapper around NSPR's PRCondVar |
|
8 */ |
|
9 |
|
10 #include "rccv.h" |
|
11 |
|
12 #include <prlog.h> |
|
13 #include <prerror.h> |
|
14 #include <prcvar.h> |
|
15 |
|
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 */ |
|
22 |
|
23 RCCondition::~RCCondition() |
|
24 { |
|
25 if (NULL != cv) PR_DestroyCondVar(cv); |
|
26 } /* RCCondition::~RCCondition */ |
|
27 |
|
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 */ |
|
41 |
|
42 PRStatus RCCondition::Notify() |
|
43 { |
|
44 return PR_NotifyCondVar(cv); |
|
45 } /* RCCondition::Notify */ |
|
46 |
|
47 PRStatus RCCondition::Broadcast() |
|
48 { |
|
49 return PR_NotifyAllCondVar(cv); |
|
50 } /* RCCondition::Broadcast */ |
|
51 |
|
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 */ |
|
62 |
|
63 RCInterval RCCondition::GetTimeout() const { return timeout; } |
|
64 |
|
65 /* rccv.cpp */ |