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

Unified 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, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/untrusted/init/init.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/untrusted/init/auto_lock.h
diff --git a/src/untrusted/init/auto_lock.h b/src/untrusted/init/auto_lock.h
new file mode 100644
index 0000000000000000000000000000000000000000..4d38395804a699e9eb88d3ce0a8ce4aed67cfcb6
--- /dev/null
+++ b/src/untrusted/init/auto_lock.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NATIVE_CLIENT_SRC_UNTRUSTED_INIT_AUTO_LOCK_H_
+#define NATIVE_CLIENT_SRC_UNTRUSTED_INIT_AUTO_LOCK_H_
+
+#include <pthread.h>
+#include "sdk_util/macros.h"
+#include "sdk_util/simple_lock.h"
+
+namespace nacl {
+
+// This macro is provided to allow us to quickly instrument locking for
+// debugging purposes.
+#define AUTO_LOCK(lock) \
+ ::nacl::AutoLock Lock##__LINE__(lock);
+
+class AutoLock {
+ public:
+ AutoLock(const SimpleLock& lock) {
+ lock_ = lock.mutex();
+ pthread_mutex_lock(lock_);
+ }
+
+ ~AutoLock() {
+ Unlock();
+ }
+
+ void Unlock() {
+ if (lock_) pthread_mutex_unlock(lock_);
+ lock_ = NULL;
+ }
+
+ private:
+ pthread_mutex_t* lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(AutoLock);
+};
+
+} // namespace nacl
+
+#endif
« 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