static void PASCAL Timer(unsigned int uTimerID, unsigned int uMsg, DWORD_PTR dwUser, DWORD_PTR dw1, DWORD_PTR dw2) { AsyncEvent *p; double tm; std::multimap<double, AsyncEvent *>::iterator e; while (1) { p = s_acSleep.get(); if (p == NULL) break; tm = s_time + s_now + p->result(); s_tms.insert(std::make_pair(tm, p)); } atom_xchg(&s_now, (int)(v8::internal::OS::TimeCurrentMillis() - s_time)); while (1) { e = s_tms.begin(); if (e == s_tms.end()) break; if (e->first > s_time + s_now) break; e->second->apost(0); s_tms.erase(e); } }
/** @brief Lock a mutex. * * * @param mp the mutex * @return 0 on success, negative if fail */ void mutex_lock(mutex_t *mp) { /* count the total number of threads who want to get the mutex */ ADD_LOCK_NUM(mp); /* if the mutex has been destroyed, do not lock it */ /* No need to recover the counter above, it is destroyed */ if (MUTEX_DESTR_YES == mp->destroy) return; /* try to accquire mutex */ while (MUTEX_LOCK_NO != atom_xchg(&mp->lock, MUTEX_LOCK_YES)) /* yield to the thread who own the mutex */ yield (mp->thread); /* get the mutex */ mp->thread = gettid(); return; }