OLD | NEW |
| (Empty) |
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 | |
3 * found in the LICENSE file. | |
4 */ | |
5 | |
6 #ifndef LIBRARIES_UTILS_AUTO_LOCK_H_ | |
7 #define LIBRARIES_UTILS_AUTO_LOCK_H_ | |
8 | |
9 #include <pthread.h> | |
10 | |
11 class AutoLock { | |
12 public: | |
13 explicit AutoLock(pthread_mutex_t* lock) { | |
14 lock_ = lock; | |
15 pthread_mutex_lock(lock_); | |
16 } | |
17 ~AutoLock() { | |
18 if (lock_) pthread_mutex_unlock(lock_); | |
19 } | |
20 | |
21 void Unlock() { | |
22 if (lock_) pthread_mutex_unlock(lock_); | |
23 lock_ = NULL; | |
24 } | |
25 | |
26 private: | |
27 pthread_mutex_t* lock_; | |
28 }; | |
29 | |
30 #endif // LIBRARIES_UTILS_AUTO_LOCK_H_ | |
OLD | NEW |