bool Thread::sleep(unsigned int time) { bool rval = true; // enter an arbitrary monitor Monitor m; m.enter(); { // wait to re-enter the monitor until the specified time uint32_t remaining = time; uint64_t st = System::getCurrentMilliseconds(); uint64_t et; uint64_t dt; while(rval && (time == 0 || remaining > 0)) { rval = waitToEnter(&m, remaining); if(rval && time > 0) { // update remaining time et = System::getCurrentMilliseconds(); dt = et - st; remaining = (dt >= remaining ? 0 : remaining - dt); st = et; } } } m.exit(); return rval; }
void Thread::interrupt() { lock(); // only interrupt if not already interrupted if(!isInterrupted()) { // set interrupted flag mInterrupted = true; // Note: disabled due to lack of support in windows // send SIGINT to thread //sendSignal(SIGINT); // store thread's current monitor Monitor* m = mWaitMonitor; unlock(); // wake up thread it is inside of a monitor if(m != NULL) { m->enter(); m->signalAll(); m->exit(); } } else { unlock(); } }