| OLD | NEW |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 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_AUTO_LOCK_H_ | 6 #ifndef LIBRARIES_SDK_UTIL_AUTO_LOCK_H_ |
| 7 #define LIBRARIES_SDK_UTIL_AUTO_LOCK_H_ | 7 #define LIBRARIES_SDK_UTIL_AUTO_LOCK_H_ |
| 8 | 8 |
| 9 #include <pthread.h> | 9 #include <pthread.h> |
| 10 #include "sdk_util/simple_lock.h" |
| 10 | 11 |
| 11 class AutoLock { | 12 class AutoLock { |
| 12 public: | 13 public: |
| 14 explicit AutoLock(SimpleLock* lock) { |
| 15 lock_ = &lock->lock_; |
| 16 pthread_mutex_lock(lock_); |
| 17 } |
| 13 explicit AutoLock(pthread_mutex_t* lock) { | 18 explicit AutoLock(pthread_mutex_t* lock) { |
| 14 lock_ = lock; | 19 lock_ = lock; |
| 15 pthread_mutex_lock(lock_); | 20 pthread_mutex_lock(lock_); |
| 16 } | 21 } |
| 17 ~AutoLock() { | 22 ~AutoLock() { |
| 18 if (lock_) pthread_mutex_unlock(lock_); | 23 if (lock_) pthread_mutex_unlock(lock_); |
| 19 } | 24 } |
| 20 | 25 |
| 21 void Unlock() { | 26 void Unlock() { |
| 22 if (lock_) pthread_mutex_unlock(lock_); | 27 if (lock_) pthread_mutex_unlock(lock_); |
| 23 lock_ = NULL; | 28 lock_ = NULL; |
| 24 } | 29 } |
| 25 | 30 |
| 26 private: | 31 private: |
| 27 pthread_mutex_t* lock_; | 32 pthread_mutex_t* lock_; |
| 28 }; | 33 }; |
| 29 | 34 |
| 30 #endif // LIBRARIES_SDK_UTIL_AUTO_LOCK_H_ | 35 #endif // LIBRARIES_SDK_UTIL_AUTO_LOCK_H_ |
| 31 | 36 |
| OLD | NEW |