| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "rlz/lib/recursive_lock.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace rlz_lib { | |
| 10 | |
| 11 RecursiveLock::RecursiveLock() | |
| 12 : owner_(), | |
| 13 recursion_() { | |
| 14 } | |
| 15 | |
| 16 RecursiveLock::~RecursiveLock() { | |
| 17 } | |
| 18 | |
| 19 void RecursiveLock::Acquire() { | |
| 20 base::subtle::Atomic32 me = base::PlatformThread::CurrentId(); | |
| 21 if (me != base::subtle::NoBarrier_Load(&owner_)) { | |
| 22 lock_.Acquire(); | |
| 23 DCHECK(!recursion_); | |
| 24 DCHECK(!owner_); | |
| 25 base::subtle::NoBarrier_Store(&owner_, me); | |
| 26 } | |
| 27 ++recursion_; | |
| 28 } | |
| 29 | |
| 30 void RecursiveLock::Release() { | |
| 31 DCHECK_EQ(base::subtle::NoBarrier_Load(&owner_), | |
| 32 base::PlatformThread::CurrentId()); | |
| 33 DCHECK_GT(recursion_, 0); | |
| 34 if (!--recursion_) { | |
| 35 base::subtle::NoBarrier_Store(&owner_, 0); | |
| 36 lock_.Release(); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 } // namespace rlz_lib | |
| OLD | NEW |