Differences From Artifact [022f3487c0]:
- File src/platform/amiga/condition.m — part of check-in [109db78ecd] at 2020-02-29 14:49:23 on branch trunk — Move platform specific files into a subdirectory (user: js, size: 5392) [annotate] [blame] [check-ins using] [more...]
To Artifact [e63442b656]:
- File
src/platform/amiga/condition.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: 5228) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
23 24 25 26 27 28 29 | #include <proto/exec.h> #include <devices/timer.h> #ifndef OF_AMIGAOS4 # include <clib/alib_protos.h> #endif | < > | < > | | < > | | < > < > | | < | < | | | | < | < | < > < > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | #include <proto/exec.h> #include <devices/timer.h> #ifndef OF_AMIGAOS4 # include <clib/alib_protos.h> #endif int of_condition_new(of_condition_t *condition) { condition->waitingTasks = NULL; return 0; } int of_condition_signal(of_condition_t *condition) { Forbid(); @try { if (condition->waitingTasks == NULL) return 0; Signal(condition->waitingTasks->task, (1ul << condition->waitingTasks->sigBit)); condition->waitingTasks = condition->waitingTasks->next; } @finally { Permit(); } return 0; } int of_condition_broadcast(of_condition_t *condition) { Forbid(); @try { if (condition->waitingTasks == NULL) return 0; while (condition->waitingTasks != NULL) { Signal(condition->waitingTasks->task, (1ul << condition->waitingTasks->sigBit)); condition->waitingTasks = condition->waitingTasks->next; } } @finally { Permit(); } return 0; } int of_condition_wait(of_condition_t *condition, of_mutex_t *mutex) { ULONG signalMask = 0; return of_condition_wait_or_signal(condition, mutex, &signalMask); } int of_condition_wait_or_signal(of_condition_t *condition, of_mutex_t *mutex, ULONG *signalMask) { struct of_condition_waiting_task waitingTask = { .task = FindTask(NULL), .sigBit = AllocSignal(-1) }; int error = 0; ULONG mask; if (waitingTask.sigBit == -1) return EAGAIN; Forbid(); if ((error = of_mutex_unlock(mutex)) != 0) { FreeSignal(waitingTask.sigBit); return error; } waitingTask.next = condition->waitingTasks; condition->waitingTasks = &waitingTask; mask = Wait((1ul << waitingTask.sigBit) | *signalMask); if (mask & (1ul << waitingTask.sigBit) || (*signalMask &= mask)) error = of_mutex_lock(mutex); else /* * This should not happen - it means something interrupted the * Wait(), so the best we can do is return EINTR. */ error = EINTR; FreeSignal(waitingTask.sigBit); Permit(); return error; } int of_condition_timed_wait(of_condition_t *condition, of_mutex_t *mutex, of_time_interval_t timeout) { ULONG signalMask = 0; return of_condition_timed_wait_or_signal(condition, mutex, timeout, &signalMask); } int of_condition_timed_wait_or_signal(of_condition_t *condition, of_mutex_t *mutex, of_time_interval_t timeout, ULONG *signalMask) { struct of_condition_waiting_task waitingTask = { .task = FindTask(NULL), .sigBit = AllocSignal(-1) }; |
︙ | ︙ | |||
178 179 180 181 182 183 184 185 | #else .tr_time = { .tv_sec = (ULONG)timeout, .tv_micro = (timeout - request.tr_time.tv_sec) * 1000000 #endif } }; ULONG mask; | > < | | | | | < | | < | < < < < < < | < > | < | < | | 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 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | #else .tr_time = { .tv_sec = (ULONG)timeout, .tv_micro = (timeout - request.tr_time.tv_sec) * 1000000 #endif } }; int error = 0; ULONG mask; NewList(&port.mp_MsgList); if (waitingTask.sigBit == -1 || port.mp_SigBit == -1) { error = EAGAIN; goto fail; } if (OpenDevice("timer.device", UNIT_MICROHZ, (struct IORequest *)&request, 0) != 0) { error = EAGAIN; goto fail; } Forbid(); if ((error = of_mutex_unlock(mutex)) != 0) { Permit(); goto fail; } waitingTask.next = condition->waitingTasks; condition->waitingTasks = &waitingTask; SendIO((struct IORequest *)&request); mask = Wait((1ul << waitingTask.sigBit) | (1ul << port.mp_SigBit) | *signalMask); if (mask & (1ul << waitingTask.sigBit) || (*signalMask &= mask)) error = of_mutex_lock(mutex); else if (mask & (1ul << port.mp_SigBit)) error = ETIMEDOUT; else /* * This should not happen - it means something interrupted the * Wait(), so the best we can do is return EINTR. */ error = EINTR; condition->waitingTasks = waitingTask.next; if (!CheckIO((struct IORequest *)&request)) { AbortIO((struct IORequest *)&request); WaitIO((struct IORequest *)&request); } CloseDevice((struct IORequest *)&request); Permit(); fail: if (waitingTask.sigBit != -1) FreeSignal(waitingTask.sigBit); if (port.mp_SigBit != -1) FreeSignal(port.mp_SigBit); return error; } int of_condition_free(of_condition_t *condition) { Forbid(); @try { if (condition->waitingTasks != NULL) return EBUSY; } @finally { Permit(); } return 0; } |