|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef LulRWLock_h |
|
8 #define LulRWLock_h |
|
9 |
|
10 #include "LulPlatformMacros.h" |
|
11 #include <pthread.h> |
|
12 |
|
13 // This class provides a simple wrapper around reader-writer locks. |
|
14 // This is necessary because Android 2.2's libpthread does not |
|
15 // provide such functionality, so there has to be a way to provide |
|
16 // an alternative with an equivalent interface. |
|
17 |
|
18 namespace lul { |
|
19 |
|
20 class LulRWLock { |
|
21 |
|
22 public: |
|
23 LulRWLock(); |
|
24 ~LulRWLock(); |
|
25 void WrLock(); |
|
26 void RdLock(); |
|
27 void Unlock(); |
|
28 |
|
29 private: |
|
30 #if defined(LUL_OS_android) |
|
31 pthread_mutex_t mLock; |
|
32 #elif defined(LUL_OS_linux) |
|
33 pthread_rwlock_t mLock; |
|
34 #else |
|
35 # error "Unsupported OS" |
|
36 #endif |
|
37 |
|
38 }; |
|
39 |
|
40 } // namespace lul |
|
41 |
|
42 #endif // LulRWLock_h |