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

Side by Side Diff: base/synchronization/read_write_lock.h

Issue 2692273008: Hacky slashy (Closed)
Patch Set: wip Created 3 years, 10 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_SYNCHRONIZATION_READ_WRITE_LOCK_H_ 5 #ifndef BASE_SYNCHRONIZATION_READ_WRITE_LOCK_H_
6 #define BASE_SYNCHRONIZATION_READ_WRITE_LOCK_H_ 6 #define BASE_SYNCHRONIZATION_READ_WRITE_LOCK_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 11
12 #if defined(OS_NACL) 12 #if defined(OS_NACL) || defined(OS_FUCHSIA)
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #endif 14 #endif
15 15
16 #if defined(OS_WIN) 16 #if defined(OS_WIN)
17 #include <windows.h> 17 #include <windows.h>
18 #elif defined(OS_POSIX) 18 #elif defined(OS_POSIX)
19 #include <pthread.h> 19 #include <pthread.h>
20 #elif defined(OS_FUCHSIA)
21 #include <threads.h>
20 #else 22 #else
21 # error No reader-writer lock defined for this platform. 23 # error No reader-writer lock defined for this platform.
22 #endif 24 #endif
23 25
24 namespace base { 26 namespace base {
25 namespace subtle { 27 namespace subtle {
26 28
27 // An OS-independent wrapper around reader-writer locks. There's no magic here. 29 // An OS-independent wrapper around reader-writer locks. There's no magic here.
28 // 30 //
29 // You are strongly encouraged to use base::Lock instead of this, unless you 31 // You are strongly encouraged to use base::Lock instead of this, unless you
(...skipping 14 matching lines...) Expand all
44 void WriteAcquire(); 46 void WriteAcquire();
45 void WriteRelease(); 47 void WriteRelease();
46 48
47 private: 49 private:
48 #if defined(OS_WIN) 50 #if defined(OS_WIN)
49 using NativeHandle = SRWLOCK; 51 using NativeHandle = SRWLOCK;
50 #elif defined(OS_NACL) 52 #elif defined(OS_NACL)
51 using NativeHandle = Lock; 53 using NativeHandle = Lock;
52 #elif defined(OS_POSIX) 54 #elif defined(OS_POSIX)
53 using NativeHandle = pthread_rwlock_t; 55 using NativeHandle = pthread_rwlock_t;
56 #elif defined(OS_FUCHSIA)
57 using NativeHandle = Lock;
54 #endif 58 #endif
55 59
56 NativeHandle native_handle_; 60 NativeHandle native_handle_;
57 61
58 #if defined(OS_NACL) 62 #if defined(OS_NACL) || defined(OS_FUCHSIA)
59 // Even though NaCl has a pthread_rwlock implementation, the build rules don't 63 // Even though NaCl has a pthread_rwlock implementation, the build rules don't
60 // make it universally available. So instead, implement a slower and trivial 64 // make it universally available. So instead, implement a slower and trivial
61 // reader-writer lock using a regular mutex. 65 // reader-writer lock using a regular mutex.
62 // TODO(amistry): Remove this and use the posix implementation when it's 66 // TODO(amistry): Remove this and use the posix implementation when it's
63 // available in all build configurations. 67 // available in all build configurations.
64 uint32_t readers_ = 0; 68 uint32_t readers_ = 0;
65 // base::Lock does checking to ensure the lock is acquired and released on the 69 // base::Lock does checking to ensure the lock is acquired and released on the
66 // same thread. This is not the case for this lock, so use pthread mutexes 70 // same thread. This is not the case for this lock, so use pthread mutexes
67 // directly here. 71 // directly here.
68 pthread_mutex_t writer_lock_ = PTHREAD_MUTEX_INITIALIZER; 72 pthread_mutex_t writer_lock_ = PTHREAD_MUTEX_INITIALIZER;
(...skipping 27 matching lines...) Expand all
96 100
97 private: 101 private:
98 ReadWriteLock& lock_; 102 ReadWriteLock& lock_;
99 DISALLOW_COPY_AND_ASSIGN(AutoWriteLock); 103 DISALLOW_COPY_AND_ASSIGN(AutoWriteLock);
100 }; 104 };
101 105
102 } // namespace subtle 106 } // namespace subtle
103 } // namespace base 107 } // namespace base
104 108
105 #endif // BASE_SYNCHRONIZATION_READ_WRITE_LOCK_H_ 109 #endif // BASE_SYNCHRONIZATION_READ_WRITE_LOCK_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698