From b108d0acfd062756da69074242e24ea7b2856b8a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 26 Nov 2018 21:19:20 -0800 Subject: Remove the last remaining uses of althrd_t --- common/threads.cpp | 85 ------------------------------------------------------ 1 file changed, 85 deletions(-) (limited to 'common/threads.cpp') 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(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; -- cgit v1.2.3