diff options
Diffstat (limited to 'common/threads.cpp')
-rw-r--r-- | common/threads.cpp | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/common/threads.cpp b/common/threads.cpp index 86fbb7b5..489e5f5b 100644 --- a/common/threads.cpp +++ b/common/threads.cpp @@ -158,91 +158,6 @@ void althrd_setname(const char *name) } -typedef struct thread_cntr { - althrd_start_t func; - void *arg; -} thread_cntr; - -static void *althrd_starter(void *arg) -{ - thread_cntr cntr; - memcpy(&cntr, arg, sizeof(cntr)); - free(arg); - - return (void*)(intptr_t)((*cntr.func)(cntr.arg)); -} - - -int althrd_create(althrd_t *thr, althrd_start_t func, void *arg) -{ - thread_cntr *cntr; - pthread_attr_t attr; - size_t stackmult = 1; - int err; - - cntr = static_cast<thread_cntr*>(malloc(sizeof(*cntr))); - if(!cntr) return althrd_nomem; - - if(pthread_attr_init(&attr) != 0) - { - free(cntr); - return althrd_error; - } -retry_stacksize: - if(pthread_attr_setstacksize(&attr, THREAD_STACK_SIZE*stackmult) != 0) - { - pthread_attr_destroy(&attr); - free(cntr); - return althrd_error; - } - - cntr->func = func; - cntr->arg = arg; - if((err=pthread_create(thr, &attr, althrd_starter, cntr)) == 0) - { - pthread_attr_destroy(&attr); - return althrd_success; - } - - if(err == EINVAL) - { - /* If an invalid stack size, try increasing it (limit x4, 8MB). */ - if(stackmult < 4) - { - stackmult *= 2; - goto retry_stacksize; - } - /* If still nothing, try defaults and hope they're good enough. */ - if(pthread_create(thr, NULL, althrd_starter, cntr) == 0) - { - pthread_attr_destroy(&attr); - return althrd_success; - } - } - pthread_attr_destroy(&attr); - free(cntr); - return althrd_error; -} - -int althrd_detach(althrd_t thr) -{ - if(pthread_detach(thr) != 0) - return althrd_error; - return althrd_success; -} - -int althrd_join(althrd_t thr, int *res) -{ - void *code; - - if(pthread_join(thr, &code) != 0) - return althrd_error; - if(res != NULL) - *res = (int)(intptr_t)code; - return althrd_success; -} - - int almtx_init(almtx_t *mtx, int type) { int ret; |