Add thread sleep function
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user