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

Side by Side Diff: src/untrusted/init/auto_lock.h

Issue 25147002: nacl_init Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 2 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
« no previous file with comments | « no previous file | src/untrusted/init/init.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 #ifndef NATIVE_CLIENT_SRC_UNTRUSTED_INIT_AUTO_LOCK_H_
6 #define NATIVE_CLIENT_SRC_UNTRUSTED_INIT_AUTO_LOCK_H_
7
8 #include <pthread.h>
9 #include "sdk_util/macros.h"
10 #include "sdk_util/simple_lock.h"
11
12 namespace nacl {
13
14 // This macro is provided to allow us to quickly instrument locking for
15 // debugging purposes.
16 #define AUTO_LOCK(lock) \
17 ::nacl::AutoLock Lock##__LINE__(lock);
18
19 class AutoLock {
20 public:
21 AutoLock(const SimpleLock& lock) {
22 lock_ = lock.mutex();
23 pthread_mutex_lock(lock_);
24 }
25
26 ~AutoLock() {
27 Unlock();
28 }
29
30 void Unlock() {
31 if (lock_) pthread_mutex_unlock(lock_);
32 lock_ = NULL;
33 }
34
35 private:
36 pthread_mutex_t* lock_;
37
38 DISALLOW_COPY_AND_ASSIGN(AutoLock);
39 };
40
41 } // namespace nacl
42
43 #endif
OLDNEW
« no previous file with comments | « no previous file | src/untrusted/init/init.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698