17 ConditionVariable::ConditionVariable() {
21 #if (V8_OS_FREEBSD || V8_OS_NETBSD || V8_OS_OPENBSD || \
22 (V8_OS_LINUX && V8_LIBC_GLIBC)) && !V8_LIBRT_NOT_AVAILABLE
25 pthread_condattr_t attr;
26 int result = pthread_condattr_init(&attr);
28 result = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
30 result = pthread_cond_init(&native_handle_, &attr);
32 result = pthread_condattr_destroy(&attr);
34 int result = pthread_cond_init(&native_handle_,
NULL);
41 ConditionVariable::~ConditionVariable() {
42 int result = pthread_cond_destroy(&native_handle_);
48 void ConditionVariable::NotifyOne() {
49 int result = pthread_cond_signal(&native_handle_);
55 void ConditionVariable::NotifyAll() {
56 int result = pthread_cond_broadcast(&native_handle_);
62 void ConditionVariable::Wait(Mutex* mutex) {
63 mutex->AssertHeldAndUnmark();
64 int result = pthread_cond_wait(&native_handle_, &mutex->native_handle());
67 mutex->AssertUnheldAndMark();
71 bool ConditionVariable::WaitFor(Mutex* mutex,
const TimeDelta& rel_time) {
74 mutex->AssertHeldAndUnmark();
78 ts = rel_time.ToTimespec();
81 result = pthread_cond_timedwait_relative_np(
82 &native_handle_, &mutex->native_handle(), &ts);
87 #if (V8_OS_FREEBSD || V8_OS_NETBSD || V8_OS_OPENBSD || \
88 (V8_OS_LINUX && V8_LIBC_GLIBC)) && !V8_LIBRT_NOT_AVAILABLE
91 result = clock_gettime(CLOCK_MONOTONIC, &ts);
93 Time now = Time::FromTimespec(ts);
96 Time now = Time::NowFromSystemTime();
98 Time end_time = now + rel_time;
100 ts = end_time.ToTimespec();
101 result = pthread_cond_timedwait(
102 &native_handle_, &mutex->native_handle(), &ts);
104 mutex->AssertUnheldAndMark();
105 if (result == ETIMEDOUT) {
114 struct ConditionVariable::Event {
120 BOOL ok = ::CloseHandle(handle_);
125 bool WaitFor(
DWORD timeout_ms) {
126 DWORD result = ::WaitForSingleObject(handle_, timeout_ms);
127 if (result == WAIT_OBJECT_0) {
130 DCHECK(result == WAIT_TIMEOUT);
137 volatile bool notified_;
141 ConditionVariable::NativeHandle::~NativeHandle() {
144 while (freelist_ !=
NULL) {
145 Event*
event = freelist_;
146 freelist_ =
event->next_;
152 ConditionVariable::Event* ConditionVariable::NativeHandle::Pre() {
153 LockGuard<Mutex> lock_guard(&mutex_);
156 Event*
event = freelist_;
158 freelist_ =
event->next_;
162 event->thread_ = GetCurrentThread();
163 event->notified_ =
false;
167 for (Event* we = waitlist_; we !=
NULL; we = we->next_) {
173 event->next_ = waitlist_;
180 void ConditionVariable::NativeHandle::Post(Event* event,
bool result) {
181 LockGuard<Mutex> lock_guard(&mutex_);
184 for (Event** wep = &waitlist_;; wep = &(*wep)->next_) {
194 for (Event* fe = freelist_; fe !=
NULL; fe = fe->next_) {
200 BOOL ok = ::ResetEvent(event->handle_);
205 event->next_ = freelist_;
209 if (!result && event->notified_ && waitlist_ !=
NULL) {
210 ok = ::SetEvent(waitlist_->handle_);
213 waitlist_->notified_ =
true;
218 ConditionVariable::ConditionVariable() {}
221 ConditionVariable::~ConditionVariable() {}
224 void ConditionVariable::NotifyOne() {
227 LockGuard<Mutex> lock_guard(native_handle_.mutex());
228 Event* highest_event =
NULL;
230 for (Event* event = native_handle().waitlist();
232 event =
event->next_) {
233 if (event->notified_) {
236 int priority = GetThreadPriority(event->thread_);
237 DCHECK_NE(THREAD_PRIORITY_ERROR_RETURN, priority);
238 if (priority >= highest_priority) {
239 highest_priority = priority;
240 highest_event = event;
243 if (highest_event !=
NULL) {
244 DCHECK(!highest_event->notified_);
245 ::SetEvent(highest_event->handle_);
246 highest_event->notified_ =
true;
251 void ConditionVariable::NotifyAll() {
253 LockGuard<Mutex> lock_guard(native_handle_.mutex());
254 for (Event* event = native_handle().waitlist();
256 event =
event->next_) {
257 if (!event->notified_) {
258 ::SetEvent(event->handle_);
259 event->notified_ =
true;
265 void ConditionVariable::Wait(Mutex* mutex) {
267 Event*
event = native_handle_.Pre();
273 while (!event->WaitFor(INFINITE))
281 native_handle_.Post(event,
true);
285 bool ConditionVariable::WaitFor(Mutex* mutex,
const TimeDelta& rel_time) {
287 Event*
event = native_handle_.Pre();
293 TimeTicks now = TimeTicks::Now();
294 TimeTicks end = now + rel_time;
297 int64_t msec = (end - now).InMilliseconds();
298 if (msec >=
static_cast<int64_t
>(INFINITE)) {
299 result =
event->WaitFor(INFINITE - 1);
303 now = TimeTicks::Now();
305 result =
event->WaitFor((msec < 0) ? 0 :
static_cast<DWORD>(msec));
314 DCHECK(!result || event->notified_);
315 native_handle_.Post(event, result);
enable harmony numeric enable harmony object literal extensions true
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK_NE(v1, v2)
#define DCHECK_GE(v1, v2)
#define DCHECK(condition)
#define DCHECK_EQ(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
static int min(int a, int b)
Debugger support for the V8 JavaScript engine.