@@ -35,32 +35,30 @@ context->function(context->object); free(context); } -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) { DWORD priority = THREAD_PRIORITY_NORMAL; struct thread_context *context; DWORD threadID; 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; if (attr->priority < 0) priority = THREAD_PRIORITY_LOWEST + (1.0 + attr->priority) * (THREAD_PRIORITY_NORMAL - THREAD_PRIORITY_LOWEST); @@ -68,73 +66,69 @@ priority = THREAD_PRIORITY_NORMAL + attr->priority * (THREAD_PRIORITY_HIGHEST - THREAD_PRIORITY_NORMAL); } - if ((context = malloc(sizeof(*context))) == NULL) { - errno = ENOMEM; - return false; - } + 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 errNo; + int error; switch (GetLastError()) { case ERROR_NOT_ENOUGH_MEMORY: - errNo = ENOMEM; + error = ENOMEM; break; case ERROR_ACCESS_DENIED: - errNo = EACCES; + error = EACCES; break; default: OF_ENSURE(0); } free(context); - errno = errNo; - return false; + return error; } if (attr != NULL && attr->priority != 0) OF_ENSURE(!SetThreadPriority(*thread, priority)); - return true; + return 0; } -bool +int of_thread_join(of_thread_t thread) { switch (WaitForSingleObject(thread, INFINITE)) { case WAIT_OBJECT_0: CloseHandle(thread); - return true; + return 0; case WAIT_FAILED: switch (GetLastError()) { case ERROR_INVALID_HANDLE: - errno = EINVAL; - return false; + return EINVAL; default: OF_ENSURE(0); } default: OF_ENSURE(0); } } -bool +int of_thread_detach(of_thread_t thread) { CloseHandle(thread); - return true; + return 0; } void of_thread_set_name(const char *name) { }