summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-11-24 06:13:11 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-11-24 08:46:20 +0100
commit620b23ece54a0bb43189bb9c0f14adf447cbafe6 (patch)
tree10aa72eb67ac01ab85f932ac25c09ba3e5d97da8 /cpukit/score/include/rtems
parentscore: Fix interrupt profiling (diff)
downloadrtems-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')
-rw-r--r--cpukit/score/include/rtems/score/coresemimpl.h5
-rw-r--r--cpukit/score/include/rtems/score/threadq.h6
-rw-r--r--cpukit/score/include/rtems/score/threadqimpl.h52
3 files changed, 54 insertions, 9 deletions
diff --git a/cpukit/score/include/rtems/score/coresemimpl.h b/cpukit/score/include/rtems/score/coresemimpl.h
index 7f5b58e76b..20ca30b366 100644
--- a/cpukit/score/include/rtems/score/coresemimpl.h
+++ b/cpukit/score/include/rtems/score/coresemimpl.h
@@ -184,12 +184,15 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_semaphore_Seize(
return STATUS_UNSATISFIED;
}
+ _Thread_queue_Context_set_thread_state(
+ queue_context,
+ STATES_WAITING_FOR_SEMAPHORE
+ );
_Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context );
_Thread_queue_Enqueue(
&the_semaphore->Wait_queue.Queue,
operations,
executing,
- STATES_WAITING_FOR_SEMAPHORE,
queue_context
);
return _Thread_Wait_get_status( executing );
diff --git a/cpukit/score/include/rtems/score/threadq.h b/cpukit/score/include/rtems/score/threadq.h
index 61ce5fbee2..dec8e13e9e 100644
--- a/cpukit/score/include/rtems/score/threadq.h
+++ b/cpukit/score/include/rtems/score/threadq.h
@@ -24,6 +24,7 @@
#include <rtems/score/object.h>
#include <rtems/score/priority.h>
#include <rtems/score/rbtree.h>
+#include <rtems/score/states.h>
#include <rtems/score/watchdog.h>
#ifdef __cplusplus
@@ -193,6 +194,11 @@ struct Thread_queue_Context {
Thread_queue_Lock_context Lock_context;
/**
+ * @brief The thread state for _Thread_queue_Enqueue().
+ */
+ States_Control thread_state;
+
+ /**
* @brief The enqueue callout for _Thread_queue_Enqueue().
*
* The callout is invoked after the release of the thread queue lock with
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
);