42 lines
738 B
C
42 lines
738 B
C
|
#include <cx.h>
|
||
|
|
||
|
CX_Thread *
|
||
|
cx_thread_new(void *(*target)(void *),
|
||
|
void *ctx) {
|
||
|
CX_Thread *self;
|
||
|
int err;
|
||
|
|
||
|
self = malloc(sizeof(CX_Thread));
|
||
|
if (!self) {
|
||
|
goto err;
|
||
|
}
|
||
|
self->ctx = ctx;
|
||
|
err = pthread_create(&self->thread, NULL, target, self);
|
||
|
if (err) {
|
||
|
goto err;
|
||
|
}
|
||
|
|
||
|
return self;
|
||
|
|
||
|
err:
|
||
|
free(self);
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
CX_ThreadGroup *
|
||
|
cx_threadGroup_new(void *(*target)(void *),
|
||
|
void *ctx) {
|
||
|
CX_ThreadGroup *self;
|
||
|
|
||
|
self = malloc(sizeof(CX_ThreadGroup));
|
||
|
|
||
|
self->workers = malloc(8 * sizeof(CX_Thread *));
|
||
|
self->worker_count = 0;
|
||
|
self->worker_size = 8;
|
||
|
|
||
|
self->group_manager = cx_thread_new(target, ctx);
|
||
|
|
||
|
return self;
|
||
|
}
|
||
|
|