Changes in uspace/lib/c/generic/thread/thread.c [3fcea34:bd41ac52] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/thread/thread.c
r3fcea34 rbd41ac52 37 37 #include <stdlib.h> 38 38 #include <libarch/faddr.h> 39 #include <abi/proc/uarg.h> 39 40 #include <fibril.h> 40 41 #include <stack.h> … … 53 54 * and exit when thread returns back. 54 55 * 55 * @param arg Fibril pointer. 56 * 57 */ 58 static void __thread_main(void *arg) 59 { 60 fibril_t *fibril = arg; 61 56 * @param uarg Pointer to userspace argument structure. 57 * 58 */ 59 void __thread_main(uspace_arg_t *uarg) 60 { 62 61 assert(!__tcb_is_set()); 62 63 fibril_t *fibril = uarg->uspace_thread_arg; 63 64 assert(fibril); 64 65 65 66 __tcb_set(fibril->tcb); 66 67 67 fibril->func(fibril->arg);68 uarg->uspace_thread_function(fibril->arg); 68 69 /* 69 70 * XXX: we cannot free the userspace stack while running on it … … 89 90 * @return Zero on success or a code from @ref errno.h on failure. 90 91 */ 91 errno_t thread_create(errno_t (*func)(void *), void *arg, const char *name) 92 { 92 errno_t thread_create(void (*function)(void *), void *arg, const char *name, 93 thread_id_t *tid) 94 { 95 uspace_arg_t *uarg = calloc(1, sizeof(uspace_arg_t)); 96 if (!uarg) 97 return ENOMEM; 98 93 99 fibril_t *fibril = fibril_alloc(); 94 if (!fibril) 100 if (!fibril) { 101 free(uarg); 95 102 return ENOMEM; 96 97 fibril->func = func; 98 fibril->arg = arg; 103 } 99 104 100 105 size_t stack_size = stack_size_get(); … … 104 109 if (stack == AS_MAP_FAILED) { 105 110 fibril_teardown(fibril); 111 free(uarg); 106 112 return ENOMEM; 107 113 } 108 114 109 uintptr_t sp = arch_thread_prepare(stack, stack_size, __thread_main, 110 fibril); 111 112 errno_t rc = (errno_t) __SYSCALL4(SYS_THREAD_CREATE, 113 (sysarg_t) FADDR(__thread_entry), sp, 114 (sysarg_t) name, (sysarg_t) str_size(name)); 115 fibril->arg = arg; 116 uarg->uspace_entry = (void *) FADDR(__thread_entry); 117 uarg->uspace_stack = stack; 118 uarg->uspace_stack_size = stack_size; 119 uarg->uspace_thread_function = function; 120 uarg->uspace_thread_arg = fibril; 121 uarg->uspace_uarg = uarg; 122 123 errno_t rc = (errno_t) __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg, 124 (sysarg_t) name, (sysarg_t) str_size(name), (sysarg_t) tid); 115 125 116 126 if (rc != EOK) { … … 120 130 */ 121 131 as_area_destroy(stack); 132 free(uarg); 122 133 } 123 134 … … 137 148 while (true) 138 149 ; 150 } 151 152 /** Detach thread. 153 * 154 * Currently not implemented. 155 * 156 * @param thread TID. 157 */ 158 void thread_detach(thread_id_t thread) 159 { 139 160 } 140 161
Note:
See TracChangeset
for help on using the changeset viewer.