diff options
| -rw-r--r-- | include/bh/thread.h | 2 | ||||
| -rw-r--r-- | src/thread_null.c | 5 | ||||
| -rw-r--r-- | src/thread_posix.c | 13 | ||||
| -rw-r--r-- | src/thread_win.c | 6 |
4 files changed, 26 insertions, 0 deletions
diff --git a/include/bh/thread.h b/include/bh/thread.h index 3360c42..598f4f7 100644 --- a/include/bh/thread.h +++ b/include/bh/thread.h @@ -60,6 +60,8 @@ void bh_task_reuse(bh_task_t *task, int bh_task_done(bh_task_t *task); +int bh_thread_sleep(unsigned long timeout); + int bh_thread_join(bh_thread_t *thread); int bh_thread_detach(bh_thread_t *thread); diff --git a/src/thread_null.c b/src/thread_null.c index 212174a..6aaefc2 100644 --- a/src/thread_null.c +++ b/src/thread_null.c @@ -41,6 +41,11 @@ int bh_thread_init(bh_thread_t *thread, return BH_NO_IMPL; } +int bh_thread_sleep(unsigned long timeout) +{ + return BH_NO_IMPL; +} + /** * Joins the \a thread. * diff --git a/src/thread_posix.c b/src/thread_posix.c index 84e8e09..1122baf 100644 --- a/src/thread_posix.c +++ b/src/thread_posix.c @@ -55,6 +55,19 @@ bh_thread_t *bh_thread_new(bh_task_t *task) return result; } +int bh_thread_sleep(unsigned long timeout) +{ + struct timespec ts; + + ts.tv_sec = timeout / 1000; + ts.tv_nsec = (timeout - ts.tv_sec * 1000) * 1000000; + + if (nanosleep(&ts, NULL)) + return BH_ERROR; + + return BH_OK; +} + int bh_thread_join(bh_thread_t *thread) { /* Join the thread */ diff --git a/src/thread_win.c b/src/thread_win.c index 92a5bb4..3b78f46 100644 --- a/src/thread_win.c +++ b/src/thread_win.c @@ -79,6 +79,12 @@ bh_thread_t *bh_thread_new_base(bh_task_t *task, return result; } +int bh_thread_sleep(unsigned long timeout) +{ + Sleep(timeout); + return BH_OK; +} + int bh_thread_join(bh_thread_t *thread) { /* Join the thread */ |
