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

Side by Side Diff: src/base/platform/mutex.h

Issue 2381273002: Turn libbase into a component (Closed)
Patch Set: updates Created 4 years, 2 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 | « src/base/platform/condition-variable.h ('k') | src/base/platform/platform.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project 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 V8_BASE_PLATFORM_MUTEX_H_ 5 #ifndef V8_BASE_PLATFORM_MUTEX_H_
6 #define V8_BASE_PLATFORM_MUTEX_H_ 6 #define V8_BASE_PLATFORM_MUTEX_H_
7 7
8 #include "src/base/base-export.h"
8 #include "src/base/lazy-instance.h" 9 #include "src/base/lazy-instance.h"
9 #if V8_OS_WIN 10 #if V8_OS_WIN
10 #include "src/base/win32-headers.h" 11 #include "src/base/win32-headers.h"
11 #endif 12 #endif
12 #include "src/base/logging.h" 13 #include "src/base/logging.h"
13 14
14 #if V8_OS_POSIX 15 #if V8_OS_POSIX
15 #include <pthread.h> // NOLINT 16 #include <pthread.h> // NOLINT
16 #endif 17 #endif
17 18
18 namespace v8 { 19 namespace v8 {
19 namespace base { 20 namespace base {
20 21
21 // ---------------------------------------------------------------------------- 22 // ----------------------------------------------------------------------------
22 // Mutex 23 // Mutex
23 // 24 //
24 // This class is a synchronization primitive that can be used to protect shared 25 // This class is a synchronization primitive that can be used to protect shared
25 // data from being simultaneously accessed by multiple threads. A mutex offers 26 // data from being simultaneously accessed by multiple threads. A mutex offers
26 // exclusive, non-recursive ownership semantics: 27 // exclusive, non-recursive ownership semantics:
27 // - A calling thread owns a mutex from the time that it successfully calls 28 // - A calling thread owns a mutex from the time that it successfully calls
28 // either |Lock()| or |TryLock()| until it calls |Unlock()|. 29 // either |Lock()| or |TryLock()| until it calls |Unlock()|.
29 // - When a thread owns a mutex, all other threads will block (for calls to 30 // - When a thread owns a mutex, all other threads will block (for calls to
30 // |Lock()|) or receive a |false| return value (for |TryLock()|) if they 31 // |Lock()|) or receive a |false| return value (for |TryLock()|) if they
31 // attempt to claim ownership of the mutex. 32 // attempt to claim ownership of the mutex.
32 // A calling thread must not own the mutex prior to calling |Lock()| or 33 // A calling thread must not own the mutex prior to calling |Lock()| or
33 // |TryLock()|. The behavior of a program is undefined if a mutex is destroyed 34 // |TryLock()|. The behavior of a program is undefined if a mutex is destroyed
34 // while still owned by some thread. The Mutex class is non-copyable. 35 // while still owned by some thread. The Mutex class is non-copyable.
35 36
36 class Mutex final { 37 class V8_BASE_EXPORT Mutex final {
37 public: 38 public:
38 Mutex(); 39 Mutex();
39 ~Mutex(); 40 ~Mutex();
40 41
41 // Locks the given mutex. If the mutex is currently unlocked, it becomes 42 // Locks the given mutex. If the mutex is currently unlocked, it becomes
42 // locked and owned by the calling thread, and immediately. If the mutex 43 // locked and owned by the calling thread, and immediately. If the mutex
43 // is already locked by another thread, suspends the calling thread until 44 // is already locked by another thread, suspends the calling thread until
44 // the mutex is unlocked. 45 // the mutex is unlocked.
45 void Lock(); 46 void Lock();
46 47
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // calls to |Unlock()|. 121 // calls to |Unlock()|.
121 // - When a thread owns a recursive mutex, all other threads will block (for 122 // - When a thread owns a recursive mutex, all other threads will block (for
122 // calls to |Lock()|) or receive a |false| return value (for |TryLock()|) if 123 // calls to |Lock()|) or receive a |false| return value (for |TryLock()|) if
123 // they attempt to claim ownership of the recursive mutex. 124 // they attempt to claim ownership of the recursive mutex.
124 // - The maximum number of times that a recursive mutex may be locked is 125 // - The maximum number of times that a recursive mutex may be locked is
125 // unspecified, but after that number is reached, calls to |Lock()| will 126 // unspecified, but after that number is reached, calls to |Lock()| will
126 // probably abort the process and calls to |TryLock()| return false. 127 // probably abort the process and calls to |TryLock()| return false.
127 // The behavior of a program is undefined if a recursive mutex is destroyed 128 // The behavior of a program is undefined if a recursive mutex is destroyed
128 // while still owned by some thread. The RecursiveMutex class is non-copyable. 129 // while still owned by some thread. The RecursiveMutex class is non-copyable.
129 130
130 class RecursiveMutex final { 131 class V8_BASE_EXPORT RecursiveMutex final {
131 public: 132 public:
132 RecursiveMutex(); 133 RecursiveMutex();
133 ~RecursiveMutex(); 134 ~RecursiveMutex();
134 135
135 // Locks the mutex. If another thread has already locked the mutex, a call to 136 // Locks the mutex. If another thread has already locked the mutex, a call to
136 // |Lock()| will block execution until the lock is acquired. A thread may call 137 // |Lock()| will block execution until the lock is acquired. A thread may call
137 // |Lock()| on a recursive mutex repeatedly. Ownership will only be released 138 // |Lock()| on a recursive mutex repeatedly. Ownership will only be released
138 // after the thread makes a matching number of calls to |Unlock()|. 139 // after the thread makes a matching number of calls to |Unlock()|.
139 // The behavior is undefined if the mutex is not unlocked before being 140 // The behavior is undefined if the mutex is not unlocked before being
140 // destroyed, i.e. some thread still owns it. 141 // destroyed, i.e. some thread still owns it.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 private: 208 private:
208 Mutex* mutex_; 209 Mutex* mutex_;
209 210
210 DISALLOW_COPY_AND_ASSIGN(LockGuard); 211 DISALLOW_COPY_AND_ASSIGN(LockGuard);
211 }; 212 };
212 213
213 } // namespace base 214 } // namespace base
214 } // namespace v8 215 } // namespace v8
215 216
216 #endif // V8_BASE_PLATFORM_MUTEX_H_ 217 #endif // V8_BASE_PLATFORM_MUTEX_H_
OLDNEW
« no previous file with comments | « src/base/platform/condition-variable.h ('k') | src/base/platform/platform.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698