From 709796209c88e6749320b3096df57f369c2d62be Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Wed, 29 Aug 2018 09:43:44 +0200 Subject: score: Add thread pin/unpin support Add support to temporarily pin a thread to its current processor. This may be used to access per-processor data structures in critical sections with enabled thread dispatching, e.g. a pinned thread is allowed to block. Update #3508. --- cpukit/include/rtems/score/threadimpl.h | 52 ++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'cpukit/include/rtems/score/threadimpl.h') diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h index 4ab855d3ff..530035ff67 100644 --- a/cpukit/include/rtems/score/threadimpl.h +++ b/cpukit/include/rtems/score/threadimpl.h @@ -1025,7 +1025,7 @@ RTEMS_INLINE_ROUTINE const Scheduler_Control *_Thread_Scheduler_get_home( ) { #if defined(RTEMS_SMP) - return the_thread->Scheduler.home; + return the_thread->Scheduler.home_scheduler; #else (void) the_thread; return &_Scheduler_Table[ 0 ]; @@ -1953,6 +1953,56 @@ size_t _Thread_Get_name( size_t buffer_size ); +#if defined(RTEMS_SMP) +#define THREAD_PIN_STEP 2 + +#define THREAD_PIN_PREEMPTION 1 + +void _Thread_Do_unpin( + Thread_Control *executing, + Per_CPU_Control *cpu_self +); +#endif + +RTEMS_INLINE_ROUTINE void _Thread_Pin( Thread_Control *executing ) +{ +#if defined(RTEMS_SMP) + _Assert( executing == _Thread_Executing ); + + executing->Scheduler.pin_level += THREAD_PIN_STEP; +#else + (void) executing; +#endif +} + +RTEMS_INLINE_ROUTINE void _Thread_Unpin( + Thread_Control *executing, + Per_CPU_Control *cpu_self +) +{ +#if defined(RTEMS_SMP) + unsigned int pin_level; + + _Assert( executing == _Thread_Executing ); + + pin_level = executing->Scheduler.pin_level; + _Assert( pin_level > 0 ); + + if ( + RTEMS_PREDICT_TRUE( + pin_level != ( THREAD_PIN_STEP | THREAD_PIN_PREEMPTION ) + ) + ) { + executing->Scheduler.pin_level = pin_level - THREAD_PIN_STEP; + } else { + _Thread_Do_unpin( executing, cpu_self ); + } +#else + (void) executing; + (void) cpu_self; +#endif +} + /** @}*/ #ifdef __cplusplus -- cgit v1.2.3