Changeset ee897e4b


Ignore:
Timestamp:
Feb 13, 2017, 5:13:11 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, with_gc
Children:
eafb094
Parents:
db6f06a
Message:

Made some clean-up and removed redundant coroutine state

Location:
src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/concurrency/coroutines

    rdb6f06a ree897e4b  
    7777                "Possible cause is a suspend executed in a member called by a coroutine user rather than by the coroutine main.",
    7878                src->name, src );
    79         assertf( src->last->notHalted,
     79        assertf( src->last->state != Halted,
    8080                "Attempt by coroutine \"%.256s\" (%p) to suspend back to terminated coroutine \"%.256s\" (%p).\n"
    8181                "Possible cause is terminated coroutine's main routine has already returned.",
     
    9898      // not resuming self ?
    9999        if ( src != dst ) {
    100                 assertf( dst->notHalted ,
     100                assertf( dst->state != Halted ,
    101101                        "Attempt by coroutine %.256s (%p) to resume terminated coroutine %.256s (%p).\n"
    102102                        "Possible cause is terminated coroutine's main routine has already returned.",
     
    116116      // not resuming self ?
    117117        if ( src != dst ) {
    118                 assertf( dst->notHalted ,
     118                assertf( dst->state != Halted ,
    119119                        "Attempt by coroutine %.256s (%p) to resume terminated coroutine %.256s (%p).\n"
    120120                        "Possible cause is terminated coroutine's main routine has already returned.",
  • src/libcfa/concurrency/coroutines.c

    rdb6f06a ree897e4b  
    6868        this->errno_ = 0;
    6969        this->state = Start;
    70         this->notHalted = true;
    7170        this->starter = NULL;
    7271        this->last = NULL;
  • src/libcfa/concurrency/invoke.c

    rdb6f06a ree897e4b  
    4848      main( this );
    4949
    50       cor->state = Halt;
    51       cor->notHalted = false;
     50      cor->state = Halted;
    5251
    5352      //Final suspend, should never return
  • src/libcfa/concurrency/invoke.h

    rdb6f06a ree897e4b  
    3939      };
    4040
    41       // struct simple_lock {
    42       //        struct simple_thread_list blocked;
    43       // };
    44 
    4541      struct signal_once {
    4642            volatile bool condition;
     
    5450            void append( struct simple_thread_list *, struct thread * );
    5551            struct thread * pop_head( struct simple_thread_list * );
    56 
    57             // void ?{}(simple_lock * this);
    58             // void ^?{}(simple_lock * this);
    5952
    6053            void ?{}(spinlock * this);
     
    7669      };
    7770
    78       enum coroutine_state { Start, Inactive, Active, Halt, Primed };
     71      enum coroutine_state { Halted, Start, Inactive, Active, Primed };
    7972
    8073      struct coroutine {
     
    8376            int errno_;                         // copy of global UNIX variable errno
    8477            enum coroutine_state state; // current execution status for coroutine
    85             bool notHalted;                   // indicate if execuation state is not halted
    8678            struct coroutine *starter;  // first coroutine to resume this one
    8779            struct coroutine *last;             // last coroutine to resume this one
     
    8981
    9082      struct thread {
    91             struct coroutine c;
    92             signal_once terminated;             // indicate if execuation state is not halted
    93             struct thread * next;
     83            struct coroutine c;           // coroutine body used to store context
     84            struct signal_once terminated;// indicate if execuation state is not halted
     85            struct thread * next;         // instrusive link field for threads
    9486      };
    9587
  • src/libcfa/concurrency/kernel.c

    rdb6f06a ree897e4b  
    119119        this->name = "Main Thread";
    120120        this->errno_ = 0;
    121         this->state = Inactive;
    122         this->notHalted = true;
     121        this->state = Start;
    123122}
    124123
     
    287286        proc_cor_storage.c.state = Active;
    288287      main( &proc_cor_storage );
    289       proc_cor_storage.c.state = Halt;
    290       proc_cor_storage.c.notHalted = false;
     288      proc_cor_storage.c.state = Halted;
    291289
    292290        // Main routine of the core returned, the core is now fully terminated
  • src/libcfa/concurrency/threads.c

    rdb6f06a ree897e4b  
    120120extern "C" {
    121121        void __thread_signal_termination( thread * this ) {
    122                 this->c.state = Halt;
     122                this->c.state = Halted;
    123123                LIB_DEBUG_PRINTF("Thread end : %p\n", this);
    124124                signal( &this->terminated );   
  • src/tests/thread.c

    rdb6f06a ree897e4b  
    44#include <threads>
    55
    6 struct First { thread t; simple_lock* lock; };
    7 struct Second { thread t; simple_lock* lock; };
     6struct First { thread t; signal_once* lock; };
     7struct Second { thread t; signal_once* lock; };
    88
    99DECL_THREAD(First);
    1010DECL_THREAD(Second);
    1111
    12 void ?{}( First * this, simple_lock* lock ) { this->lock = lock; }
    13 void ?{}( Second * this, simple_lock* lock ) { this->lock = lock; }
     12void ?{}( First * this, signal_once* lock ) { this->lock = lock; }
     13void ?{}( Second * this, signal_once* lock ) { this->lock = lock; }
    1414
    1515void main(First* this) {
     
    1818                yield();
    1919        }
    20         unlock(this->lock);
     20        signal(this->lock);
    2121}
    2222
    2323void main(Second* this) {
    24         lock(this->lock);       
     24        wait(this->lock);
    2525        for(int i = 0; i < 10; i++) {
    2626                sout | "Second : Suspend No." | i + 1 | endl;
     
    3131
    3232int main(int argc, char* argv[]) {
    33         simple_lock lock;
     33        signal_once lock;
    3434        sout | "User main begin" | endl;
    3535        {
    36                 // processor p;
     36                processor p;
    3737                {
    3838                        scoped(First)  f = { &lock };
Note: See TracChangeset for help on using the changeset viewer.