diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-11-24 06:13:11 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-11-24 08:46:20 +0100 |
commit | 620b23ece54a0bb43189bb9c0f14adf447cbafe6 (patch) | |
tree | 10aa72eb67ac01ab85f932ac25c09ba3e5d97da8 /cpukit/score/include/rtems/score/threadqimpl.h | |
parent | score: Fix interrupt profiling (diff) | |
download | rtems-620b23ece54a0bb43189bb9c0f14adf447cbafe6.tar.bz2 |
score: Optimize _Thread_queue_Enqueue()
Move thread state for _Thread_queue_Enqueue() to the thread queue
context. This reduces the parameter count of _Thread_queue_Enqueue()
from five to four (ARM for example has only four function parameter
registers). Since the thread state is used after several function calls
inside _Thread_queue_Enqueue() this parameter was saved on the stack
previously.
Diffstat (limited to 'cpukit/score/include/rtems/score/threadqimpl.h')
-rw-r--r-- | cpukit/score/include/rtems/score/threadqimpl.h | 52 |
1 files changed, 44 insertions, 8 deletions
diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h index 6e3c044aed..bb35b1718b 100644 --- a/cpukit/score/include/rtems/score/threadqimpl.h +++ b/cpukit/score/include/rtems/score/threadqimpl.h @@ -96,6 +96,24 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Context_initialize( } /** + * @brief Sets the thread state for the thread to enqueue in the thread queue + * context. + * + * @param queue_context The thread queue context. + * @param state The thread state. + * + * @see _Thread_queue_Enqueue(). + */ +RTEMS_INLINE_ROUTINE void +_Thread_queue_Context_set_thread_state( + Thread_queue_Context *queue_context, + States_Control thread_state +) +{ + queue_context->thread_state = thread_state; +} + +/** * @brief Sets the enqueue callout in the thread queue context. * * @param queue_context The thread queue context. @@ -557,6 +575,20 @@ Thread_Control *_Thread_queue_Do_dequeue( * to protect the state of objects embedding the thread queue and directly * enter _Thread_queue_Enqueue() in case the thread must block. * + * The thread queue context must be set up with the following functions, + * otherwise the behaviour is unpredictable + * + * - _Thread_queue_Context_set_thread_state(), + * + * - _Thread_queue_Context_set_enqueue_callout() or + * _Thread_queue_Context_set_do_nothing_enqueue_callout(), + * + * - _Thread_queue_Context_set_no_timeout() or + * _Thread_queue_Context_set_relative_timeout() or + * _Thread_queue_Context_set_absolute_timeout(), and + * + * - _Thread_queue_Context_set_deadlock_callout(). + * * @code * #include <rtems/score/threadqimpl.h> * #include <rtems/score/statesimpl.h> @@ -564,8 +596,7 @@ Thread_Control *_Thread_queue_Do_dequeue( * #define MUTEX_TQ_OPERATIONS &_Thread_queue_Operations_priority * * typedef struct { - * Thread_queue_Control Queue; - * Thread_Control *owner; + * Thread_queue_Control Queue; * } Mutex; * * void _Mutex_Obtain( Mutex *mutex ) @@ -578,17 +609,24 @@ Thread_Control *_Thread_queue_Do_dequeue( * * executing = _Thread_Executing; * - * if ( mutex->owner == NULL ) { - * mutex->owner = executing; + * if ( mutex->Queue.owner == NULL ) { + * mutex->Queue.owner = executing; * _Thread_queue_Release( &mutex->Queue, queue_context ); * } else { + * _Thread_queue_Context_set_thread_state( + * &queue_context, + * STATES_WAITING_FOR_MUTEX + * ); * _Thread_queue_Context_set_do_nothing_enqueue_callout( &queue_context ); + * _Thread_queue_Context_set_no_timeout( &queue_context ); + * _Thread_queue_Context_set_deadlock_callout( + * queue_context, + * _Thread_queue_Deadlock_fatal + * ); * _Thread_queue_Enqueue( * &mutex->Queue.Queue, * MUTEX_TQ_OPERATIONS, * executing, - * STATES_WAITING_FOR_MUTEX, - * 0, * &queue_context * ); * } @@ -598,14 +636,12 @@ Thread_Control *_Thread_queue_Do_dequeue( * @param[in] queue The actual thread queue. * @param[in] operations The thread queue operations. * @param[in] the_thread The thread to enqueue. - * @param[in] state The new state of the thread. * @param[in] queue_context The thread queue context of the lock acquire. */ void _Thread_queue_Enqueue( Thread_queue_Queue *queue, const Thread_queue_Operations *operations, Thread_Control *the_thread, - States_Control state, Thread_queue_Context *queue_context ); |