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" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 FutexWaitListNode* head_; | 76 FutexWaitListNode* head_; |
77 FutexWaitListNode* tail_; | 77 FutexWaitListNode* tail_; |
78 | 78 |
79 DISALLOW_COPY_AND_ASSIGN(FutexWaitList); | 79 DISALLOW_COPY_AND_ASSIGN(FutexWaitList); |
80 }; | 80 }; |
81 | 81 |
82 | 82 |
83 class FutexEmulation : public AllStatic { | 83 class FutexEmulation : public AllStatic { |
84 public: | 84 public: |
| 85 // Pass to Wake() to wake all waiters. |
| 86 static const uint32_t kWakeAll = UINT32_MAX; |
| 87 |
85 // Check that array_buffer[addr] == value, and return "not-equal" if not. If | 88 // Check that array_buffer[addr] == value, and return "not-equal" if not. If |
86 // they are equal, block execution on |isolate|'s thread until woken via | 89 // they are equal, block execution on |isolate|'s thread until woken via |
87 // |Wake|, or when the time given in |rel_timeout_ms| elapses. Note that | 90 // |Wake|, or when the time given in |rel_timeout_ms| elapses. Note that |
88 // |rel_timeout_ms| can be Infinity. | 91 // |rel_timeout_ms| can be Infinity. |
89 // If woken, return "ok", otherwise return "timed-out". The initial check and | 92 // If woken, return "ok", otherwise return "timed-out". The initial check and |
90 // the decision to wait happen atomically. | 93 // the decision to wait happen atomically. |
91 static Object* Wait(Isolate* isolate, Handle<JSArrayBuffer> array_buffer, | 94 static Object* Wait(Isolate* isolate, Handle<JSArrayBuffer> array_buffer, |
92 size_t addr, int32_t value, double rel_timeout_ms); | 95 size_t addr, int32_t value, double rel_timeout_ms); |
93 | 96 |
94 // Wake |num_waiters_to_wake| threads that are waiting on the given |addr|. | 97 // Wake |num_waiters_to_wake| threads that are waiting on the given |addr|. |
95 // The rest of the waiters will continue to wait. The return value is the | 98 // |num_waiters_to_wake| can be kWakeAll, in which case all waiters are |
96 // number of woken waiters. | 99 // woken. The rest of the waiters will continue to wait. The return value is |
| 100 // the number of woken waiters. |
97 static Object* Wake(Isolate* isolate, Handle<JSArrayBuffer> array_buffer, | 101 static Object* Wake(Isolate* isolate, Handle<JSArrayBuffer> array_buffer, |
98 size_t addr, int num_waiters_to_wake); | 102 size_t addr, uint32_t num_waiters_to_wake); |
99 | 103 |
100 // Return the number of threads waiting on |addr|. Should only be used for | 104 // Return the number of threads waiting on |addr|. Should only be used for |
101 // testing. | 105 // testing. |
102 static Object* NumWaitersForTesting(Isolate* isolate, | 106 static Object* NumWaitersForTesting(Isolate* isolate, |
103 Handle<JSArrayBuffer> array_buffer, | 107 Handle<JSArrayBuffer> array_buffer, |
104 size_t addr); | 108 size_t addr); |
105 | 109 |
106 private: | 110 private: |
107 friend class FutexWaitListNode; | 111 friend class FutexWaitListNode; |
108 | 112 |
109 static base::LazyMutex mutex_; | 113 static base::LazyMutex mutex_; |
110 static base::LazyInstance<FutexWaitList>::type wait_list_; | 114 static base::LazyInstance<FutexWaitList>::type wait_list_; |
111 }; | 115 }; |
112 } // namespace internal | 116 } // namespace internal |
113 } // namespace v8 | 117 } // namespace v8 |
114 | 118 |
115 #endif // V8_FUTEX_EMULATION_H_ | 119 #endif // V8_FUTEX_EMULATION_H_ |
OLD | NEW |