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