Skip to content

Commit

Permalink
native: Object.wait()
Browse files Browse the repository at this point in the history
Signed-off-by: imkiva <[email protected]>
  • Loading branch information
imkiva committed May 28, 2018
1 parent dc63433 commit 4d09a36
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion include/kivm/oop/oop.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ namespace kivm {
static void *operator new(size_t size, bool = true) noexcept;

static void *operator new(size_t size, const std::nothrow_t &) noexcept = delete;

static void *operator new[](size_t size, bool = true) throw();

static void *operator new[](size_t size, const std::nothrow_t &) noexcept = delete;

static void operator delete(void *ptr);

static void operator delete[](void *ptr);
Expand Down Expand Up @@ -65,7 +67,7 @@ namespace kivm {

inline void wait() { _monitor.wait(); }

inline void wait(long macro_sec) { _monitor.wait(macro_sec); }
inline void wait(jlong timeout) { _monitor.wait((jlong) timeout); }

inline void notify() { _monitor.notify(); }

Expand Down
2 changes: 1 addition & 1 deletion include/shared/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace kivm {
_cond.wait(_lock);
}

void wait(long millisecond) {
void wait(jlong millisecond) {
_cond.wait_for(_lock, std::chrono::milliseconds(millisecond));
}

Expand Down
9 changes: 9 additions & 0 deletions src/kivm/native/java_lang_Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,12 @@ JAVA_NATIVE void Java_java_lang_Object_notify(JNIEnv *env, jobject javaObject) {
auto object = Resolver::javaOop(javaObject);
object->getMarkOop()->notify();
}

JAVA_NATIVE void Java_java_lang_Object_wait(JNIEnv *env, jobject javaObject, jlong timeout) {
auto object = Resolver::javaOop(javaObject);
if (timeout == 0) {
object->getMarkOop()->wait();
} else {
object->getMarkOop()->wait(timeout);
}
}

0 comments on commit 4d09a36

Please sign in to comment.