summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-08-22 10:58:34 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-09-08 09:55:27 +0200
commite41308eab8ae4505844d8e499664424f8c7f2bd1 (patch)
tree7dffe5edacd3f245ba5ef3b64b431b7e4c74c454 /cpukit/score/include/rtems
parentscore: Simplify thread queue acquire/release (diff)
downloadrtems-e41308eab8ae4505844d8e499664424f8c7f2bd1.tar.bz2
score: Introduce Thread_queue_Lock_context
Introduce Thread_queue_Lock_context to contain the context necessary for thread queue lock and thread wait lock acquire/release operations to reduce the Thread_Control size.
Diffstat (limited to 'cpukit/score/include/rtems')
-rw-r--r--cpukit/score/include/rtems/score/coremuteximpl.h6
-rw-r--r--cpukit/score/include/rtems/score/mrspimpl.h20
-rw-r--r--cpukit/score/include/rtems/score/threadimpl.h80
-rw-r--r--cpukit/score/include/rtems/score/threadq.h112
-rw-r--r--cpukit/score/include/rtems/score/threadqimpl.h12
5 files changed, 128 insertions, 102 deletions
diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h
index 680c6d5eaf..d40d91c4fd 100644
--- a/cpukit/score/include/rtems/score/coremuteximpl.h
+++ b/cpukit/score/include/rtems/score/coremuteximpl.h
@@ -408,7 +408,9 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Set_owner(
return STATUS_SUCCESSFUL;
}
- cpu_self = _Thread_Dispatch_disable_critical( &queue_context->Lock_context );
+ cpu_self = _Thread_Dispatch_disable_critical(
+ &queue_context->Lock_context.Lock_context
+ );
_CORE_mutex_Release( &the_mutex->Recursive.Mutex, queue_context );
_Thread_Raise_priority( owner, priority_ceiling );
_Thread_Dispatch_enable( cpu_self );
@@ -524,7 +526,7 @@ RTEMS_INLINE_ROUTINE Status_Control _CORE_ceiling_mutex_Surrender(
unblock,
&the_mutex->Recursive.Mutex.Wait_queue.Queue,
new_owner,
- &queue_context->Lock_context
+ &queue_context->Lock_context.Lock_context
);
} else {
_CORE_mutex_Release( &the_mutex->Recursive.Mutex, queue_context );
diff --git a/cpukit/score/include/rtems/score/mrspimpl.h b/cpukit/score/include/rtems/score/mrspimpl.h
index 593d846b9c..5f639d7e04 100644
--- a/cpukit/score/include/rtems/score/mrspimpl.h
+++ b/cpukit/score/include/rtems/score/mrspimpl.h
@@ -126,7 +126,9 @@ RTEMS_INLINE_ROUTINE void _MRSP_Claim_ownership(
mrsp->initial_priority_of_owner = initial_priority;
_Scheduler_Thread_change_help_state( new_owner, SCHEDULER_HELP_ACTIVE_OWNER );
- cpu_self = _Thread_Dispatch_disable_critical( &queue_context->Lock_context );
+ cpu_self = _Thread_Dispatch_disable_critical(
+ &queue_context->Lock_context.Lock_context
+ );
_MRSP_Release( mrsp, queue_context );
_Thread_Raise_priority( new_owner, ceiling_priority );
@@ -207,7 +209,7 @@ RTEMS_INLINE_ROUTINE void _MRSP_Timeout( Watchdog_Control *watchdog )
Thread_queue_Context queue_context;
_Thread_queue_Context_initialize( &queue_context );
- _ISR_lock_ISR_disable( &queue_context.Lock_context );
+ _ISR_lock_ISR_disable( &queue_context.Lock_context.Lock_context );
_MRSP_Acquire_critical( mrsp, &queue_context );
if ( rival->status == MRSP_WAIT_FOR_OWNERSHIP ) {
@@ -270,7 +272,9 @@ RTEMS_INLINE_ROUTINE Status_Control _MRSP_Wait_for_ownership(
_MRSP_Giant_release( &giant_lock_context );
- cpu_self = _Thread_Dispatch_disable_critical( &queue_context->Lock_context );
+ cpu_self = _Thread_Dispatch_disable_critical(
+ &queue_context->Lock_context.Lock_context
+ );
_MRSP_Release( mrsp, queue_context );
_Thread_Raise_priority( executing, ceiling_priority );
@@ -330,7 +334,7 @@ RTEMS_INLINE_ROUTINE Status_Control _MRSP_Seize(
Resource_Node *owner;
if ( !priority_ok) {
- _ISR_lock_ISR_enable( &queue_context->Lock_context );
+ _ISR_lock_ISR_enable( &queue_context->Lock_context.Lock_context );
return STATUS_MUTEX_CEILING_VIOLATED;
}
@@ -377,7 +381,7 @@ RTEMS_INLINE_ROUTINE Status_Control _MRSP_Surrender(
ISR_lock_Context giant_lock_context;
if ( _Resource_Get_owner( &mrsp->Resource ) != &executing->Resource_node ) {
- _ISR_lock_ISR_enable( &queue_context->Lock_context );
+ _ISR_lock_ISR_enable( &queue_context->Lock_context.Lock_context );
return STATUS_NOT_OWNER;
}
@@ -387,7 +391,7 @@ RTEMS_INLINE_ROUTINE Status_Control _MRSP_Surrender(
&executing->Resource_node
)
) {
- _ISR_lock_ISR_enable( &queue_context->Lock_context );
+ _ISR_lock_ISR_enable( &queue_context->Lock_context.Lock_context );
return STATUS_RELEASE_ORDER_VIOLATION;
}
@@ -428,7 +432,9 @@ RTEMS_INLINE_ROUTINE Status_Control _MRSP_Surrender(
_MRSP_Giant_release( &giant_lock_context );
- cpu_self = _Thread_Dispatch_disable_critical( &queue_context->Lock_context );
+ cpu_self = _Thread_Dispatch_disable_critical(
+ &queue_context->Lock_context.Lock_context
+ );
_MRSP_Release( mrsp, queue_context );
_MRSP_Restore_priority( executing, initial_priority );
diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h
index 72e0ba3655..03c1ed8088 100644
--- a/cpukit/score/include/rtems/score/threadimpl.h
+++ b/cpukit/score/include/rtems/score/threadimpl.h
@@ -1031,16 +1031,16 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_release_default(
#if defined(RTEMS_SMP)
#define THREAD_QUEUE_CONTEXT_OF_REQUEST( node ) \
- RTEMS_CONTAINER_OF( node, Thread_queue_Context, Wait.Gate.Node )
+ RTEMS_CONTAINER_OF( node, Thread_queue_Context, Lock_context.Wait.Gate.Node )
RTEMS_INLINE_ROUTINE void _Thread_Wait_remove_request_locked(
- Thread_Control *the_thread,
- Thread_queue_Context *queue_context
+ Thread_Control *the_thread,
+ Thread_queue_Lock_context *queue_lock_context
)
{
Chain_Node *first;
- _Chain_Extract_unprotected( &queue_context->Wait.Gate.Node );
+ _Chain_Extract_unprotected( &queue_lock_context->Wait.Gate.Node );
first = _Chain_First( &the_thread->Wait.Lock.Pending_requests );
if ( first != _Chain_Tail( &the_thread->Wait.Lock.Pending_requests ) ) {
@@ -1049,25 +1049,25 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_remove_request_locked(
}
RTEMS_INLINE_ROUTINE void _Thread_Wait_acquire_queue_critical(
- Thread_queue_Queue *queue,
- Thread_queue_Context *queue_context
+ Thread_queue_Queue *queue,
+ Thread_queue_Lock_context *queue_lock_context
)
{
_Thread_queue_Queue_acquire_critical(
queue,
&_Thread_Executing->Potpourri_stats,
- &queue_context->Lock_context
+ &queue_lock_context->Lock_context
);
}
RTEMS_INLINE_ROUTINE void _Thread_Wait_release_queue_critical(
- Thread_queue_Queue *queue,
- Thread_queue_Context *queue_context
+ Thread_queue_Queue *queue,
+ Thread_queue_Lock_context *queue_lock_context
)
{
_Thread_queue_Queue_release_critical(
queue,
- &queue_context->Lock_context
+ &queue_lock_context->Lock_context
);
}
#endif
@@ -1092,30 +1092,36 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_acquire_critical(
_Thread_Wait_acquire_default_critical(
the_thread,
- &queue_context->Lock_context
+ &queue_context->Lock_context.Lock_context
);
queue = the_thread->Wait.queue;
- queue_context->Wait.queue = queue;
+ queue_context->Lock_context.Wait.queue = queue;
if ( queue != NULL ) {
_Thread_queue_Gate_add(
&the_thread->Wait.Lock.Pending_requests,
- &queue_context->Wait.Gate
+ &queue_context->Lock_context.Wait.Gate
);
_Thread_Wait_release_default_critical(
the_thread,
- &queue_context->Lock_context
+ &queue_context->Lock_context.Lock_context
);
- _Thread_Wait_acquire_queue_critical( queue, queue_context );
+ _Thread_Wait_acquire_queue_critical( queue, &queue_context->Lock_context );
- if ( queue_context->Wait.queue == NULL ) {
- _Thread_Wait_release_queue_critical( queue, queue_context );
+ if ( queue_context->Lock_context.Wait.queue == NULL ) {
+ _Thread_Wait_release_queue_critical(
+ queue,
+ &queue_context->Lock_context
+ );
_Thread_Wait_acquire_default_critical(
the_thread,
+ &queue_context->Lock_context.Lock_context
+ );
+ _Thread_Wait_remove_request_locked(
+ the_thread,
&queue_context->Lock_context
);
- _Thread_Wait_remove_request_locked( the_thread, queue_context );
_Assert( the_thread->Wait.queue == NULL );
}
}
@@ -1138,7 +1144,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_acquire(
)
{
_Thread_queue_Context_initialize( queue_context );
- _ISR_lock_ISR_disable( &queue_context->Lock_context );
+ _ISR_lock_ISR_disable( &queue_context->Lock_context.Lock_context );
_Thread_Wait_acquire_critical( the_thread, queue_context );
}
@@ -1160,21 +1166,25 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_release_critical(
#if defined(RTEMS_SMP)
Thread_queue_Queue *queue;
- queue = queue_context->Wait.queue;
+ queue = queue_context->Lock_context.Wait.queue;
if ( queue != NULL ) {
- _Thread_Wait_release_queue_critical( queue, queue_context );
+ _Thread_Wait_release_queue_critical(
+ queue, &queue_context->Lock_context
+ );
_Thread_Wait_acquire_default_critical(
the_thread,
+ &queue_context->Lock_context.Lock_context
+ );
+ _Thread_Wait_remove_request_locked(
+ the_thread,
&queue_context->Lock_context
);
-
- _Thread_Wait_remove_request_locked( the_thread, queue_context );
}
_Thread_Wait_release_default_critical(
the_thread,
- &queue_context->Lock_context
+ &queue_context->Lock_context.Lock_context
);
#else
(void) the_thread;
@@ -1196,7 +1206,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_release(
)
{
_Thread_Wait_release_critical( the_thread, queue_context );
- _ISR_lock_ISR_enable( &queue_context->Lock_context );
+ _ISR_lock_ISR_enable( &queue_context->Lock_context.Lock_context );
}
/**
@@ -1243,23 +1253,23 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_claim(
* On other configurations, this function does nothing.
*
* @param[in] the_thread The thread.
- * @param[in] queue_context The thread queue context used for corresponding
- * _Thread_Wait_acquire().
+ * @param[in] queue_lock_context The thread queue lock context used for
+ * corresponding _Thread_Wait_acquire().
*/
RTEMS_INLINE_ROUTINE void _Thread_Wait_remove_request(
- Thread_Control *the_thread,
- Thread_queue_Context *queue_context
+ Thread_Control *the_thread,
+ Thread_queue_Lock_context *queue_lock_context
)
{
#if defined(RTEMS_SMP)
ISR_lock_Context lock_context;
_Thread_Wait_acquire_default( the_thread, &lock_context );
- _Thread_Wait_remove_request_locked( the_thread, queue_context );
+ _Thread_Wait_remove_request_locked( the_thread, queue_lock_context );
_Thread_Wait_release_default( the_thread, &lock_context );
#else
(void) the_thread;
- (void) queue_context;
+ (void) queue_lock_context;
#endif
}
@@ -1294,7 +1304,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_restore_default(
Thread_queue_Context *queue_context;
queue_context = THREAD_QUEUE_CONTEXT_OF_REQUEST( node );
- queue_context->Wait.queue = NULL;
+ queue_context->Lock_context.Wait.queue = NULL;
node = _Chain_Next( node );
} while ( node != tail );
@@ -1363,15 +1373,15 @@ RTEMS_INLINE_ROUTINE void _Thread_Wait_cancel(
#if defined(RTEMS_SMP)
if ( queue != NULL ) {
- _Assert( queue_context->Wait.queue == queue );
+ _Assert( queue_context->Lock_context.Wait.queue == queue );
#endif
( *the_thread->Wait.operations->extract )( queue, the_thread );
_Thread_Wait_restore_default( the_thread );
#if defined(RTEMS_SMP)
- _Assert( queue_context->Wait.queue == NULL );
- queue_context->Wait.queue = queue;
+ _Assert( queue_context->Lock_context.Wait.queue == NULL );
+ queue_context->Lock_context.Wait.queue = queue;
}
#endif
}
diff --git a/cpukit/score/include/rtems/score/threadq.h b/cpukit/score/include/rtems/score/threadq.h
index 48e951eef1..a4ad0827a3 100644
--- a/cpukit/score/include/rtems/score/threadq.h
+++ b/cpukit/score/include/rtems/score/threadq.h
@@ -95,11 +95,6 @@ typedef struct {
} Thread_queue_Gate;
#endif
-/**
- * @brief Thread queue context for the thread queue methods.
- *
- * @see _Thread_queue_Context_initialize().
- */
typedef struct {
/**
* @brief The lock context for the thread queue acquire and release
@@ -107,50 +102,6 @@ typedef struct {
*/
ISR_lock_Context Lock_context;
- /**
- * @brief The expected thread dispatch disable level for
- * _Thread_queue_Enqueue_critical().
- *
- * In case the actual thread dispatch disable level is not equal to the
- * expected level, then a fatal error occurs.
- */
- uint32_t expected_thread_dispatch_disable_level;
-
- /**
- * @brief The clock discipline for the interval timeout.
- * Use WATCHDOG_NO_TIMEOUT to block indefinitely.
- */
- Watchdog_Discipline timeout_discipline;
-
- /**
- * @brief Interval to wait.
- */
- uint64_t timeout;
-
- /**
- * @brief Invoked in case of a detected deadlock.
- *
- * Must be initialized for _Thread_queue_Enqueue_critical() in case the
- * thread queue may have an owner, e.g. for mutex objects.
- *
- * @see _Thread_queue_Context_set_deadlock_callout().
- */
- Thread_queue_Deadlock_callout deadlock_callout;
-
-#if defined(RTEMS_MULTIPROCESSING)
- /**
- * @brief Callout to unblock the thread in case it is actually a thread
- * proxy.
- *
- * This field is only used on multiprocessing configurations. Used by
- * thread queue extract and unblock methods for objects with multiprocessing
- * (MP) support.
- *
- * @see _Thread_queue_Context_set_MP_callout().
- */
- Thread_queue_MP_callout mp_callout;
-#endif
-
#if defined(RTEMS_SMP)
/**
* @brief Data to support thread queue enqueue operations.
@@ -169,7 +120,7 @@ typedef struct {
Thread_queue_Queue *queue;
} Wait;
#endif
-} Thread_queue_Context;
+} Thread_queue_Lock_context;
#if defined(RTEMS_SMP)
/**
@@ -205,14 +156,71 @@ typedef struct {
Thread_Control *owner;
/**
- * @brief The queue context used to acquire the thread wait lock of the
+ * @brief The queue lock context used to acquire the thread wait lock of the
* owner.
*/
- Thread_queue_Context Queue_context;
+ Thread_queue_Lock_context Lock_context;
} Thread_queue_Link;
#endif
/**
+ * @brief Thread queue context for the thread queue methods.
+ *
+ * @see _Thread_queue_Context_initialize().
+ */
+typedef struct {
+ /**
+ * @brief The lock context for the thread queue acquire and release
+ * operations.
+ */
+ Thread_queue_Lock_context Lock_context;
+
+ /**
+ * @brief The expected thread dispatch disable level for
+ * _Thread_queue_Enqueue_critical().
+ *
+ * In case the actual thread dispatch disable level is not equal to the
+ * expected level, then a fatal error occurs.
+ */
+ uint32_t expected_thread_dispatch_disable_level;
+
+ /**
+ * @brief The clock discipline for the interval timeout.
+ * Use WATCHDOG_NO_TIMEOUT to block indefinitely.
+ */
+ Watchdog_Discipline timeout_discipline;
+
+ /**
+ * @brief Interval to wait.
+ */
+ uint64_t timeout;
+
+ /**
+ * @brief Invoked in case of a detected deadlock.
+ *
+ * Must be initialized for _Thread_queue_Enqueue_critical() in case the
+ * thread queue may have an owner, e.g. for mutex objects.
+ *
+ * @see _Thread_queue_Context_set_deadlock_callout().
+ */
+ Thread_queue_Deadlock_callout deadlock_callout;
+
+#if defined(RTEMS_MULTIPROCESSING)
+ /**
+ * @brief Callout to unblock the thread in case it is actually a thread
+ * proxy.
+ *
+ * This field is only used on multiprocessing configurations. Used by
+ * thread queue extract and unblock methods for objects with multiprocessing
+ * (MP) support.
+ *
+ * @see _Thread_queue_Context_set_MP_callout().
+ */
+ Thread_queue_MP_callout mp_callout;
+#endif
+} Thread_queue_Context;
+
+/**
* @brief Thread priority queue.
*/
typedef struct {
diff --git a/cpukit/score/include/rtems/score/threadqimpl.h b/cpukit/score/include/rtems/score/threadqimpl.h
index 641c618b1d..977b0ceb38 100644
--- a/cpukit/score/include/rtems/score/threadqimpl.h
+++ b/cpukit/score/include/rtems/score/threadqimpl.h
@@ -372,7 +372,7 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Acquire_critical(
{
_Thread_queue_Do_acquire_critical(
the_thread_queue,
- &queue_context->Lock_context
+ &queue_context->Lock_context.Lock_context
);
}
@@ -381,7 +381,7 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Acquire(
Thread_queue_Context *queue_context
)
{
- _ISR_lock_ISR_disable( &queue_context->Lock_context );
+ _ISR_lock_ISR_disable( &queue_context->Lock_context.Lock_context );
_Thread_queue_Acquire_critical( the_thread_queue, queue_context );
}
@@ -422,7 +422,7 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Release_critical(
{
_Thread_queue_Do_release_critical(
the_thread_queue,
- &queue_context->Lock_context
+ &queue_context->Lock_context.Lock_context
);
}
@@ -432,7 +432,7 @@ RTEMS_INLINE_ROUTINE void _Thread_queue_Release(
)
{
_Thread_queue_Release_critical( the_thread_queue, queue_context );
- _ISR_lock_ISR_enable( &queue_context->Lock_context );
+ _ISR_lock_ISR_enable( &queue_context->Lock_context.Lock_context );
}
Thread_Control *_Thread_queue_Do_dequeue(
@@ -511,13 +511,13 @@ Thread_Control *_Thread_queue_Do_dequeue(
* Thread_Control *executing;
*
* _Thread_queue_Context_initialize( &queue_context );
- * _Thread_queue_Acquire( &mutex->Queue, &queue_context.Lock_context );
+ * _Thread_queue_Acquire( &mutex->Queue, queue_context );
*
* executing = _Thread_Executing;
*
* if ( mutex->owner == NULL ) {
* mutex->owner = executing;
- * _Thread_queue_Release( &mutex->Queue, &queue_context.Lock_context );
+ * _Thread_queue_Release( &mutex->Queue, queue_context );
* } else {
* _Thread_queue_Context_set_expected_level( &queue_context, 1 );
* _Thread_queue_Enqueue_critical(