|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef RWLOCK_AUTO_ENTER_H |
|
6 #define RWLOCK_AUTO_ENTER_H |
|
7 |
|
8 #include "prrwlock.h" |
|
9 #include "mozilla/Assertions.h" |
|
10 |
|
11 class RwLockAutoEnterRead |
|
12 { |
|
13 public: |
|
14 RwLockAutoEnterRead(PRRWLock* aRwLock) |
|
15 : mRwLock(aRwLock) |
|
16 { |
|
17 MOZ_ASSERT(mRwLock); |
|
18 PR_RWLock_Rlock(mRwLock); |
|
19 } |
|
20 |
|
21 ~RwLockAutoEnterRead() |
|
22 { |
|
23 PR_RWLock_Unlock(mRwLock); |
|
24 } |
|
25 |
|
26 protected: |
|
27 PRRWLock* mRwLock; |
|
28 }; |
|
29 |
|
30 class RwLockAutoEnterWrite |
|
31 { |
|
32 public: |
|
33 RwLockAutoEnterWrite(PRRWLock* aRwLock) |
|
34 : mRwLock(aRwLock) |
|
35 { |
|
36 MOZ_ASSERT(mRwLock); |
|
37 PR_RWLock_Wlock(mRwLock); |
|
38 } |
|
39 |
|
40 ~RwLockAutoEnterWrite() |
|
41 { |
|
42 PR_RWLock_Unlock(mRwLock); |
|
43 } |
|
44 |
|
45 protected: |
|
46 PRRWLock* mRwLock; |
|
47 }; |
|
48 |
|
49 #endif // RWLOCK_AUTO_ENTER_H |