From aa9c887fb4c34d604d7bfad3b67b0dc439938286 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 1 Feb 2011 18:14:32 -0700 Subject: [PATCH] implement Thread.yield --- src/classpath-avian.cpp | 7 +++++++ src/classpath-openjdk.cpp | 8 ++------ src/posix.cpp | 5 +++++ src/system.h | 1 + src/windows.cpp | 4 ++++ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/classpath-avian.cpp b/src/classpath-avian.cpp index 656086f4c1..95b2a32703 100644 --- a/src/classpath-avian.cpp +++ b/src/classpath-avian.cpp @@ -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*) diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index 8882976f3c..b06d1406f4 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -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 diff --git a/src/posix.cpp b/src/posix.cpp index de879c3496..53dfb0bb90 100644 --- a/src/posix.cpp +++ b/src/posix.cpp @@ -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(tv.tv_usec) / 1000); } + virtual void yield() { + sched_yield(); + } + virtual void exit(int code) { ::exit(code); } diff --git a/src/system.h b/src/system.h index 4d155cfd66..6e2ea14721 100644 --- a/src/system.h +++ b/src/system.h @@ -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; diff --git a/src/windows.cpp b/src/windows.cpp index b86d2fa99e..0079121d2f 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -807,6 +807,10 @@ class MySystem: public System { | time.dwLowDateTime) / 10000) - 11644473600000LL; } + virtual void yield() { + SwitchToThread(); + } + virtual void exit(int code) { ::exit(code); }