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/lock.h

Issue 2028303005: Add PTHREAD_PRIO_INHERIT to POSIX Locks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_LOCK_H_ 5 #ifndef BASE_SYNCHRONIZATION_LOCK_H_
6 #define BASE_SYNCHRONIZATION_LOCK_H_ 6 #define BASE_SYNCHRONIZATION_LOCK_H_
7 7
8 #include "base/base_export.h" 8 #include "base/base_export.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/synchronization/lock_impl.h" 11 #include "base/synchronization/lock_impl.h"
12 #include "base/threading/platform_thread.h" 12 #include "base/threading/platform_thread.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 14
15 namespace base { 15 namespace base {
16 16
17 #if defined(OS_POSIX)
18
19 // Determines which platforms can consider using priority inheritance locks. If
20 // priority inheritance is possible, it does not necessarily mean it's
21 // available. Lock::PriorityInheritanceAvailable must still be checked.
22 #if defined(OS_NACL) || defined(OS_ANDROID)
23 #define PRIORITY_INHERITANCE_LOCKS_POSSIBLE() 0
24 #else
25 #define PRIORITY_INHERITANCE_LOCKS_POSSIBLE() 1
26 #endif
27
28 #endif
29
17 // A convenient wrapper for an OS specific critical section. The only real 30 // A convenient wrapper for an OS specific critical section. The only real
18 // intelligence in this class is in debug mode for the support for the 31 // intelligence in this class is in debug mode for the support for the
19 // AssertAcquired() method. 32 // AssertAcquired() method.
20 class BASE_EXPORT Lock { 33 class BASE_EXPORT Lock {
21 public: 34 public:
22 #if !DCHECK_IS_ON() 35 #if !DCHECK_IS_ON()
23 // Optimized wrapper implementation 36 // Optimized wrapper implementation
24 Lock() : lock_() {} 37 Lock() : lock_() {}
25 ~Lock() {} 38 ~Lock() {}
26 void Acquire() { lock_.Lock(); } 39 void Acquire() { lock_.Lock(); }
(...skipping 27 matching lines...) Expand all
54 bool rv = lock_.Try(); 67 bool rv = lock_.Try();
55 if (rv) { 68 if (rv) {
56 CheckUnheldAndMark(); 69 CheckUnheldAndMark();
57 } 70 }
58 return rv; 71 return rv;
59 } 72 }
60 73
61 void AssertAcquired() const; 74 void AssertAcquired() const;
62 #endif // DCHECK_IS_ON() 75 #endif // DCHECK_IS_ON()
63 76
77 #if defined(OS_POSIX)
78 // Whether this platform has priority inheritance available. All locks will
79 // attempt to use the priority inheritance version if available.
80 static bool PriorityInheritanceAvailable() {
81 return internal::LockImpl::PriorityInheritanceAvailable();
82 }
83 #endif
84
64 #if defined(OS_POSIX) || defined(OS_WIN) 85 #if defined(OS_POSIX) || defined(OS_WIN)
65 // Both Windows and POSIX implementations of ConditionVariable need to be 86 // Both Windows and POSIX implementations of ConditionVariable need to be
66 // able to see our lock and tweak our debugging counters, as they release and 87 // able to see our lock and tweak our debugging counters, as they release and
67 // acquire locks inside of their condition variable APIs. 88 // acquire locks inside of their condition variable APIs.
68 friend class ConditionVariable; 89 friend class ConditionVariable;
69 #endif 90 #endif
70 91
71 private: 92 private:
72 #if DCHECK_IS_ON() 93 #if DCHECK_IS_ON()
73 // Members and routines taking care of locks assertions. 94 // Members and routines taking care of locks assertions.
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 } 148 }
128 149
129 private: 150 private:
130 Lock& lock_; 151 Lock& lock_;
131 DISALLOW_COPY_AND_ASSIGN(AutoUnlock); 152 DISALLOW_COPY_AND_ASSIGN(AutoUnlock);
132 }; 153 };
133 154
134 } // namespace base 155 } // namespace base
135 156
136 #endif // BASE_SYNCHRONIZATION_LOCK_H_ 157 #endif // BASE_SYNCHRONIZATION_LOCK_H_
OLDNEW
« no previous file with comments | « no previous file | base/synchronization/lock_impl.h » ('j') | base/synchronization/lock_impl_posix.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698