| 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 #ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | 5 #ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | 
| 6 #define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | 6 #define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | 
| 7 | 7 | 
| 8 #include "pthread.h" | 8 #include "pthread.h" | 
| 9 #include "sdk_util/macros.h" | 9 #include "sdk_util/macros.h" | 
| 10 | 10 | 
| 11 namespace sdk_util { | 11 namespace sdk_util { | 
| 12 | 12 | 
| 13 /* | 13 /* | 
| 14  * SimpleLock | 14  * SimpleLock | 
| 15  * | 15  * | 
| 16  * A pthread mutex object, with automatic initialization and destruction. | 16  * A pthread mutex object, with automatic initialization and destruction. | 
| 17  * Should be used with AutoLock where possible. | 17  * Should be used with AutoLock where possible. | 
| 18  */ | 18  */ | 
| 19 class SimpleLock { | 19 class SimpleLock { | 
| 20  public: | 20  public: | 
| 21   SimpleLock() { | 21   SimpleLock() { | 
| 22     pthread_mutex_init(&lock_, NULL); | 22     pthread_mutex_init(&lock_, NULL); | 
| 23   } | 23   } | 
| 24 | 24 | 
| 25   ~SimpleLock() { | 25   ~SimpleLock() { | 
| 26     pthread_mutex_destroy(&lock_); | 26     pthread_mutex_destroy(&lock_); | 
| 27   } | 27   } | 
| 28 | 28 | 
|  | 29   void Lock() const   { pthread_mutex_lock(&lock_); } | 
|  | 30   void Unlock() const { pthread_mutex_unlock(&lock_); } | 
|  | 31 | 
| 29   pthread_mutex_t* mutex() const { return &lock_; } | 32   pthread_mutex_t* mutex() const { return &lock_; } | 
| 30 | 33 | 
| 31  private: | 34  private: | 
| 32   mutable pthread_mutex_t lock_; | 35   mutable pthread_mutex_t lock_; | 
| 33 | 36 | 
| 34   DISALLOW_COPY_AND_ASSIGN(SimpleLock); | 37   DISALLOW_COPY_AND_ASSIGN(SimpleLock); | 
| 35 }; | 38 }; | 
| 36 | 39 | 
| 37 }  // namespace sdk_util | 40 }  // namespace sdk_util | 
| 38 | 41 | 
| 39 #endif  // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | 42 #endif  // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ | 
| OLD | NEW | 
|---|