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

Side by Side Diff: base/synchronization/read_write_lock_nacl.cc

Issue 1988563002: Create a reader-writer lock implementaiton in base. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move to base::subtle and add a warning 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 unified diff | Download patch
« no previous file with comments | « base/synchronization/read_write_lock.h ('k') | base/synchronization/read_write_lock_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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 "base/synchronization/read_write_lock.h"
6
7 #include "base/logging.h"
8
9 namespace base {
10 namespace subtle {
11
12 ReadWriteLock::ReadWriteLock() {}
13
14 ReadWriteLock::~ReadWriteLock() {
15 DCHECK_EQ(0u, readers_);
16 int result = pthread_mutex_destroy(&writer_lock_);
17 DCHECK_EQ(result, 0) << ". " << strerror(result);
18 }
19
20 void ReadWriteLock::ReadAcquire() {
21 AutoLock hold(native_handle_);
22 readers_++;
23 if (readers_ == 1) {
24 int result = pthread_mutex_lock(&writer_lock_);
25 DCHECK_EQ(result, 0) << ". " << strerror(result);
26 }
27 }
28
29 void ReadWriteLock::ReadRelease() {
30 AutoLock hold(native_handle_);
31 readers_--;
32 if (readers_ == 0) {
33 int result = pthread_mutex_unlock(&writer_lock_);
34 DCHECK_EQ(result, 0) << ". " << strerror(result);
35 }
36 }
37
38 void ReadWriteLock::WriteAcquire() {
39 int result = pthread_mutex_lock(&writer_lock_);
40 DCHECK_EQ(result, 0) << ". " << strerror(result);
41 }
42
43 void ReadWriteLock::WriteRelease() {
44 int result = pthread_mutex_unlock(&writer_lock_);
45 DCHECK_EQ(result, 0) << ". " << strerror(result);
46 }
47
48 } // namespace subtle
49 } // namespace base
OLDNEW
« no previous file with comments | « base/synchronization/read_write_lock.h ('k') | base/synchronization/read_write_lock_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698