/* Sleep "exactly" msec milliseconds. * Threads can be finalized at this moment. * Source: http://cc.byexamples.com/2007/05/25/nanosleep-is-better-than-sleep-and-usleep/ */ void guaranteedSleep(int msec) { if (cheetah_shutdown) { if (pthread_mutex_lock(&shutdown_mutex)) perror("pthread_mutex_lock"); shutdown_threads--; if (pthread_mutex_unlock(&shutdown_mutex)) perror("pthread_mutex_unlock"); finalizeThread(); } struct timespec timeout0; struct timespec timeout1; struct timespec* tmp; struct timespec* t0 = &timeout0; struct timespec* t1 = &timeout1; t0->tv_sec = msec / 1000; t0->tv_nsec = (msec % 1000) * (1000 * 1000); while ((nanosleep(t0, t1) == (-1)) && (errno == EINTR)) { tmp = t0; t0 = t1; t1 = tmp; } /* * Old Implementation: struct timespec time; time.tv_sec = msec / 1000; time.tv_nsec = (msec % 1000) * (1000 * 1000); nanosleep(&time,NULL);*/ }
void ExecutionTracker::SimulateExit(thrID myself, void * ret_addr, void * arg) { glock(); log->SimulateExit(myself); finalizeThread(myself, ret_addr); gunlock(); Originals::pthread_exit(arg); }
void ExecutionTracker::ThreadFinish(thrID myself, void * (*start_routine) (void *), void * arg) { glock(); log->ThreadFinish(myself, arg); finalizeThread(myself, reinterpret_cast<void *>(start_routine)); lock_count--; Originals::pthread_mutex_unlock(global_lock); }