| OLD | NEW |
| 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/lazy-instance.h" | 8 #include "src/base/lazy-instance.h" |
| 9 #if V8_OS_WIN | 9 #if V8_OS_WIN |
| 10 #include "src/base/win32-headers.h" | 10 #include "src/base/win32-headers.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // exclusive, non-recursive ownership semantics: | 26 // exclusive, non-recursive ownership semantics: |
| 27 // - A calling thread owns a mutex from the time that it successfully calls | 27 // - A calling thread owns a mutex from the time that it successfully calls |
| 28 // either |Lock()| or |TryLock()| until it calls |Unlock()|. | 28 // either |Lock()| or |TryLock()| until it calls |Unlock()|. |
| 29 // - When a thread owns a mutex, all other threads will block (for calls to | 29 // - 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 | 30 // |Lock()|) or receive a |false| return value (for |TryLock()|) if they |
| 31 // attempt to claim ownership of the mutex. | 31 // attempt to claim ownership of the mutex. |
| 32 // A calling thread must not own the mutex prior to calling |Lock()| or | 32 // 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 | 33 // |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. | 34 // while still owned by some thread. The Mutex class is non-copyable. |
| 35 | 35 |
| 36 class Mutex FINAL { | 36 class Mutex final { |
| 37 public: | 37 public: |
| 38 Mutex(); | 38 Mutex(); |
| 39 ~Mutex(); | 39 ~Mutex(); |
| 40 | 40 |
| 41 // Locks the given mutex. If the mutex is currently unlocked, it becomes | 41 // 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 | 42 // locked and owned by the calling thread, and immediately. If the mutex |
| 43 // is already locked by another thread, suspends the calling thread until | 43 // is already locked by another thread, suspends the calling thread until |
| 44 // the mutex is unlocked. | 44 // the mutex is unlocked. |
| 45 void Lock(); | 45 void Lock(); |
| 46 | 46 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // calls to |Unlock()|. | 120 // calls to |Unlock()|. |
| 121 // - When a thread owns a recursive mutex, all other threads will block (for | 121 // - 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 | 122 // calls to |Lock()|) or receive a |false| return value (for |TryLock()|) if |
| 123 // they attempt to claim ownership of the recursive mutex. | 123 // they attempt to claim ownership of the recursive mutex. |
| 124 // - The maximum number of times that a recursive mutex may be locked is | 124 // - 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 | 125 // unspecified, but after that number is reached, calls to |Lock()| will |
| 126 // probably abort the process and calls to |TryLock()| return false. | 126 // probably abort the process and calls to |TryLock()| return false. |
| 127 // The behavior of a program is undefined if a recursive mutex is destroyed | 127 // 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. | 128 // while still owned by some thread. The RecursiveMutex class is non-copyable. |
| 129 | 129 |
| 130 class RecursiveMutex FINAL { | 130 class RecursiveMutex final { |
| 131 public: | 131 public: |
| 132 RecursiveMutex(); | 132 RecursiveMutex(); |
| 133 ~RecursiveMutex(); | 133 ~RecursiveMutex(); |
| 134 | 134 |
| 135 // Locks the mutex. If another thread has already locked the mutex, a call to | 135 // 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 | 136 // |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 | 137 // |Lock()| on a recursive mutex repeatedly. Ownership will only be released |
| 138 // after the thread makes a matching number of calls to |Unlock()|. | 138 // after the thread makes a matching number of calls to |Unlock()|. |
| 139 // The behavior is undefined if the mutex is not unlocked before being | 139 // The behavior is undefined if the mutex is not unlocked before being |
| 140 // destroyed, i.e. some thread still owns it. | 140 // destroyed, i.e. some thread still owns it. |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 // LockGuard | 192 // LockGuard |
| 193 // | 193 // |
| 194 // This class is a mutex wrapper that provides a convenient RAII-style mechanism | 194 // This class is a mutex wrapper that provides a convenient RAII-style mechanism |
| 195 // for owning a mutex for the duration of a scoped block. | 195 // for owning a mutex for the duration of a scoped block. |
| 196 // When a LockGuard object is created, it attempts to take ownership of the | 196 // When a LockGuard object is created, it attempts to take ownership of the |
| 197 // mutex it is given. When control leaves the scope in which the LockGuard | 197 // mutex it is given. When control leaves the scope in which the LockGuard |
| 198 // object was created, the LockGuard is destructed and the mutex is released. | 198 // object was created, the LockGuard is destructed and the mutex is released. |
| 199 // The LockGuard class is non-copyable. | 199 // The LockGuard class is non-copyable. |
| 200 | 200 |
| 201 template <typename Mutex> | 201 template <typename Mutex> |
| 202 class LockGuard FINAL { | 202 class LockGuard final { |
| 203 public: | 203 public: |
| 204 explicit LockGuard(Mutex* mutex) : mutex_(mutex) { mutex_->Lock(); } | 204 explicit LockGuard(Mutex* mutex) : mutex_(mutex) { mutex_->Lock(); } |
| 205 ~LockGuard() { mutex_->Unlock(); } | 205 ~LockGuard() { mutex_->Unlock(); } |
| 206 | 206 |
| 207 private: | 207 private: |
| 208 Mutex* mutex_; | 208 Mutex* mutex_; |
| 209 | 209 |
| 210 DISALLOW_COPY_AND_ASSIGN(LockGuard); | 210 DISALLOW_COPY_AND_ASSIGN(LockGuard); |
| 211 }; | 211 }; |
| 212 | 212 |
| 213 } } // namespace v8::base | 213 } } // namespace v8::base |
| 214 | 214 |
| 215 #endif // V8_BASE_PLATFORM_MUTEX_H_ | 215 #endif // V8_BASE_PLATFORM_MUTEX_H_ |
| OLD | NEW |