Changeset ebb1489 in mainline for uspace/lib/c/generic/thread/thread.c
- Timestamp:
- 2024-10-13T08:23:40Z (8 weeks ago)
- Children:
- 0472cf17
- Parents:
- 2a0c827c (diff), b3b79981 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- boba-buba <120932204+boba-buba@…> (2024-10-13 08:23:40)
- git-committer:
- GitHub <noreply@…> (2024-10-13 08:23:40)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/thread/thread.c
r2a0c827c rebb1489 37 37 #include <stdlib.h> 38 38 #include <libarch/faddr.h> 39 #include <abi/proc/uarg.h>40 39 #include <fibril.h> 41 40 #include <stack.h> … … 54 53 * and exit when thread returns back. 55 54 * 56 * @param uarg Pointer to userspace argument structure.55 * @param arg Fibril pointer. 57 56 * 58 57 */ 59 void __thread_main(uspace_arg_t *uarg)58 static void __thread_main(void *arg) 60 59 { 60 fibril_t *fibril = arg; 61 61 62 assert(!__tcb_is_set()); 62 63 fibril_t *fibril = uarg->uspace_thread_arg;64 63 assert(fibril); 65 64 66 65 __tcb_set(fibril->tcb); 67 66 68 uarg->uspace_thread_function(fibril->arg);67 fibril->func(fibril->arg); 69 68 /* 70 69 * XXX: we cannot free the userspace stack while running on it … … 90 89 * @return Zero on success or a code from @ref errno.h on failure. 91 90 */ 92 errno_t thread_create(void (*function)(void *), void *arg, const char *name, 93 thread_id_t *tid) 91 errno_t thread_create(errno_t (*func)(void *), void *arg, const char *name) 94 92 { 95 uspace_arg_t *uarg = calloc(1, sizeof(uspace_arg_t));96 if (! uarg)93 fibril_t *fibril = fibril_alloc(); 94 if (!fibril) 97 95 return ENOMEM; 98 96 99 fibril_t *fibril = fibril_alloc(); 100 if (!fibril) { 101 free(uarg); 102 return ENOMEM; 103 } 97 fibril->func = func; 98 fibril->arg = arg; 104 99 105 100 size_t stack_size = stack_size_get(); … … 109 104 if (stack == AS_MAP_FAILED) { 110 105 fibril_teardown(fibril); 111 free(uarg);112 106 return ENOMEM; 113 107 } 114 108 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; 109 uintptr_t sp = arch_thread_prepare(stack, stack_size, __thread_main, 110 fibril); 122 111 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); 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)); 125 115 126 116 if (rc != EOK) { … … 130 120 */ 131 121 as_area_destroy(stack); 132 free(uarg);133 122 } 134 123 … … 148 137 while (true) 149 138 ; 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 {160 139 } 161 140
Note:
See TracChangeset
for help on using the changeset viewer.