From fc28b55b298340f8ab7d9e872471e7040e5326b8 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 11 Jun 2009 19:26:30 +0000 Subject: [PATCH] yielding the timeslice --- panda/src/pipeline/threadSimpleImpl.cxx | 4 ++++ panda/src/pipeline/threadSimpleManager.cxx | 16 ++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/panda/src/pipeline/threadSimpleImpl.cxx b/panda/src/pipeline/threadSimpleImpl.cxx index 62e29138f2..1ba9b9382a 100644 --- a/panda/src/pipeline/threadSimpleImpl.cxx +++ b/panda/src/pipeline/threadSimpleImpl.cxx @@ -216,6 +216,10 @@ sleep_this(double seconds) { //////////////////////////////////////////////////////////////////// void ThreadSimpleImpl:: yield_this(bool volunteer) { + if (thread_cat->is_debug() && volunteer) { + thread_cat.debug() + << "Force-yielding " << _parent_obj->get_name() << "\n"; + } _manager->enqueue_ready(this, true); _manager->next_context(); } diff --git a/panda/src/pipeline/threadSimpleManager.cxx b/panda/src/pipeline/threadSimpleManager.cxx index 2e82a152fd..035e7876b4 100644 --- a/panda/src/pipeline/threadSimpleManager.cxx +++ b/panda/src/pipeline/threadSimpleManager.cxx @@ -468,14 +468,22 @@ write_status(ostream &out) const { //////////////////////////////////////////////////////////////////// void ThreadSimpleManager:: system_yield() { + if (thread_cat->is_debug()) { + thread_cat.debug() + << "system_yield\n"; + } + #ifdef WIN32 Sleep(0); #else - struct timespec rqtp; - rqtp.tv_sec = 0; - rqtp.tv_nsec = 0; - nanosleep(&rqtp, NULL); + // We use select() as the only way that seems to actually yield the + // timeslice. sleep() and nanosleep() don't appear to do the trick. + struct timeval tv; + tv.tv_sec = 0; + tv.tv_usec = 1; + select(0, NULL, NULL, NULL, &tv); + #endif // WIN32 }