@@ -16,45 +16,44 @@ #include "config.h" #include #include +#import "OFPlainThread.h" #import "OFData.h" - -#import "thread.h" -#import "tlskey.h" +#import "OFTLSKey.h" #include #include #include #ifndef OF_MORPHOS -extern void of_tlskey_thread_exited(void); +extern void OFTLSKeyThreadExited(void); #endif -static of_tlskey_t threadKey; +static OFTLSKey threadKey; OF_CONSTRUCTOR() { - OF_ENSURE(of_tlskey_new(&threadKey) == 0); + OFEnsure(OFTLSKeyNew(&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) == 0); + OFPlainThread thread = + (OFPlainThread)((struct Process *)FindTask(NULL))->pr_ExitData; + OFEnsure(OFTLSKeySet(threadKey, thread) == 0); thread->function(thread->object); ObtainSemaphore(&thread->semaphore); @try { thread->done = true; #ifndef OF_MORPHOS - of_tlskey_thread_exited(); + OFTLSKeyThreadExited(); #endif if (thread->detached) detached = true; else if (thread->joinTask != NULL) @@ -66,21 +65,21 @@ if (detached) free(thread); } int -of_thread_attr_init(of_thread_attr_t *attr) +OFPlainThreadAttributesInit(OFPlainThreadAttributes *attr) { attr->priority = 0; attr->stackSize = 0; return 0; } int -of_thread_new(of_thread_t *thread, const char *name, void (*function)(id), - id object, const of_thread_attr_t *attr) +OFPlainThreadNew(OFPlainThread *thread, const char *name, void (*function)(id), + id object, const OFPlainThreadAttributes *attr) { OFMutableData *tags = nil; if ((*thread = calloc(1, sizeof(**thread))) == NULL) return ENOMEM; @@ -153,18 +152,24 @@ } return 0; } -of_thread_t -of_thread_current(void) +OFPlainThread +OFCurrentPlainThread(void) +{ + return OFTLSKeyGet(threadKey); +} + +bool +OFPlainThreadIsCurrent(OFPlainThread thread) { - return of_tlskey_get(threadKey); + return (thread->task == FindTask(NULL)); } int -of_thread_join(of_thread_t thread) +OFPlainThreadJoin(OFPlainThread thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) { ReleaseSemaphore(&thread->semaphore); @@ -193,11 +198,11 @@ return 0; } int -of_thread_detach(of_thread_t thread) +OFPlainThreadDetach(OFPlainThread thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) free(thread); @@ -208,8 +213,8 @@ return 0; } void -of_thread_set_name(const char *name) +OFSetThreadName(const char *name) { }