Changeset 116d3f6f in mainline for uspace/lib/libc/generic/fibril.c


Ignore:
Timestamp:
2007-10-03T06:55:56Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
18525c5
Parents:
5b5d25f
Message:

Rename fibril_schedule_next_adv() to fibril_switch(). Rename
fibril_schedule_next() to fibril_yield(). Some fibril structures could be
uninitialized, set them to zero in fibril_setup(). For some fibrils, the stack
member can be NULL (e.g. every thread's first/main fibril); don't do free on
these stacks when cleaning up after a dead fibril.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libc/generic/fibril.c

    r5b5d25f r116d3f6f  
    7676                return NULL;
    7777
    78         f = malloc(sizeof(*f));
     78        f = malloc(sizeof(fibril_t));
    7979        if (!f) {
    8080                __free_tls(tcb);
     
    8585        f->tcb = tcb;
    8686
     87        f->func = NULL;
     88        f->arg = NULL;
     89        f->stack = NULL;
     90        f->clean_after_me = NULL;
     91        f->retval = 0;
     92        f->flags = 0;
     93
    8794        return f;
    8895}
     
    107114        f->retval = f->func(f->arg);
    108115
    109         fibril_schedule_next_adv(FIBRIL_FROM_DEAD);
     116        fibril_switch(FIBRIL_FROM_DEAD);
    110117        /* not reached */
    111118}
    112119
    113 /** Schedule next fibril.
     120/** Switch from the current fibril.
    114121 *
    115122 * If calling with FIBRIL_TO_MANAGER parameter, the async_futex should be
     
    122129 *                      return 1 otherwise.
    123130 */
    124 int fibril_schedule_next_adv(fibril_switch_type_t stype)
     131int fibril_switch(fibril_switch_type_t stype)
    125132{
    126133        fibril_t *srcf, *dstf;
     
    139146                 * managers.
    140147                 */
    141                 if (list_empty(&serialized_list) && fibrils_in_manager <=
    142                     serialized_fibrils) {
     148                if (list_empty(&serialized_list) &&
     149                    fibrils_in_manager <= serialized_fibrils) {
    143150                        goto ret_0;
    144151                }
     
    164171                                 * restored context here.
    165172                                 */
    166                                 free(srcf->clean_after_me->stack);
     173                                void *stack = srcf->clean_after_me->stack;
     174                                if (stack) {
     175                                        /*
     176                                         * This check is necessary because a
     177                                         * thread could have exited like a
     178                                         * normal fibril using the
     179                                         * FIBRIL_FROM_DEAD switch type. In that
     180                                         * case, its fibril will not have the
     181                                         * stack member filled.
     182                                         */
     183                                        free(stack);
     184                                }
    167185                                fibril_teardown(srcf->clean_after_me);
    168186                                srcf->clean_after_me = NULL;
     
    185203                }
    186204        }
    187 
     205       
    188206        /* Choose a new fibril to run */
    189207        if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {
     
    195213                fibrils_in_manager++;
    196214
    197                 if (stype == FIBRIL_FROM_DEAD)
     215                if (stype == FIBRIL_FROM_DEAD) 
    198216                        dstf->clean_after_me = srcf;
    199217        } else {
     
    234252        f->stack = (char *) malloc(FIBRIL_INITIAL_STACK_PAGES_NO *
    235253            getpagesize());
    236 
    237254        if (!f->stack) {
    238255                fibril_teardown(f);
    239256                return 0;
    240257        }
    241 
     258       
     259        f->func = func;
    242260        f->arg = arg;
    243         f->func = func;
    244         f->clean_after_me = NULL;
    245         f->retval = 0;
    246         f->flags = 0;
    247261
    248262        context_save(&f->ctx);
Note: See TracChangeset for help on using the changeset viewer.