implement Thread.yield

This commit is contained in:
Joel Dice 2011-02-01 18:14:32 -07:00
parent 9ef9d9619d
commit aa9c887fb4
5 changed files with 19 additions and 6 deletions

View File

@ -579,6 +579,13 @@ Avian_java_lang_Thread_enumerate
return count;
}
extern "C" JNIEXPORT void JNICALL
Avian_java_lang_Thread_yield
(Thread* t, object, uintptr_t*)
{
t->m->system->yield();
}
extern "C" JNIEXPORT void JNICALL
Avian_avian_Classes_acquireClassLock
(Thread* t, object, uintptr_t*)

View File

@ -2210,13 +2210,9 @@ EXPORT(JVM_SetThreadPriority)(Thread*, jobject, jint)
}
extern "C" JNIEXPORT void JNICALL
EXPORT(JVM_Yield)(Thread*, jclass)
EXPORT(JVM_Yield)(Thread* t, jclass)
{
#ifdef PLATFORM_WINDOWS
SwitchToThread();
#else
sched_yield();
#endif
t->m->system->yield();
}
uint64_t

View File

@ -30,6 +30,7 @@
#include "sys/ucontext.h"
#include "stdint.h"
#include "dirent.h"
#include "sched.h"
#include "arch.h"
#include "system.h"
@ -795,6 +796,10 @@ class MySystem: public System {
(static_cast<int64_t>(tv.tv_usec) / 1000);
}
virtual void yield() {
sched_yield();
}
virtual void exit(int code) {
::exit(code);
}

View File

@ -141,6 +141,7 @@ class System {
virtual char pathSeparator() = 0;
virtual char fileSeparator() = 0;
virtual int64_t now() = 0;
virtual void yield() = 0;
virtual void exit(int code) = 0;
virtual void abort() = 0;
virtual void dispose() = 0;

View File

@ -807,6 +807,10 @@ class MySystem: public System {
| time.dwLowDateTime) / 10000) - 11644473600000LL;
}
virtual void yield() {
SwitchToThread();
}
virtual void exit(int code) {
::exit(code);
}