NEED A GOOD LAWYER
This commit is contained in:
parent
855cdc1344
commit
ed72a09f08
3 changed files with 52 additions and 2 deletions
|
@ -1,5 +1,4 @@
|
|||
#ifndef _WIN32
|
||||
#include "tcp.h"
|
||||
|
||||
|
||||
#endif
|
|
@ -18,7 +18,20 @@
|
|||
typedef pthread_mutex_t glv_mutex_t;
|
||||
#endif
|
||||
|
||||
glv_thread_t* glv_thread_create();
|
||||
#include <stdlib.h>
|
||||
typedef void(*glv_func_t)(void*);
|
||||
|
||||
glv_thread_t* glv_thread_create(glv_func_t func, void* args);
|
||||
void glv_thread_join(glv_thread_t* thread);
|
||||
void glv_thread_destroy(glv_thread_t* thread);
|
||||
|
||||
/** END THREAD DECLS **/
|
||||
/**********************/
|
||||
/** BEGIN MUTX DECLS **/
|
||||
|
||||
glv_mutex_t* glv_mutex_create();
|
||||
void glv_mutex_lock(glv_mutex_t* mutex);
|
||||
void glv_mutex_unlock(glv_mutex_t* mutex);
|
||||
void glv_mutex_destroy(glv_mutex_t* mutex);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,6 +1,44 @@
|
|||
#ifndef _WIN32
|
||||
#include "thread.h"
|
||||
|
||||
typedef struct {
|
||||
glv_func_t func;
|
||||
void* args;
|
||||
} wrapper_t;
|
||||
|
||||
static void* _wrapper_func(void* proxy) {
|
||||
wrapper_t wrapper = *((wrapper_t*)proxy);
|
||||
free(proxy);
|
||||
|
||||
wrapper.func(wrapper.args);
|
||||
}
|
||||
|
||||
glv_thread_t* glv_thread_create(glv_func_t func, void* args) {
|
||||
wrapper_t* proxy = malloc(sizeof(wrapper_t));
|
||||
proxy->func = func;
|
||||
proxy->args = args;
|
||||
|
||||
glv_thread_t* thread = malloc(sizeof(thread));
|
||||
if(pthread_create(thread, NULL, _wrapper_func, proxy) == 0)
|
||||
return thread;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void glv_thread_join(glv_thread_t* thread) {
|
||||
pthread_join(*thread, NULL);
|
||||
}
|
||||
|
||||
void glv_thread_destroy(glv_thread_t* thread) {
|
||||
free(thread);
|
||||
}
|
||||
|
||||
/** END THREAD IMPL **/
|
||||
/*********************/
|
||||
/** BEGIN MUTX IMPL **/
|
||||
|
||||
glv_mutex_t* glv_mutex_create() {
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Reference in a new issue