40 ConditionVariable::ConditionVariable() {
44 #if (V8_OS_FREEBSD || V8_OS_NETBSD || V8_OS_OPENBSD || \
45 (V8_OS_LINUX && V8_LIBC_GLIBC)) && !V8_LIBRT_NOT_AVAILABLE
48 pthread_condattr_t attr;
49 int result = pthread_condattr_init(&attr);
51 result = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
53 result = pthread_cond_init(&native_handle_, &attr);
55 result = pthread_condattr_destroy(&attr);
57 int result = pthread_cond_init(&native_handle_,
NULL);
64 ConditionVariable::~ConditionVariable() {
65 int result = pthread_cond_destroy(&native_handle_);
71 void ConditionVariable::NotifyOne() {
72 int result = pthread_cond_signal(&native_handle_);
78 void ConditionVariable::NotifyAll() {
79 int result = pthread_cond_broadcast(&native_handle_);
85 void ConditionVariable::Wait(Mutex* mutex) {
86 mutex->AssertHeldAndUnmark();
87 int result = pthread_cond_wait(&native_handle_, &mutex->native_handle());
90 mutex->AssertUnheldAndMark();
94 bool ConditionVariable::WaitFor(Mutex* mutex,
const TimeDelta& rel_time) {
97 mutex->AssertHeldAndUnmark();
101 ts = rel_time.ToTimespec();
104 result = pthread_cond_timedwait_relative_np(
105 &native_handle_, &mutex->native_handle(), &ts);
110 #if (V8_OS_FREEBSD || V8_OS_NETBSD || V8_OS_OPENBSD || \
111 (V8_OS_LINUX && V8_LIBC_GLIBC)) && !V8_LIBRT_NOT_AVAILABLE
114 result = clock_gettime(CLOCK_MONOTONIC, &ts);
116 Time now = Time::FromTimespec(ts);
119 Time now = Time::NowFromSystemTime();
121 Time end_time = now + rel_time;
123 ts = end_time.ToTimespec();
124 result = pthread_cond_timedwait(
125 &native_handle_, &mutex->native_handle(), &ts);
126 #endif // V8_OS_MACOSX
127 mutex->AssertUnheldAndMark();
128 if (result == ETIMEDOUT) {
137 struct ConditionVariable::Event {
143 BOOL ok = ::CloseHandle(handle_);
148 bool WaitFor(
DWORD timeout_ms) {
149 DWORD result = ::WaitForSingleObject(handle_, timeout_ms);
150 if (result == WAIT_OBJECT_0) {
153 ASSERT(result == WAIT_TIMEOUT);
160 volatile bool notified_;
164 ConditionVariable::NativeHandle::~NativeHandle() {
167 while (freelist_ !=
NULL) {
168 Event*
event = freelist_;
169 freelist_ =
event->next_;
175 ConditionVariable::Event* ConditionVariable::NativeHandle::Pre() {
176 LockGuard<Mutex> lock_guard(&mutex_);
179 Event*
event = freelist_;
181 freelist_ =
event->next_;
185 event->thread_ = GetCurrentThread();
186 event->notified_ =
false;
190 for (Event* we = waitlist_; we !=
NULL; we = we->next_) {
196 event->next_ = waitlist_;
203 void ConditionVariable::NativeHandle::Post(Event* event,
bool result) {
204 LockGuard<Mutex> lock_guard(&mutex_);
207 for (Event** wep = &waitlist_;; wep = &(*wep)->next_) {
217 for (Event* fe = freelist_; fe !=
NULL; fe = fe->next_) {
223 BOOL ok = ::ResetEvent(event->handle_);
228 event->next_ = freelist_;
232 if (!result && event->notified_ && waitlist_ !=
NULL) {
233 ok = ::SetEvent(waitlist_->handle_);
236 waitlist_->notified_ =
true;
241 ConditionVariable::ConditionVariable() {}
244 ConditionVariable::~ConditionVariable() {}
247 void ConditionVariable::NotifyOne() {
250 LockGuard<Mutex> lock_guard(native_handle_.mutex());
251 Event* highest_event =
NULL;
252 int highest_priority = std::numeric_limits<int>::min();
253 for (Event* event = native_handle().waitlist();
255 event =
event->next_) {
256 if (event->notified_) {
259 int priority = GetThreadPriority(event->thread_);
260 ASSERT_NE(THREAD_PRIORITY_ERROR_RETURN, priority);
261 if (priority >= highest_priority) {
262 highest_priority = priority;
263 highest_event = event;
266 if (highest_event !=
NULL) {
267 ASSERT(!highest_event->notified_);
268 ::SetEvent(highest_event->handle_);
269 highest_event->notified_ =
true;
274 void ConditionVariable::NotifyAll() {
276 LockGuard<Mutex> lock_guard(native_handle_.mutex());
277 for (Event* event = native_handle().waitlist();
279 event =
event->next_) {
280 if (!event->notified_) {
281 ::SetEvent(event->handle_);
282 event->notified_ =
true;
288 void ConditionVariable::Wait(Mutex* mutex) {
290 Event*
event = native_handle_.Pre();
296 while (!event->WaitFor(INFINITE))
304 native_handle_.Post(event,
true);
308 bool ConditionVariable::WaitFor(Mutex* mutex,
const TimeDelta& rel_time) {
310 Event*
event = native_handle_.Pre();
316 TimeTicks now = TimeTicks::Now();
317 TimeTicks end = now + rel_time;
320 int64_t msec = (end - now).InMilliseconds();
321 if (msec >= static_cast<int64_t>(INFINITE)) {
322 result =
event->WaitFor(INFINITE - 1);
326 now = TimeTicks::Now();
328 result =
event->WaitFor((msec < 0) ? 0 : static_cast<DWORD>(msec));
337 ASSERT(!result || event->notified_);
338 native_handle_.Post(event, result);
343 #endif // V8_OS_POSIX
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths true
#define ASSERT(condition)
#define ASSERT_GE(v1, v2)
typedef HANDLE(__stdcall *DLL_FUNC_TYPE(CreateToolhelp32Snapshot))(DWORD dwFlags
typedef DWORD(__stdcall *DLL_FUNC_TYPE(SymGetOptions))(VOID)
typedef BOOL(__stdcall *DLL_FUNC_TYPE(SymInitialize))(IN HANDLE hProcess
#define ASSERT_EQ(v1, v2)
#define ASSERT_NE(v1, v2)