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

Unified Diff: rlz/lib/recursive_lock.cc

Issue 11361057: [cros] Add RecursiveLock for CrOS implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 8 years, 1 month 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 | « rlz/lib/recursive_lock.h ('k') | rlz/lib/recursive_lock_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: rlz/lib/recursive_lock.cc
diff --git a/rlz/lib/recursive_lock.cc b/rlz/lib/recursive_lock.cc
new file mode 100644
index 0000000000000000000000000000000000000000..686cf0ebba26da2688f4fe204742c75009b57971
--- /dev/null
+++ b/rlz/lib/recursive_lock.cc
@@ -0,0 +1,40 @@
+// 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.
+
+#include "rlz/lib/recursive_lock.h"
+
+#include "base/logging.h"
+
+namespace rlz_lib {
+
+RecursiveLock::RecursiveLock()
+ : owner_(),
+ recursion_() {
+}
+
+RecursiveLock::~RecursiveLock() {
+}
+
+void RecursiveLock::Acquire() {
+ base::subtle::Atomic32 me = base::PlatformThread::CurrentId();
+ if (me != base::subtle::NoBarrier_Load(&owner_)) {
+ lock_.Acquire();
+ DCHECK(!recursion_);
+ DCHECK(!owner_);
+ base::subtle::NoBarrier_Store(&owner_, me);
+ }
+ ++recursion_;
+}
+
+void RecursiveLock::Release() {
+ DCHECK_EQ(base::subtle::NoBarrier_Load(&owner_),
+ base::PlatformThread::CurrentId());
+ DCHECK_GT(recursion_, 0);
+ if (!--recursion_) {
+ base::subtle::NoBarrier_Store(&owner_, 0);
+ lock_.Release();
+ }
+}
+
+} // namespace rlz_lib
« no previous file with comments | « rlz/lib/recursive_lock.h ('k') | rlz/lib/recursive_lock_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698