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), |
| 45 interrupted_(false) {} |
| 46 |
| 47 void NotifyWake(); |
44 | 48 |
45 private: | 49 private: |
46 friend class FutexEmulation; | 50 friend class FutexEmulation; |
47 friend class FutexWaitList; | 51 friend class FutexWaitList; |
48 | 52 |
49 base::ConditionVariable cond_; | 53 base::ConditionVariable cond_; |
50 FutexWaitListNode* prev_; | 54 FutexWaitListNode* prev_; |
51 FutexWaitListNode* next_; | 55 FutexWaitListNode* next_; |
52 void* backing_store_; | 56 void* backing_store_; |
53 size_t wait_addr_; | 57 size_t wait_addr_; |
54 bool waiting_; | 58 bool waiting_; |
| 59 bool interrupted_; |
55 | 60 |
56 DISALLOW_COPY_AND_ASSIGN(FutexWaitListNode); | 61 DISALLOW_COPY_AND_ASSIGN(FutexWaitListNode); |
57 }; | 62 }; |
58 | 63 |
59 | 64 |
60 class FutexWaitList { | 65 class FutexWaitList { |
61 public: | 66 public: |
62 FutexWaitList(); | 67 FutexWaitList(); |
63 | 68 |
64 void AddNode(FutexWaitListNode* node); | 69 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, | 113 int num_waiters_to_wake, int32_t value, |
109 size_t addr2); | 114 size_t addr2); |
110 | 115 |
111 // Return the number of threads waiting on |addr|. Should only be used for | 116 // Return the number of threads waiting on |addr|. Should only be used for |
112 // testing. | 117 // testing. |
113 static Object* NumWaitersForTesting(Isolate* isolate, | 118 static Object* NumWaitersForTesting(Isolate* isolate, |
114 Handle<JSArrayBuffer> array_buffer, | 119 Handle<JSArrayBuffer> array_buffer, |
115 size_t addr); | 120 size_t addr); |
116 | 121 |
117 private: | 122 private: |
| 123 friend class FutexWaitListNode; |
| 124 |
118 static base::LazyMutex mutex_; | 125 static base::LazyMutex mutex_; |
119 static base::LazyInstance<FutexWaitList>::type wait_list_; | 126 static base::LazyInstance<FutexWaitList>::type wait_list_; |
120 }; | 127 }; |
121 } | 128 } |
122 } // namespace v8::internal | 129 } // namespace v8::internal |
123 | 130 |
124 #endif // V8_FUTEX_EMULATION_H_ | 131 #endif // V8_FUTEX_EMULATION_H_ |
OLD | NEW |