Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(593)

Side by Side Diff: src/futex-emulation.h

Issue 1230303005: Signal a blocked futex if the isolate is interrupted; don't busy-wait (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix windows build Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 11 matching lines...) Expand all
32 33
33 class Isolate; 34 class Isolate;
34 35
35 class FutexWaitListNode { 36 class FutexWaitListNode {
36 public: 37 public:
37 FutexWaitListNode() 38 FutexWaitListNode()
38 : prev_(nullptr), 39 : prev_(nullptr),
39 next_(nullptr), 40 next_(nullptr),
40 backing_store_(nullptr), 41 backing_store_(nullptr),
41 wait_addr_(0), 42 wait_addr_(0),
42 waiting_(false) {} 43 waiting_(false),
44 interrupted_(false) {}
45
46 bool waiting() { return base::NoBarrier_Load(&waiting_) != 0; }
47 bool interrupted() { return base::NoBarrier_Load(&interrupted_) != 0; }
48
49 void set_waiting(bool value) {
50 base::NoBarrier_Store(&waiting_, value ? 1 : 0);
51 }
52
53 void set_interrupted(bool value) {
54 base::NoBarrier_Store(&interrupted_, value ? 1 : 0);
55 }
56
57 bool CheckInterruptedAndClear() {
58 return base::NoBarrier_CompareAndSwap(&interrupted_, 1, 0) == 1;
59 }
60
61 void NotifyWake();
43 62
44 private: 63 private:
45 friend class FutexEmulation; 64 friend class FutexEmulation;
46 friend class FutexWaitList; 65 friend class FutexWaitList;
47 66
48 base::ConditionVariable cond_; 67 base::ConditionVariable cond_;
49 FutexWaitListNode* prev_; 68 FutexWaitListNode* prev_;
50 FutexWaitListNode* next_; 69 FutexWaitListNode* next_;
51 void* backing_store_; 70 void* backing_store_;
52 size_t wait_addr_; 71 size_t wait_addr_;
53 bool waiting_; 72 base::Atomic32 waiting_;
73 base::Atomic32 interrupted_;
54 74
55 DISALLOW_COPY_AND_ASSIGN(FutexWaitListNode); 75 DISALLOW_COPY_AND_ASSIGN(FutexWaitListNode);
56 }; 76 };
57 77
58 78
59 class FutexWaitList { 79 class FutexWaitList {
60 public: 80 public:
61 FutexWaitList(); 81 FutexWaitList();
62 82
63 void AddNode(FutexWaitListNode* node); 83 void AddNode(FutexWaitListNode* node);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 int num_waiters_to_wake, int32_t value, 127 int num_waiters_to_wake, int32_t value,
108 size_t addr2); 128 size_t addr2);
109 129
110 // Return the number of threads waiting on |addr|. Should only be used for 130 // Return the number of threads waiting on |addr|. Should only be used for
111 // testing. 131 // testing.
112 static Object* NumWaitersForTesting(Isolate* isolate, 132 static Object* NumWaitersForTesting(Isolate* isolate,
113 Handle<JSArrayBuffer> array_buffer, 133 Handle<JSArrayBuffer> array_buffer,
114 size_t addr); 134 size_t addr);
115 135
116 private: 136 private:
137 friend class FutexWaitListNode;
138
117 static base::LazyMutex mutex_; 139 static base::LazyMutex mutex_;
118 static base::LazyInstance<FutexWaitList>::type wait_list_; 140 static base::LazyInstance<FutexWaitList>::type wait_list_;
119 }; 141 };
120 } 142 }
121 } // namespace v8::internal 143 } // namespace v8::internal
122 144
123 #endif // V8_FUTEX_EMULATION_H_ 145 #endif // V8_FUTEX_EMULATION_H_
OLDNEW
« no previous file with comments | « src/execution.cc ('k') | src/futex-emulation.cc » ('j') | src/futex-emulation.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698