|
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 ** C++ access to NSPR locks (PRLock) |
|
8 */ |
|
9 |
|
10 #if defined(_RCLOCK_H) |
|
11 #else |
|
12 #define _RCLOCK_H |
|
13 |
|
14 #include "rcbase.h" |
|
15 |
|
16 #include <prlock.h> |
|
17 |
|
18 class PR_IMPLEMENT(RCLock): public RCBase |
|
19 { |
|
20 public: |
|
21 RCLock(); |
|
22 virtual ~RCLock(); |
|
23 |
|
24 void Acquire(); /* non-reentrant */ |
|
25 void Release(); /* should be by owning thread */ |
|
26 |
|
27 friend class RCCondition; |
|
28 |
|
29 private: |
|
30 RCLock(const RCLock&); /* can't do that */ |
|
31 void operator=(const RCLock&); /* nor that */ |
|
32 |
|
33 PRLock *lock; |
|
34 }; /* RCLock */ |
|
35 |
|
36 /* |
|
37 ** Class: RCEnter |
|
38 ** |
|
39 ** In scope locks. You can only allocate them on the stack. The language |
|
40 ** will insure that they get released (by calling the destructor) when |
|
41 ** the thread leaves scope, even if via an exception. |
|
42 */ |
|
43 class PR_IMPLEMENT(RCEnter) |
|
44 { |
|
45 public: |
|
46 ~RCEnter(); /* releases the lock */ |
|
47 RCEnter(RCLock*); /* acquires the lock */ |
|
48 |
|
49 private: |
|
50 RCLock *lock; |
|
51 |
|
52 RCEnter(); |
|
53 RCEnter(const RCEnter&); |
|
54 void operator=(const RCEnter&); |
|
55 |
|
56 void *operator new(PRSize) { return NULL; } |
|
57 void operator delete(void*) { } |
|
58 }; /* RCEnter */ |
|
59 |
|
60 |
|
61 inline RCEnter::RCEnter(RCLock* ml) { lock = ml; lock->Acquire(); } |
|
62 inline RCEnter::~RCEnter() { lock->Release(); lock = NULL; } |
|
63 |
|
64 #endif /* defined(_RCLOCK_H) */ |
|
65 |
|
66 /* RCLock.h */ |