Sync to the latest version.
Can be broken or partially implemented.
This commit is contained in:
@@ -20,17 +20,46 @@ static void *bh_thread_run(void *arg)
|
||||
int bh_thread_init(bh_thread_t *thread,
|
||||
bh_task_t *task)
|
||||
{
|
||||
thread->allocated = 0;
|
||||
return pthread_create(&thread->handle, NULL, bh_thread_run, task);
|
||||
}
|
||||
|
||||
bh_thread_t *bh_thread_new(bh_task_t *task)
|
||||
{
|
||||
bh_thread_t *result;
|
||||
|
||||
result = malloc(sizeof(*result));
|
||||
|
||||
if (result && bh_thread_init(result, task))
|
||||
{
|
||||
free(result);
|
||||
result = NULL;
|
||||
}
|
||||
|
||||
if (result)
|
||||
result->allocated = 1;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int bh_thread_join(bh_thread_t *thread)
|
||||
{
|
||||
return pthread_join(thread->handle, NULL);
|
||||
int result = pthread_join(thread->handle, NULL);
|
||||
|
||||
if (thread->allocated)
|
||||
free(thread);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int bh_thread_detach(bh_thread_t *thread)
|
||||
{
|
||||
return pthread_detach(thread->handle);
|
||||
int result = pthread_detach(thread->handle);
|
||||
|
||||
if (thread->allocated)
|
||||
free(thread);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int bh_mutex_init(bh_mutex_t *mutex)
|
||||
|
||||
Reference in New Issue
Block a user