| 125 | } |
| 126 | |
| 127 | int cbm_thread_create(cbm_thread_t *t, size_t stack_size, void *(*fn)(void *), void *arg) { |
| 128 | if (stack_size == 0) { |
| 129 | stack_size = cbm_thread_default_stack_size(); |
| 130 | } else { |
| 131 | stack_size = cbm_thread_stack_floor(stack_size); |
| 132 | } |
| 133 | win_thread_arg_t *a = (win_thread_arg_t *)malloc(sizeof(win_thread_arg_t)); |
| 134 | if (!a) { |
| 135 | return CBM_NOT_FOUND; |
| 136 | } |
| 137 | a->fn = fn; |
| 138 | a->arg = arg; |
| 139 | t->handle = CreateThread(NULL, stack_size, win_thread_wrapper, a, 0, NULL); |
| 140 | if (!t->handle) { |
| 141 | free(a); |
| 142 | return CBM_NOT_FOUND; |
| 143 | } |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | int cbm_thread_join(cbm_thread_t *t) { |
| 148 | if (WaitForSingleObject(t->handle, INFINITE) != WAIT_OBJECT_0) { |