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

Unified Diff: native_client_sdk/src/libraries/sdk_util/simple_lock.h

Issue 18644009: [NaCl SDK] Upate atomic ops in nacl_io (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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
Index: native_client_sdk/src/libraries/sdk_util/simple_lock.h
diff --git a/native_client_sdk/src/libraries/sdk_util/simple_lock.h b/native_client_sdk/src/libraries/sdk_util/simple_lock.h
new file mode 100644
index 0000000000000000000000000000000000000000..9014ff9ed822f69f5499096fb80e892b84d054fa
--- /dev/null
+++ b/native_client_sdk/src/libraries/sdk_util/simple_lock.h
@@ -0,0 +1,40 @@
+/* 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"
+
+class AutoLock;
binji 2013/07/12 00:51:23 not necessary
noelallen1 2013/07/12 23:18:47 Done.
+
+/*
+ * SimpleLock
+ *
+ * A pthread mutex object, with automatic initialization and destruction.
+ * Should be used with AutoLock where possible.
+ */
+class SimpleLock {
binji 2013/07/12 00:51:23 Why SimpleLock? Maybe just Lock?
noelallen1 2013/07/12 23:18:47 Less likely to collide with a name.
binji 2013/07/13 00:16:47 OK, can we change it to Lock after I add namespace
+ public:
+ SimpleLock() {
+ pthread_mutex_init(&lock_, NULL);
+ }
+
+ ~SimpleLock() {
+ pthread_mutex_destroy(&lock_);
+ }
+
+ operator pthread_mutex_t*() const { return &lock_; }
binji 2013/07/12 00:51:23 We should just have a function for this, rather th
noelallen1 2013/07/12 23:18:47 Done.
+
+ private:
+ mutable pthread_mutex_t lock_;
+ friend class AutoLock;
+
+ DISALLOW_COPY_AND_ASSIGN(SimpleLock);
+};
+
+#endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
+

Powered by Google App Engine
This is Rietveld 408576698