Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 33 #include "win32-headers.h" | 33 #include "win32-headers.h" |
| 34 #endif | 34 #endif |
| 35 | 35 |
| 36 #if V8_OS_POSIX | 36 #if V8_OS_POSIX |
| 37 #include <pthread.h> // NOLINT | 37 #include <pthread.h> // NOLINT |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 namespace v8 { | 40 namespace v8 { |
| 41 namespace internal { | 41 namespace internal { |
| 42 | 42 |
| 43 // Forward declarations. | |
| 44 class ConditionVariable; | |
|
Michael Starzinger
2013/09/02 19:12:43
There should be no need to forward declare this if
Benedikt Meurer
2013/09/03 07:27:39
Done.
| |
| 45 | |
| 43 // ---------------------------------------------------------------------------- | 46 // ---------------------------------------------------------------------------- |
| 44 // Mutex | 47 // Mutex |
| 45 // | 48 // |
| 46 // This class is a synchronization primitive that can be used to protect shared | 49 // This class is a synchronization primitive that can be used to protect shared |
| 47 // data from being simultaneously accessed by multiple threads. A mutex offers | 50 // data from being simultaneously accessed by multiple threads. A mutex offers |
| 48 // exclusive, non-recursive ownership semantics: | 51 // exclusive, non-recursive ownership semantics: |
| 49 // - A calling thread owns a mutex from the time that it successfully calls | 52 // - A calling thread owns a mutex from the time that it successfully calls |
| 50 // either |Lock()| or |TryLock()| until it calls |Unlock()|. | 53 // either |Lock()| or |TryLock()| until it calls |Unlock()|. |
| 51 // - When a thread owns a mutex, all other threads will block (for calls to | 54 // - When a thread owns a mutex, all other threads will block (for calls to |
| 52 // |Lock()|) or receive a |false| return value (for |TryLock()|) if they | 55 // |Lock()|) or receive a |false| return value (for |TryLock()|) if they |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 const NativeHandle& native_handle() const V8_WARN_UNUSED_RESULT { | 90 const NativeHandle& native_handle() const V8_WARN_UNUSED_RESULT { |
| 88 return native_handle_; | 91 return native_handle_; |
| 89 } | 92 } |
| 90 | 93 |
| 91 private: | 94 private: |
| 92 NativeHandle native_handle_; | 95 NativeHandle native_handle_; |
| 93 #ifdef DEBUG | 96 #ifdef DEBUG |
| 94 int level_; | 97 int level_; |
| 95 #endif | 98 #endif |
| 96 | 99 |
| 100 V8_INLINE(void CheckHeldAndUnmark()) { | |
|
Michael Starzinger
2013/09/02 19:12:43
nit: s/Check/Assert/, we use "check" to describe p
Benedikt Meurer
2013/09/03 07:27:39
Done.
| |
| 101 #ifdef DEBUG | |
| 102 ASSERT_EQ(1, level_); | |
| 103 level_--; | |
| 104 #endif | |
| 105 } | |
| 106 | |
| 107 V8_INLINE(void CheckUnheldAndMark()) { | |
|
Michael Starzinger
2013/09/02 19:12:43
Likewise.
Benedikt Meurer
2013/09/03 07:27:39
Done.
| |
| 108 #ifdef DEBUG | |
| 109 ASSERT_EQ(0, level_); | |
| 110 level_++; | |
| 111 #endif | |
| 112 } | |
| 113 | |
| 114 friend class ConditionVariable; | |
| 115 | |
| 97 DISALLOW_COPY_AND_ASSIGN(Mutex); | 116 DISALLOW_COPY_AND_ASSIGN(Mutex); |
| 98 }; | 117 }; |
| 99 | 118 |
| 100 | 119 |
| 101 // POD Mutex initialized lazily (i.e. the first time Pointer() is called). | 120 // POD Mutex initialized lazily (i.e. the first time Pointer() is called). |
| 102 // Usage: | 121 // Usage: |
| 103 // static LazyMutex my_mutex = LAZY_MUTEX_INITIALIZER; | 122 // static LazyMutex my_mutex = LAZY_MUTEX_INITIALIZER; |
| 104 // | 123 // |
| 105 // void my_function() { | 124 // void my_function() { |
| 106 // LockGuard<Mutex> guard(my_mutex.Pointer()); | 125 // LockGuard<Mutex> guard(my_mutex.Pointer()); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 private: | 233 private: |
| 215 Mutex* mutex_; | 234 Mutex* mutex_; |
| 216 | 235 |
| 217 LockGuard(const LockGuard<Mutex>& other) V8_DELETE; | 236 LockGuard(const LockGuard<Mutex>& other) V8_DELETE; |
| 218 LockGuard<Mutex>& operator=(const LockGuard<Mutex>& other) V8_DELETE; | 237 LockGuard<Mutex>& operator=(const LockGuard<Mutex>& other) V8_DELETE; |
| 219 }; | 238 }; |
| 220 | 239 |
| 221 } } // namespace v8::internal | 240 } } // namespace v8::internal |
| 222 | 241 |
| 223 #endif // V8_PLATFORM_MUTEX_H_ | 242 #endif // V8_PLATFORM_MUTEX_H_ |
| OLD | NEW |