@@ -34,20 +34,20 @@ #endif static of_tlskey_t threadKey; OF_CONSTRUCTOR() { - OF_ENSURE(of_tlskey_new(&threadKey)); + OF_ENSURE(of_tlskey_new(&threadKey) == 0); } static void functionWrapper(void) { bool detached = false; of_thread_t thread = (of_thread_t)((struct Process *)FindTask(NULL))->pr_ExitData; - OF_ENSURE(of_tlskey_set(threadKey, thread)); + OF_ENSURE(of_tlskey_set(threadKey, thread) == 0); thread->function(thread->object); ObtainSemaphore(&thread->semaphore); @try { @@ -67,29 +67,27 @@ if (detached) free(thread); } -bool +int of_thread_attr_init(of_thread_attr_t *attr) { attr->priority = 0; attr->stackSize = 0; - return true; + return 0; } -bool +int of_thread_new(of_thread_t *thread, const char *name, void (*function)(id), id object, const of_thread_attr_t *attr) { OFMutableData *tags = nil; - if ((*thread = calloc(1, sizeof(**thread))) == NULL) { - errno = ENOMEM; - return false; - } + if ((*thread = calloc(1, sizeof(**thread))) == NULL) + return ENOMEM; @try { (*thread)->function = function; (*thread)->object = object; InitSemaphore(&(*thread)->semaphore); @@ -122,14 +120,12 @@ ADD_TAG(NP_CloseInput, FALSE) ADD_TAG(NP_CloseOutput, FALSE) ADD_TAG(NP_CloseError, FALSE) if (attr != NULL && attr->priority != 0) { - if (attr->priority < 1 || attr->priority > 1) { - errno = EINVAL; - return false; - } + if (attr->priority < 1 || attr->priority > 1) + return EINVAL; /* * -1 should be -128 (lowest possible priority) while * +1 should be +127 (highest possible priority). */ @@ -147,51 +143,46 @@ #undef ADD_TAG (*thread)->task = (struct Task *)CreateNewProc(tags.items); if ((*thread)->task == NULL) { free(*thread); - errno = EAGAIN; - return false; + return EAGAIN; } } @catch (id e) { free(*thread); @throw e; } @finally { [tags release]; } - return true; + return 0; } of_thread_t of_thread_current(void) { return of_tlskey_get(threadKey); } -bool +int of_thread_join(of_thread_t thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) { ReleaseSemaphore(&thread->semaphore); free(thread); - return true; + return 0; } @try { - if (thread->detached || thread->joinTask != NULL) { - errno = EINVAL; - return false; - } - - if ((thread->joinSigBit = AllocSignal(-1)) == -1) { - errno = EAGAIN; - return false; - } + if (thread->detached || thread->joinTask != NULL) + return EINVAL; + + if ((thread->joinSigBit = AllocSignal(-1)) == -1) + return EAGAIN; thread->joinTask = FindTask(NULL); } @finally { ReleaseSemaphore(&thread->semaphore); } @@ -200,14 +191,14 @@ FreeSignal(thread->joinSigBit); assert(thread->done); free(thread); - return true; + return 0; } -bool +int of_thread_detach(of_thread_t thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) @@ -215,12 +206,12 @@ else thread->detached = true; ReleaseSemaphore(&thread->semaphore); - return true; + return 0; } void of_thread_set_name(const char *name) { }