Differences From Artifact [d3d9eb9ec8]:
- File src/platform/windows/thread.m — part of check-in [164475afdb] at 2020-06-14 16:07:41 on branch trunk — Check thread attributes before spawning the thread (user: js, size: 2788) [annotate] [blame] [check-ins using] [more...]
To Artifact [ea501b1747]:
- File
src/platform/windows/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: 2691) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
33 34 35 36 37 38 39 | functionWrapper(struct thread_context *context) { context->function(context->object); free(context); } | < > | < > | < | < | < | < | | | < | | < > | < | < > | | 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 | functionWrapper(struct thread_context *context) { context->function(context->object); free(context); } 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) { DWORD priority = THREAD_PRIORITY_NORMAL; struct thread_context *context; DWORD threadID; if (attr != NULL && attr->priority != 0) { if (attr->priority < -1 || attr->priority > 1) return EINVAL; if (attr->priority < 0) priority = THREAD_PRIORITY_LOWEST + (1.0 + attr->priority) * (THREAD_PRIORITY_NORMAL - THREAD_PRIORITY_LOWEST); else priority = THREAD_PRIORITY_NORMAL + attr->priority * (THREAD_PRIORITY_HIGHEST - THREAD_PRIORITY_NORMAL); } if ((context = malloc(sizeof(*context))) == NULL) return ENOMEM; context->function = function; context->object = object; *thread = CreateThread(NULL, (attr != NULL ? attr->stackSize : 0), (LPTHREAD_START_ROUTINE)functionWrapper, context, 0, &threadID); if (thread == NULL) { int error; switch (GetLastError()) { case ERROR_NOT_ENOUGH_MEMORY: error = ENOMEM; break; case ERROR_ACCESS_DENIED: error = EACCES; break; default: OF_ENSURE(0); } free(context); return error; } if (attr != NULL && attr->priority != 0) OF_ENSURE(!SetThreadPriority(*thread, priority)); return 0; } int of_thread_join(of_thread_t thread) { switch (WaitForSingleObject(thread, INFINITE)) { case WAIT_OBJECT_0: CloseHandle(thread); return 0; case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: return EINVAL; default: OF_ENSURE(0); } default: OF_ENSURE(0); } } int of_thread_detach(of_thread_t thread) { CloseHandle(thread); return 0; } void of_thread_set_name(const char *name) { } |