Changeset 827d73f in mainline for uspace/lib/libc/generic/fibril.c


Ignore:
Timestamp:
2010-02-12T14:09:22Z (14 years ago)
Author:
Lukas Mejdrech <lukasmejdrech@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a70bda4
Parents:
918e9910 (diff), e70edd1 (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.
Message:

Merged the actual head

File:
1 edited

Legend:

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

    r918e9910 r827d73f  
    4141#include <unistd.h>
    4242#include <stdio.h>
     43#include <arch/barrier.h>
    4344#include <libarch/faddr.h>
    4445#include <futex.h>
     
    133134int fibril_switch(fibril_switch_type_t stype)
    134135{
    135         fibril_t *srcf, *dstf;
    136136        int retval = 0;
    137137       
    138138        futex_down(&fibril_futex);
    139 
     139       
    140140        if (stype == FIBRIL_PREEMPT && list_empty(&ready_list))
    141141                goto ret_0;
    142 
     142       
    143143        if (stype == FIBRIL_FROM_MANAGER) {
    144                 if (list_empty(&ready_list) && list_empty(&serialized_list))
     144                if ((list_empty(&ready_list)) && (list_empty(&serialized_list)))
    145145                        goto ret_0;
     146               
    146147                /*
    147148                 * Do not preempt if there is not enough threads to run the
    148149                 * ready fibrils which are not serialized.
    149150                 */
    150                 if (list_empty(&serialized_list) &&
    151                     threads_in_manager <= serialized_threads) {
     151                if ((list_empty(&serialized_list)) &&
     152                    (threads_in_manager <= serialized_threads)) {
    152153                        goto ret_0;
    153154                }
    154155        }
     156       
    155157        /* If we are going to manager and none exists, create it */
    156         if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {
     158        if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) {
    157159                while (list_empty(&manager_list)) {
    158160                        futex_up(&fibril_futex);
     
    162164        }
    163165       
    164         srcf = __tcb_get()->fibril_data;
     166        fibril_t *srcf = __tcb_get()->fibril_data;
    165167        if (stype != FIBRIL_FROM_DEAD) {
     168               
    166169                /* Save current state */
    167170                if (!context_save(&srcf->ctx)) {
    168171                        if (serialization_count)
    169172                                srcf->flags &= ~FIBRIL_SERIALIZED;
     173                       
    170174                        if (srcf->clean_after_me) {
    171175                                /*
     
    173177                                 * restored context here.
    174178                                 */
    175                                 void *stack = srcf->clean_after_me->stack; 
     179                                void *stack = srcf->clean_after_me->stack;
    176180                                if (stack) {
    177181                                        /*
     
    188192                                srcf->clean_after_me = NULL;
    189193                        }
     194                       
    190195                        return 1;       /* futex_up already done here */
    191196                }
    192 
     197               
    193198                /* Save myself to the correct run list */
    194199                if (stype == FIBRIL_PREEMPT)
     
    197202                        list_append(&srcf->link, &manager_list);
    198203                        threads_in_manager--;
    199                 } else {       
     204                } else {
    200205                        /*
    201206                         * If stype == FIBRIL_TO_MANAGER, don't put ourselves to
     
    206211        }
    207212       
     213        /* Avoid srcf being clobbered by context_save() */
     214        srcf = __tcb_get()->fibril_data;
     215       
    208216        /* Choose a new fibril to run */
    209         if (stype == FIBRIL_TO_MANAGER || stype == FIBRIL_FROM_DEAD) {
     217        fibril_t *dstf;
     218        if ((stype == FIBRIL_TO_MANAGER) || (stype == FIBRIL_FROM_DEAD)) {
    210219                dstf = list_get_instance(manager_list.next, fibril_t, link);
    211220                if (serialization_count && stype == FIBRIL_TO_MANAGER) {
     
    214223                }
    215224                threads_in_manager++;
    216 
     225               
    217226                if (stype == FIBRIL_FROM_DEAD)
    218227                        dstf->clean_after_me = srcf;
     
    228237        }
    229238        list_remove(&dstf->link);
    230 
     239       
    231240        futex_up(&fibril_futex);
    232241        context_restore(&dstf->ctx);
    233242        /* not reached */
    234 
     243       
    235244ret_0:
    236245        futex_up(&fibril_futex);
Note: See TracChangeset for help on using the changeset viewer.