Bugfixes for pthreads.
This commit is contained in:
parent
99a2307d1d
commit
d106ecdc65
|
@ -20,6 +20,12 @@
|
||||||
#include "uhub.h"
|
#include "uhub.h"
|
||||||
|
|
||||||
#ifdef POSIX_THREAD_SUPPORT
|
#ifdef POSIX_THREAD_SUPPORT
|
||||||
|
|
||||||
|
struct pthread_data
|
||||||
|
{
|
||||||
|
pthread_t handle;
|
||||||
|
};
|
||||||
|
|
||||||
void uhub_mutex_init(uhub_mutex_t* mutex)
|
void uhub_mutex_init(uhub_mutex_t* mutex)
|
||||||
{
|
{
|
||||||
pthread_mutex_init(mutex, NULL);
|
pthread_mutex_init(mutex, NULL);
|
||||||
|
@ -48,23 +54,25 @@ int uhub_mutex_trylock(uhub_mutex_t* mutex)
|
||||||
|
|
||||||
uhub_thread_t* uhub_thread_create(uhub_thread_start start, void* arg)
|
uhub_thread_t* uhub_thread_create(uhub_thread_start start, void* arg)
|
||||||
{
|
{
|
||||||
uhub_thread_t* thread = (uhub_thread_t*) hub_malloc_zero(sizeof(uhub_thread_t));
|
struct pthread_data* thread = (struct pthread_data*) hub_malloc_zero(sizeof(struct pthread_data));
|
||||||
int ret = pthread_create(thread, NULL, start, arg);
|
int ret = pthread_create(&thread->handle, NULL, start, arg);
|
||||||
if (ret == 0)
|
if (ret != 0)
|
||||||
return thread;
|
{
|
||||||
hub_free(thread);
|
hub_free(thread);
|
||||||
return NULL;
|
thread = NULL;
|
||||||
|
}
|
||||||
|
return thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
void uhub_thread_cancel(uhub_thread_t* thread)
|
void uhub_thread_cancel(uhub_thread_t* thread)
|
||||||
{
|
{
|
||||||
pthread_cancel(thread);
|
pthread_cancel(thread->handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void* uhub_thread_join(uhub_thread_t* thread)
|
void* uhub_thread_join(uhub_thread_t* thread)
|
||||||
{
|
{
|
||||||
void* ret = NULL;
|
void* ret = NULL;
|
||||||
pthread_join(thread, &ret);
|
pthread_join(thread->handle, &ret);
|
||||||
hub_free(thread);
|
hub_free(thread);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
typedef void*(*uhub_thread_start)(void*) ;
|
typedef void*(*uhub_thread_start)(void*) ;
|
||||||
|
|
||||||
#ifdef POSIX_THREAD_SUPPORT
|
#ifdef POSIX_THREAD_SUPPORT
|
||||||
typedef pthread_t uhub_thread_t;
|
typedef struct pthread_data uhub_thread_t;
|
||||||
typedef pthread_mutex_t uhub_mutex_t;
|
typedef pthread_mutex_t uhub_mutex_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue