Ignore:
Timestamp:
Feb 13, 2020, 4:18:07 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
50b8885
Parents:
9f575ea
Message:

Added park/unpark primitives thread and removed BlockInternal?.
Converted monitors to use park unpark.
Intrusive Queue now mark next field when thread is inside queue.
Added several asserts to kernel and monitor.
Added a few tests for park and unpark.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel_private.hfa

    r9f575ea r3381ed7  
    3232
    3333void ScheduleThread( thread_desc * ) __attribute__((nonnull (1)));
    34 static inline void WakeThread( thread_desc * thrd, bool must_yield ) {
    35         if( !thrd ) return;
    36 
    37         enum coroutine_state new_state = must_yield ? Reschedule : Rerun;
    38 
    39         disable_interrupts();
    40         static_assert(sizeof(thrd->state) == sizeof(int));
    41         enum coroutine_state old_state = (enum coroutine_state)__atomic_exchange_n((volatile int *)&thrd->state, (int)new_state, __ATOMIC_SEQ_CST);
    42         switch(old_state) {
    43                 case Active:
    44                         // Wake won the race, the thread will reschedule/rerun itself
    45                         break;
    46                 case Inactive:
    47                         // Wake lost the race,
    48                         thrd->state = Inactive;
    49                         ScheduleThread( thrd );
    50                         break;
    51                 case Rerun:
    52                 case Reschedule:
    53                         abort("More than one thread attempted to schedule thread %p\n", thrd);
    54                         break;
    55                 case Halted:
    56                 case Start:
    57                 case Primed:
    58                 default:
    59                         // This makes no sense, something is wrong abort
    60                         abort();
    61         }
    62         enable_interrupts( __cfaabi_dbg_ctx );
    63 }
    64 thread_desc * nextThread(cluster * this);
    6534
    6635//Block current thread and release/wake-up the following resources
    67 void BlockInternal(void);
    68 void BlockInternal(__spinlock_t * lock);
    69 void BlockInternal(thread_desc * thrd);
    70 void BlockInternal(__spinlock_t * lock, thread_desc * thrd);
    71 void BlockInternal(__spinlock_t * locks [], unsigned short count);
    72 void BlockInternal(__spinlock_t * locks [], unsigned short count, thread_desc * thrds [], unsigned short thrd_count);
    73 void BlockInternal(__finish_callback_fptr_t callback);
    74 void LeaveThread(__spinlock_t * lock, thread_desc * thrd);
     36void LeaveThread();
     37
     38bool force_yield( enum __Preemption_Reason );
    7539
    7640//-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.