@@ -12,10 +12,12 @@ * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ + +#include #ifdef HAVE_PTHREAD_NP_H # include #endif @@ -112,12 +114,14 @@ struct thread_ctx *ctx; if (attr != NULL) { struct sched_param param; - if (attr->priority < -1 || attr->priority > 1) + if (attr->priority < -1 || attr->priority > 1) { + errno = EINVAL; return false; + } #ifdef HAVE_PTHREAD_ATTR_SETINHERITSCHED if (pthread_attr_setinheritsched(&pattr, PTHREAD_EXPLICIT_SCHED) != 0) return false; @@ -139,12 +143,14 @@ attr->stackSize) != 0) return false; } } - if ((ctx = malloc(sizeof(*ctx))) == NULL) + if ((ctx = malloc(sizeof(*ctx))) == NULL) { + errno = ENOMEM; return false; + } ctx->function = function; ctx->object = object; ret = (pthread_create(thread, &pattr, @@ -159,18 +165,11 @@ bool of_thread_join(of_thread_t thread) { void *ret; - if (pthread_join(thread, &ret) != 0) - return false; - -#ifdef PTHREAD_CANCELED - return (ret != PTHREAD_CANCELED); -#else - return true; -#endif + return (pthread_join(thread, &ret) == 0); } bool of_thread_detach(of_thread_t thread) {