OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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_FUTEX_EMULATION_H_ | 5 #ifndef V8_FUTEX_EMULATION_H_ |
6 #define V8_FUTEX_EMULATION_H_ | 6 #define V8_FUTEX_EMULATION_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "src/allocation.h" | 10 #include "src/allocation.h" |
11 #include "src/base/atomicops.h" | |
11 #include "src/base/lazy-instance.h" | 12 #include "src/base/lazy-instance.h" |
12 #include "src/base/macros.h" | 13 #include "src/base/macros.h" |
13 #include "src/base/platform/condition-variable.h" | 14 #include "src/base/platform/condition-variable.h" |
14 #include "src/base/platform/mutex.h" | 15 #include "src/base/platform/mutex.h" |
15 #include "src/handles.h" | 16 #include "src/handles.h" |
16 | 17 |
17 // Support for emulating futexes, a low-level synchronization primitive. They | 18 // Support for emulating futexes, a low-level synchronization primitive. They |
18 // are natively supported by Linux, but must be emulated for other platforms. | 19 // are natively supported by Linux, but must be emulated for other platforms. |
19 // This library emulates them on all platforms using mutexes and condition | 20 // This library emulates them on all platforms using mutexes and condition |
20 // variables for consistency. | 21 // variables for consistency. |
(...skipping 12 matching lines...) Expand all Loading... | |
33 class Isolate; | 34 class Isolate; |
34 class JSArrayBuffer; | 35 class JSArrayBuffer; |
35 | 36 |
36 class FutexWaitListNode { | 37 class FutexWaitListNode { |
37 public: | 38 public: |
38 FutexWaitListNode() | 39 FutexWaitListNode() |
39 : prev_(nullptr), | 40 : prev_(nullptr), |
40 next_(nullptr), | 41 next_(nullptr), |
41 backing_store_(nullptr), | 42 backing_store_(nullptr), |
42 wait_addr_(0), | 43 wait_addr_(0), |
43 waiting_(false) {} | 44 waiting_(false), |
Jarin
2015/08/19 05:26:05
waiting_(0)
binji
2015/08/19 17:36:23
Done.
| |
45 interrupted_(false) {} | |
46 | |
47 bool waiting() { return base::NoBarrier_Load(&waiting_) != 0; } | |
48 | |
49 void set_waiting(bool value) { | |
50 base::NoBarrier_Store(&waiting_, value ? 1 : 0); | |
51 } | |
52 | |
53 void NotifyWake(); | |
44 | 54 |
45 private: | 55 private: |
46 friend class FutexEmulation; | 56 friend class FutexEmulation; |
47 friend class FutexWaitList; | 57 friend class FutexWaitList; |
48 | 58 |
49 base::ConditionVariable cond_; | 59 base::ConditionVariable cond_; |
50 FutexWaitListNode* prev_; | 60 FutexWaitListNode* prev_; |
51 FutexWaitListNode* next_; | 61 FutexWaitListNode* next_; |
52 void* backing_store_; | 62 void* backing_store_; |
53 size_t wait_addr_; | 63 size_t wait_addr_; |
54 bool waiting_; | 64 base::Atomic32 waiting_; |
65 bool interrupted_; | |
55 | 66 |
56 DISALLOW_COPY_AND_ASSIGN(FutexWaitListNode); | 67 DISALLOW_COPY_AND_ASSIGN(FutexWaitListNode); |
57 }; | 68 }; |
58 | 69 |
59 | 70 |
60 class FutexWaitList { | 71 class FutexWaitList { |
61 public: | 72 public: |
62 FutexWaitList(); | 73 FutexWaitList(); |
63 | 74 |
64 void AddNode(FutexWaitListNode* node); | 75 void AddNode(FutexWaitListNode* node); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 int num_waiters_to_wake, int32_t value, | 119 int num_waiters_to_wake, int32_t value, |
109 size_t addr2); | 120 size_t addr2); |
110 | 121 |
111 // Return the number of threads waiting on |addr|. Should only be used for | 122 // Return the number of threads waiting on |addr|. Should only be used for |
112 // testing. | 123 // testing. |
113 static Object* NumWaitersForTesting(Isolate* isolate, | 124 static Object* NumWaitersForTesting(Isolate* isolate, |
114 Handle<JSArrayBuffer> array_buffer, | 125 Handle<JSArrayBuffer> array_buffer, |
115 size_t addr); | 126 size_t addr); |
116 | 127 |
117 private: | 128 private: |
129 friend class FutexWaitListNode; | |
130 | |
118 static base::LazyMutex mutex_; | 131 static base::LazyMutex mutex_; |
119 static base::LazyInstance<FutexWaitList>::type wait_list_; | 132 static base::LazyInstance<FutexWaitList>::type wait_list_; |
120 }; | 133 }; |
121 } | 134 } |
122 } // namespace v8::internal | 135 } // namespace v8::internal |
123 | 136 |
124 #endif // V8_FUTEX_EMULATION_H_ | 137 #endif // V8_FUTEX_EMULATION_H_ |
OLD | NEW |