mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
yielding the timeslice
This commit is contained in:
parent
e10d398afd
commit
fc28b55b29
@ -216,6 +216,10 @@ sleep_this(double seconds) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void ThreadSimpleImpl::
|
void ThreadSimpleImpl::
|
||||||
yield_this(bool volunteer) {
|
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->enqueue_ready(this, true);
|
||||||
_manager->next_context();
|
_manager->next_context();
|
||||||
}
|
}
|
||||||
|
@ -468,14 +468,22 @@ write_status(ostream &out) const {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void ThreadSimpleManager::
|
void ThreadSimpleManager::
|
||||||
system_yield() {
|
system_yield() {
|
||||||
|
if (thread_cat->is_debug()) {
|
||||||
|
thread_cat.debug()
|
||||||
|
<< "system_yield\n";
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
Sleep(0);
|
Sleep(0);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
struct timespec rqtp;
|
// We use select() as the only way that seems to actually yield the
|
||||||
rqtp.tv_sec = 0;
|
// timeslice. sleep() and nanosleep() don't appear to do the trick.
|
||||||
rqtp.tv_nsec = 0;
|
struct timeval tv;
|
||||||
nanosleep(&rqtp, NULL);
|
tv.tv_sec = 0;
|
||||||
|
tv.tv_usec = 1;
|
||||||
|
select(0, NULL, NULL, NULL, &tv);
|
||||||
|
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user