Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(459)

Side by Side Diff: native_client_sdk/src/libraries/sdk_util/auto_lock.h

Issue 23005005: [NaCl SDK] nacl_io: Add initial implementations of kill and signal (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 #ifndef LIBRARIES_SDK_UTIL_AUTO_LOCK_H_ 5 #ifndef LIBRARIES_SDK_UTIL_AUTO_LOCK_H_
6 #define LIBRARIES_SDK_UTIL_AUTO_LOCK_H_ 6 #define LIBRARIES_SDK_UTIL_AUTO_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 #include "sdk_util/simple_lock.h" 10 #include "sdk_util/simple_lock.h"
11 11
12 namespace sdk_util { 12 namespace sdk_util {
13 13
14 // This macro is provided to allow us to quickly instrument locking for 14 // This macro is provided to allow us to quickly instrument locking for
15 // debugging purposes. 15 // debugging purposes.
16 #define AUTO_LOCK(lock) \ 16 #define AUTO_LOCK(lock) \
17 ::sdk_util::AutoLock Lock##__LINE__(lock); 17 ::sdk_util::AutoLock Lock##__LINE__(lock);
18 18
19 class AutoLock { 19 class AutoLock {
20 public: 20 public:
21 AutoLock(const SimpleLock& lock) { 21 AutoLock(const SimpleLock& lock) {
22 lock_ = lock.mutex(); 22 lock_ = lock.mutex();
23 pthread_mutex_lock(lock_); 23 pthread_mutex_lock(lock_);
24 } 24 }
25 25
26 ~AutoLock() { 26 ~AutoLock() {
27 if (lock_) pthread_mutex_unlock(lock_); 27 Unlock();
28 } 28 }
29 29
30 void Unlock() { 30 void Unlock() {
31 if (lock_) pthread_mutex_unlock(lock_); 31 if (lock_) pthread_mutex_unlock(lock_);
32 lock_ = NULL; 32 lock_ = NULL;
33 } 33 }
34 34
35 private: 35 private:
36 pthread_mutex_t* lock_; 36 pthread_mutex_t* lock_;
37 37
38 DISALLOW_COPY_AND_ASSIGN(AutoLock); 38 DISALLOW_COPY_AND_ASSIGN(AutoLock);
39 }; 39 };
40 40
41 } // namespace sdk_util 41 } // namespace sdk_util
42 42
43 #endif // LIBRARIES_SDK_UTIL_AUTO_LOCK_H_ 43 #endif // LIBRARIES_SDK_UTIL_AUTO_LOCK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698