Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 * found in the LICENSE file. | |
| 4 */ | |
| 5 | |
| 6 #ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | |
| 7 #define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | |
| 8 | |
| 9 #include "pthread.h" | |
| 10 #include "sdk_util/macros.h" | |
| 11 | |
| 12 class AutoLock; | |
|
binji
2013/07/12 00:51:23
not necessary
noelallen1
2013/07/12 23:18:47
Done.
| |
| 13 | |
| 14 /* | |
| 15 * SimpleLock | |
| 16 * | |
| 17 * A pthread mutex object, with automatic initialization and destruction. | |
| 18 * Should be used with AutoLock where possible. | |
| 19 */ | |
| 20 class SimpleLock { | |
|
binji
2013/07/12 00:51:23
Why SimpleLock? Maybe just Lock?
noelallen1
2013/07/12 23:18:47
Less likely to collide with a name.
binji
2013/07/13 00:16:47
OK, can we change it to Lock after I add namespace
| |
| 21 public: | |
| 22 SimpleLock() { | |
| 23 pthread_mutex_init(&lock_, NULL); | |
| 24 } | |
| 25 | |
| 26 ~SimpleLock() { | |
| 27 pthread_mutex_destroy(&lock_); | |
| 28 } | |
| 29 | |
| 30 operator pthread_mutex_t*() const { return &lock_; } | |
|
binji
2013/07/12 00:51:23
We should just have a function for this, rather th
noelallen1
2013/07/12 23:18:47
Done.
| |
| 31 | |
| 32 private: | |
| 33 mutable pthread_mutex_t lock_; | |
| 34 friend class AutoLock; | |
| 35 | |
| 36 DISALLOW_COPY_AND_ASSIGN(SimpleLock); | |
| 37 }; | |
| 38 | |
| 39 #endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | |
| 40 | |
| OLD | NEW |