Ignore:
Timestamp:
Oct 30, 2020, 12:01:12 PM (3 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
4ae78c1
Parents:
7ee8153
Message:

Changed park/unpark ticket to be -1,0,1 instead of 0,1,2 because it's more natural.
Also added defines in kernel_private.h to avoid these magic numbers

Location:
libcfa/src/concurrency
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/invoke.h

    r7ee8153 r6a77224  
    157157
    158158                // current execution status for coroutine
     159                // Possible values are:
     160                //    - TICKET_BLOCKED (-1) thread is blocked
     161                //    - TICKET_RUNNING ( 0) thread is running
     162                //    - TICKET_UNBLOCK ( 1) thread should ignore next block
    159163                volatile int ticket;
    160164                enum __Coroutine_State state:8;
  • libcfa/src/concurrency/io/setup.cfa

    r7ee8153 r6a77224  
    250250                                        // Fixup the thread state
    251251                                        thrd.state = Blocked;
    252                                         thrd.ticket = 0;
     252                                        thrd.ticket = TICKET_BLOCKED;
    253253                                        thrd.preempted = __NO_PREEMPTION;
    254254
  • libcfa/src/concurrency/kernel.cfa

    r7ee8153 r6a77224  
    299299                int old_ticket = __atomic_fetch_sub(&thrd_dst->ticket, 1, __ATOMIC_SEQ_CST);
    300300                switch(old_ticket) {
    301                         case 1:
     301                        case TICKET_RUNNING:
    302302                                // This is case 1, the regular case, nothing more is needed
    303303                                break RUNNING;
    304                         case 2:
     304                        case TICKET_UNBLOCK:
    305305                                // This is case 2, the racy case, someone tried to run this thread before it finished blocking
    306306                                // In this case, just run it again.
     
    410410        int old_ticket = __atomic_fetch_add(&thrd->ticket, 1, __ATOMIC_SEQ_CST);
    411411        switch(old_ticket) {
    412                 case 1:
     412                case TICKET_RUNNING:
    413413                        // Wake won the race, the thread will reschedule/rerun itself
    414414                        break;
    415                 case 0:
     415                case TICKET_BLOCKED:
    416416                        /* paranoid */ verify( ! thrd->preempted != __NO_PREEMPTION );
    417417                        /* paranoid */ verify( thrd->state == Blocked );
  • libcfa/src/concurrency/kernel/startup.cfa

    r7ee8153 r6a77224  
    441441
    442442static void ?{}( $thread & this, current_stack_info_t * info) with( this ) {
    443         ticket = 1;
     443        ticket = TICKET_RUNNING;
    444444        state = Start;
    445445        self_cor{ info };
  • libcfa/src/concurrency/kernel_private.hfa

    r7ee8153 r6a77224  
    6565// KERNEL ONLY unpark with out disabling interrupts
    6666void __unpark( struct __processor_id_t *, $thread * thrd );
     67
     68#define TICKET_BLOCKED (-1) // thread is blocked
     69#define TICKET_RUNNING ( 0) // thread is running
     70#define TICKET_UNBLOCK ( 1) // thread should ignore next block
    6771
    6872static inline bool __post(single_sem & this, struct __processor_id_t * id) {
  • libcfa/src/concurrency/thread.cfa

    r7ee8153 r6a77224  
    2929        context{ 0p, 0p };
    3030        self_cor{ name, storage, storageSize };
    31         ticket = 1;
     31        ticket = TICKET_RUNNING;
    3232        state = Start;
    3333        preempted = __NO_PREEMPTION;
Note: See TracChangeset for help on using the changeset viewer.