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

Unified Diff: src/untrusted/init/simple_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 | « src/untrusted/init/scoped_non_ptr.h ('k') | src/untrusted/init/simple_service.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/untrusted/init/simple_lock.h
diff --git a/src/untrusted/init/simple_lock.h b/src/untrusted/init/simple_lock.h
new file mode 100644
index 0000000000000000000000000000000000000000..1f3818511dd806c56673ad067dd867a35b226dfd
--- /dev/null
+++ b/src/untrusted/init/simple_lock.h
@@ -0,0 +1,42 @@
+// Copyright (c) 2013 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 LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
+#define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
+
+#include "pthread.h"
+#include "sdk_util/macros.h"
+
+namespace sdk_util {
+
+/*
+ * SimpleLock
+ *
+ * A pthread mutex object, with automatic initialization and destruction.
+ * Should be used with AutoLock where possible.
+ */
+class SimpleLock {
+ public:
+ SimpleLock() {
+ pthread_mutex_init(&lock_, NULL);
+ }
+
+ ~SimpleLock() {
+ pthread_mutex_destroy(&lock_);
+ }
+
+ void Lock() const { pthread_mutex_lock(&lock_); }
+ void Unlock() const { pthread_mutex_unlock(&lock_); }
+
+ pthread_mutex_t* mutex() const { return &lock_; }
+
+ private:
+ mutable pthread_mutex_t lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(SimpleLock);
+};
+
+} // namespace sdk_util
+
+#endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
« no previous file with comments | « src/untrusted/init/scoped_non_ptr.h ('k') | src/untrusted/init/simple_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698