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

Unified Diff: base/synchronization/rw_lock_posix.cc

Issue 1988563002: Create a reader-writer lock implementaiton in base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simple-stupid implementaiton for NaCl Created 4 years, 7 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: base/synchronization/rw_lock_posix.cc
diff --git a/base/synchronization/rw_lock_posix.cc b/base/synchronization/rw_lock_posix.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7003978aacc1aad99a2e6a9ea641f7d43346646b
--- /dev/null
+++ b/base/synchronization/rw_lock_posix.cc
@@ -0,0 +1,41 @@
+// Copyright 2016 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.
+
+#include "base/synchronization/rw_lock.h"
+
+#include "base/logging.h"
+
+namespace base {
+
+RWLock::RWLock() {
danakj 2016/05/19 23:01:37 can you use PTHREAD_RWLOCK_INITIALIZER similar to
Anand Mistry (off Chromium) 2016/05/20 04:06:38 Done. Oddly enough, the man on Linux doesn't say
+ int rv = pthread_rwlock_init(&native_handle_, nullptr);
danakj 2016/05/19 23:01:37 nit: name "result" instead of rv. ditto elsewhere
Anand Mistry (off Chromium) 2016/05/20 04:06:38 Done.
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+}
+
+RWLock::~RWLock() {
+ int rv = pthread_rwlock_destroy(&native_handle_);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+}
+
+void RWLock::ReadAcquire() {
+ int rv = pthread_rwlock_rdlock(&native_handle_);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+}
+
+void RWLock::ReadRelease() {
+ int rv = pthread_rwlock_unlock(&native_handle_);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+}
+
+void RWLock::WriteAcquire() {
+ int rv = pthread_rwlock_wrlock(&native_handle_);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+}
+
+void RWLock::WriteRelease() {
+ int rv = pthread_rwlock_unlock(&native_handle_);
+ DCHECK_EQ(rv, 0) << ". " << strerror(rv);
+}
+
+} // namespace base

Powered by Google App Engine
This is Rietveld 408576698