Differences From Artifact [1416763f86]:
- File src/platform/amiga/thread.m — part of check-in [c75596237e] at 2020-12-06 01:54:02 on branch trunk — Use OS-native TLS keys on MorphOS (user: js, size: 4585) [annotate] [blame] [check-ins using] [more...]
To Artifact [020e13328a]:
- File
src/platform/amiga/thread.m
— part of check-in
[5b37fbeb82]
at
2020-12-20 21:26:08
on branch trunk
— Return error instead of using errno for threading
errno is problematic for Amiga libraries and is also not thread-safe on
some systems, even though it should. (user: js, size: 4462) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
32 33 34 35 36 37 38 | #ifndef OF_MORPHOS extern void of_tlskey_thread_exited(void); #endif static of_tlskey_t threadKey; OF_CONSTRUCTOR() { | | | | 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #ifndef OF_MORPHOS extern void of_tlskey_thread_exited(void); #endif static of_tlskey_t threadKey; OF_CONSTRUCTOR() { 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) == 0); thread->function(thread->object); ObtainSemaphore(&thread->semaphore); @try { thread->done = true; |
︙ | ︙ | |||
65 66 67 68 69 70 71 | ReleaseSemaphore(&thread->semaphore); } if (detached) free(thread); } | < > | < > | < | < | 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | ReleaseSemaphore(&thread->semaphore); } if (detached) free(thread); } int of_thread_attr_init(of_thread_attr_t *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) { OFMutableData *tags = nil; if ((*thread = calloc(1, sizeof(**thread))) == NULL) return ENOMEM; @try { (*thread)->function = function; (*thread)->object = object; InitSemaphore(&(*thread)->semaphore); tags = [[OFMutableData alloc] |
︙ | ︙ | |||
120 121 122 123 124 125 126 | ADD_TAG(NP_Output, ((struct Process *)FindTask(NULL))->pr_COS) ADD_TAG(NP_Error, ((struct Process *)FindTask(NULL))->pr_CES) ADD_TAG(NP_CloseInput, FALSE) ADD_TAG(NP_CloseOutput, FALSE) ADD_TAG(NP_CloseError, FALSE) if (attr != NULL && attr->priority != 0) { | | < | < | 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | ADD_TAG(NP_Output, ((struct Process *)FindTask(NULL))->pr_COS) ADD_TAG(NP_Error, ((struct Process *)FindTask(NULL))->pr_CES) 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) return EINVAL; /* * -1 should be -128 (lowest possible priority) while * +1 should be +127 (highest possible priority). */ ADD_TAG(NP_Priority, (attr->priority > 0 ? attr->priority * 127 : attr->priority * 128)) |
︙ | ︙ | |||
145 146 147 148 149 150 151 | ADD_TAG(TAG_DONE, 0) #undef ADD_TAG (*thread)->task = (struct Task *)CreateNewProc(tags.items); if ((*thread)->task == NULL) { free(*thread); | < | | < > | | < | | < | < | < | < > | | 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | ADD_TAG(TAG_DONE, 0) #undef ADD_TAG (*thread)->task = (struct Task *)CreateNewProc(tags.items); if ((*thread)->task == NULL) { free(*thread); return EAGAIN; } } @catch (id e) { free(*thread); @throw e; } @finally { [tags release]; } return 0; } of_thread_t of_thread_current(void) { return of_tlskey_get(threadKey); } int of_thread_join(of_thread_t thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) { ReleaseSemaphore(&thread->semaphore); free(thread); return 0; } @try { if (thread->detached || thread->joinTask != NULL) return EINVAL; if ((thread->joinSigBit = AllocSignal(-1)) == -1) return EAGAIN; thread->joinTask = FindTask(NULL); } @finally { ReleaseSemaphore(&thread->semaphore); } Wait(1ul << thread->joinSigBit); FreeSignal(thread->joinSigBit); assert(thread->done); free(thread); return 0; } int of_thread_detach(of_thread_t thread) { ObtainSemaphore(&thread->semaphore); if (thread->done) free(thread); else thread->detached = true; ReleaseSemaphore(&thread->semaphore); return 0; } void of_thread_set_name(const char *name) { } |