Changeset 6a57b93 in mainline


Ignore:
Timestamp:
2025-03-05T21:40:21Z (4 days ago)
Author:
Matěj Volf <git@…>
Children:
5208709
Parents:
df2b4ce7
git-author:
Matěj Volf <git@…> (2025-01-17 14:14:59)
git-committer:
Matěj Volf <git@…> (2025-03-05 21:40:21)
Message:

Add fibril exit hook

Location:
uspace/lib/c
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/private/fibril.h

    rdf2b4ce7 r6a57b93  
    7070        fibril_owner_info_t *waits_for;
    7171        fibril_event_t *sleep_event;
     72
     73        list_t exit_hooks;
    7274};
     75
     76typedef struct {
     77        link_t link;
     78        void (*func)(void);
     79} fibril_hook_t;
    7380
    7481extern fibril_t *fibril_alloc(void);
  • uspace/lib/c/generic/thread/fibril.c

    rdf2b4ce7 r6a57b93  
    198198        if (fibril->is_freeable) {
    199199                tls_free(fibril->tcb);
     200                list_foreach_safe(fibril->exit_hooks, cur, _next) {
     201                        fibril_hook_t *hook = list_get_instance(cur, fibril_hook_t, link);
     202                        free(hook);
     203                }
    200204                free(fibril);
    201205        }
     
    562566        fibril->arg = arg;
    563567
     568        list_initialize(&fibril->exit_hooks);
     569
    564570        context_create_t sctx = {
    565571                .fn = _fibril_main,
     
    855861        (void) retval;
    856862
     863        list_foreach(fibril_self()->exit_hooks, link, fibril_hook_t, hook) {
     864                hook->func();
     865        }
     866
    857867        fibril_t *f = _ready_list_pop_nonblocking(false);
    858868        if (!f)
     
    918928}
    919929
     930errno_t fibril_add_exit_hook(void (*hook)(void))
     931{
     932        fibril_hook_t *h = malloc(sizeof(fibril_hook_t));
     933        if (!h)
     934                return ENOMEM;
     935
     936        h->func = hook;
     937        list_append(&h->link, &fibril_self()->exit_hooks);
     938        return EOK;
     939}
     940
    920941errno_t fibril_ipc_wait(ipc_call_t *call, const struct timespec *expires)
    921942{
  • uspace/lib/c/include/fibril.h

    rdf2b4ce7 r6a57b93  
    7474extern __noreturn void fibril_exit(long);
    7575
     76/** Add a function to be called after fibril exits, just before it is destroyed */
     77extern errno_t fibril_add_exit_hook(void (*)(void));
     78
    7679__HELENOS_DECLS_END;
    7780
Note: See TracChangeset for help on using the changeset viewer.