Ignore:
Timestamp:
Apr 4, 2019, 3:37:55 PM (3 years ago)
Author:
tdelisle <tdelisle@…>
Branches:
arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
8c01e1b
Parents:
2fabdc02
Message:

Swapped memory storage for context and stack information inside the coroutine implementation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel.cfa

    r2fabdc02 rb2f6113  
    4242//-----------------------------------------------------------------------------
    4343// Kernel storage
    44 KERNEL_STORAGE(cluster,           mainCluster);
    45 KERNEL_STORAGE(processor,         mainProcessor);
    46 KERNEL_STORAGE(thread_desc,       mainThread);
    47 KERNEL_STORAGE(machine_context_t, mainThreadCtx);
     44KERNEL_STORAGE(cluster,         mainCluster);
     45KERNEL_STORAGE(processor,       mainProcessor);
     46KERNEL_STORAGE(thread_desc,     mainThread);
     47KERNEL_STORAGE(__stack_t,       mainThreadCtx);
    4848
    4949cluster     * mainCluster;
     
    5454struct { __dllist_t(cluster) list; __spinlock_t lock; } __cfa_dbg_global_clusters;
    5555}
     56
     57size_t __page_size = 0;
    5658
    5759//-----------------------------------------------------------------------------
     
    6668// Struct to steal stack
    6769struct current_stack_info_t {
    68         machine_context_t ctx;
     70        __stack_t * storage;            // pointer to stack object
    6971        unsigned int size;              // size of stack
    7072        void *base;                             // base of stack
    71         void *storage;                  // pointer to stack
    7273        void *limit;                    // stack grows towards stack limit
    7374        void *context;                  // address of cfa_context_t
    74         void *top;                              // address of top of storage
    7575};
    7676
    7777void ?{}( current_stack_info_t & this ) {
    78         CtxGet( this.ctx );
    79         this.base = this.ctx.FP;
    80         this.storage = this.ctx.SP;
     78        __stack_context_t ctx;
     79        CtxGet( ctx );
     80        this.base = ctx.FP;
    8181
    8282        rlimit r;
     
    8686        this.limit = (void *)(((intptr_t)this.base) - this.size);
    8787        this.context = &storage_mainThreadCtx;
    88         this.top = this.base;
    8988}
    9089
    9190//-----------------------------------------------------------------------------
    9291// Main thread construction
    93 void ?{}( coStack_t & this, current_stack_info_t * info) with( this ) {
    94         size      = info->size;
    95         storage   = info->storage;
    96         limit     = info->limit;
    97         base      = info->base;
    98         context   = info->context;
    99         top       = info->top;
    100         userStack = true;
    101 }
    10292
    10393void ?{}( coroutine_desc & this, current_stack_info_t * info) with( this ) {
    104         stack{ info };
     94        context.errno_ = 0;
     95        stack.storage = info->storage;
     96        stack.userStack = true;
     97        with(*stack.storage) {
     98                size      = info->size;
     99                limit     = info->limit;
     100                base      = info->base;
     101        }
    105102        name = "Main Thread";
    106         errno_ = 0;
    107103        state = Start;
    108104        starter = NULL;
     105        last = NULL;
     106        cancellation = NULL;
    109107}
    110108
     
    312310        // to waste the perfectly valid stack create by pthread.
    313311        current_stack_info_t info;
    314         machine_context_t ctx;
    315         info.context = &ctx;
     312        __stack_t ctx;
     313        info.storage = &ctx;
    316314        (proc->runner){ proc, &info };
    317315
    318         __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.base);
     316        __cfaabi_dbg_print_safe("Coroutine : created stack %p\n", get_coroutine(proc->runner)->stack.storage);
    319317
    320318        //Set global state
     
    353351        verify( ! kernelTLS.preemption_state.enabled );
    354352
    355         create_stack(&dst->stack, dst->stack.size);
     353        __stack_prepare( &dst->stack, 65000 );
    356354        CtxStart(&this->runner, CtxInvokeCoroutine);
    357355
     
    372370
    373371        // context switch to specified coroutine
    374         assert( src->stack.context );
    375         CtxSwitch( src->stack.context, dst->stack.context );
     372        CtxSwitch( &src->context, &dst->context );
    376373        // when CtxSwitch returns we are back in the src coroutine
    377374
     
    545542        __cfaabi_dbg_print_safe("Kernel : Starting\n");
    546543
     544        __page_size = sysconf( _SC_PAGESIZE );
     545
    547546        __cfa_dbg_global_clusters.list{ __get };
    548547        __cfa_dbg_global_clusters.lock{};
     
    559558        mainThread = (thread_desc *)&storage_mainThread;
    560559        current_stack_info_t info;
     560        info.storage = (__stack_t*)&storage_mainThreadCtx;
    561561        (*mainThread){ &info };
    562562
Note: See TracChangeset for help on using the changeset viewer.