Changeset d50f3e5 in mainline for uspace/lib/c
- Timestamp:
- 2025-03-09T20:06:24Z (11 months ago)
- Children:
- 53e652d
- Parents:
- af28af6
- git-author:
- Matěj Volf <git@…> (2025-03-09 20:05:51)
- git-committer:
- Matěj Volf <git@…> (2025-03-09 20:06:24)
- Location:
- uspace/lib/c
- Files:
-
- 1 deleted
- 6 edited
-
generic/libc.c (modified) (1 diff)
-
generic/private/fibril.h (modified) (2 diffs)
-
generic/thread/fibril.c (modified) (4 diffs)
-
include/fibril.h (modified) (1 diff)
-
meson.build (modified) (1 diff)
-
test/fibril/exit_hook.c (deleted)
-
test/main.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/libc.c
raf28af6 rd50f3e5 173 173 void __libc_exit(int status) 174 174 { 175 fibril_run_exit_hooks(&main_fibril);176 177 175 /* 178 176 * GCC extension __attribute__((destructor)), -
uspace/lib/c/generic/private/fibril.h
raf28af6 rd50f3e5 70 70 fibril_owner_info_t *waits_for; 71 71 fibril_event_t *sleep_event; 72 73 list_t exit_hooks;74 72 }; 75 76 typedef struct {77 link_t link;78 void (*func)(void);79 } fibril_hook_t;80 73 81 74 extern fibril_t *fibril_alloc(void); … … 93 86 extern errno_t fibril_ipc_wait(ipc_call_t *, const struct timespec *); 94 87 extern void fibril_ipc_poke(void); 95 96 extern void fibril_run_exit_hooks(fibril_t *);97 88 98 89 /** -
uspace/lib/c/generic/thread/fibril.c
raf28af6 rd50f3e5 185 185 void fibril_setup(fibril_t *f) 186 186 { 187 list_initialize(&f->exit_hooks);188 187 futex_lock(&fibril_futex); 189 188 list_append(&f->all_link, &fibril_list); … … 846 845 } 847 846 848 void fibril_run_exit_hooks(fibril_t *f)849 {850 list_foreach_safe(f->exit_hooks, cur, _next) {851 fibril_hook_t *hook = list_get_instance(cur, fibril_hook_t, link);852 list_remove(cur);853 hook->func();854 free(hook);855 }856 }857 858 847 /** 859 848 * Exit a fibril. Never returns. … … 865 854 // TODO: implement fibril_join() and remember retval 866 855 (void) retval; 867 868 fibril_run_exit_hooks(fibril_self());869 856 870 857 fibril_t *f = _ready_list_pop_nonblocking(false); … … 931 918 } 932 919 933 errno_t fibril_add_exit_hook(void (*hook)(void))934 {935 fibril_hook_t *h = malloc(sizeof(fibril_hook_t));936 if (!h)937 return ENOMEM;938 939 DPRINTF("adding exit hook: function %p (fibril_hook_t structure at %p)\n", hook, h);940 941 h->func = hook;942 list_append(&h->link, &fibril_self()->exit_hooks);943 return EOK;944 }945 946 920 errno_t fibril_ipc_wait(ipc_call_t *call, const struct timespec *expires) 947 921 { -
uspace/lib/c/include/fibril.h
raf28af6 rd50f3e5 74 74 extern __noreturn void fibril_exit(long); 75 75 76 /** Add a function to be called after fibril exits, just before it is destroyed */77 extern errno_t fibril_add_exit_hook(void (*)(void));78 79 76 __HELENOS_DECLS_END; 80 77 -
uspace/lib/c/meson.build
raf28af6 rd50f3e5 177 177 'test/double_to_str.c', 178 178 'test/fibril/timer.c', 179 'test/fibril/exit_hook.c',180 179 'test/getopt.c', 181 180 'test/gsort.c', -
uspace/lib/c/test/main.c
raf28af6 rd50f3e5 38 38 PCUT_IMPORT(double_to_str); 39 39 PCUT_IMPORT(fibril_timer); 40 PCUT_IMPORT(fibril_exit_hook);41 40 PCUT_IMPORT(getopt); 42 41 PCUT_IMPORT(gsort);
Note:
See TracChangeset
for help on using the changeset viewer.
