Changeset 3fcea34 in mainline for uspace/lib/c/generic
- Timestamp:
- 2024-09-20T12:16:28Z (10 months ago)
- Branches:
- master
- Children:
- d3109ff
- Parents:
- 2cf8f994
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-20 11:42:13)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-20 12:16:28)
- Location:
- uspace/lib/c/generic
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/private/fibril.h
r2cf8f994 r3fcea34 33 33 #include <context.h> 34 34 #include <tls.h> 35 #include <abi/proc/uarg.h>36 35 #include <fibril.h> 37 36 #include <ipc/common.h> … … 50 49 context_t ctx; 51 50 52 uspace_arg_t uarg;53 51 link_t link; 54 52 void *stack; -
uspace/lib/c/generic/private/thread.h
r2cf8f994 r3fcea34 37 37 38 38 #include <time.h> 39 #include <abi/proc/uarg.h>40 39 #include <libarch/thread.h> 41 40 #include <abi/proc/thread.h> 42 41 43 42 extern void __thread_entry(void); 44 extern void __thread_main(uspace_arg_t *);45 43 46 extern errno_t thread_create(void (*)(void *), void *, const char *, 47 thread_id_t *); 44 extern errno_t thread_create(errno_t (*)(void *), void *, const char *); 48 45 extern void thread_exit(int) __attribute__((noreturn)); 49 extern void thread_detach(thread_id_t);50 46 extern thread_id_t thread_get_id(void); 51 47 extern void thread_usleep(usec_t); -
uspace/lib/c/generic/thread/fibril.c
r2cf8f994 r3fcea34 781 781 } 782 782 783 static void_runner_fn(void *arg)783 static errno_t _runner_fn(void *arg) 784 784 { 785 785 _helper_fibril_fn(arg); 786 return EOK; 786 787 } 787 788 … … 808 809 809 810 for (int i = 0; i < n; i++) { 810 thread_id_t tid; 811 rc = thread_create(_runner_fn, NULL, "fibril runner", &tid); 811 rc = thread_create(_runner_fn, NULL, "fibril runner"); 812 812 if (rc != EOK) 813 813 return i; 814 thread_detach(tid);815 814 } 816 815 -
uspace/lib/c/generic/thread/thread.c
r2cf8f994 r3fcea34 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.