OLD | NEW |
1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 #ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | 6 #ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ |
7 #define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | 7 #define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ |
8 | 8 |
9 #include "pthread.h" | 9 #include "pthread.h" |
10 #include "sdk_util/macros.h" | 10 #include "sdk_util/macros.h" |
11 | 11 |
| 12 namespace sdk_util { |
| 13 |
12 /* | 14 /* |
13 * SimpleLock | 15 * SimpleLock |
14 * | 16 * |
15 * A pthread mutex object, with automatic initialization and destruction. | 17 * A pthread mutex object, with automatic initialization and destruction. |
16 * Should be used with AutoLock where possible. | 18 * Should be used with AutoLock where possible. |
17 */ | 19 */ |
18 class SimpleLock { | 20 class SimpleLock { |
19 public: | 21 public: |
20 SimpleLock() { | 22 SimpleLock() { |
21 pthread_mutex_init(&lock_, NULL); | 23 pthread_mutex_init(&lock_, NULL); |
22 } | 24 } |
23 | 25 |
24 ~SimpleLock() { | 26 ~SimpleLock() { |
25 pthread_mutex_destroy(&lock_); | 27 pthread_mutex_destroy(&lock_); |
26 } | 28 } |
27 | 29 |
28 pthread_mutex_t* mutex() const { return &lock_; } | 30 pthread_mutex_t* mutex() const { return &lock_; } |
29 | 31 |
30 private: | 32 private: |
31 mutable pthread_mutex_t lock_; | 33 mutable pthread_mutex_t lock_; |
32 | 34 |
33 DISALLOW_COPY_AND_ASSIGN(SimpleLock); | 35 DISALLOW_COPY_AND_ASSIGN(SimpleLock); |
34 }; | 36 }; |
35 | 37 |
| 38 } // namespace sdk_util |
| 39 |
36 #endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | 40 #endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ |
37 | 41 |
OLD | NEW |