[PATCH 25/25] score: Avoid direct usage of _Thread_Executing
Sebastian Huber
sebastian.huber at embedded-brains.de
Thu Jul 18 14:26:13 UTC 2013
Pass the executing thread as a function parameter. Obtain the executing
thread inside a thread dispatch critical section to avoid problems on
SMP.
---
cpukit/posix/src/mqueuerecvsupp.c | 9 ++++++---
cpukit/posix/src/mqueuesendsupp.c | 5 ++++-
cpukit/rtems/src/msgqreceive.c | 5 ++++-
cpukit/score/include/rtems/score/coremsgimpl.h | 4 ++++
cpukit/score/src/coremsgseize.c | 5 ++---
cpukit/score/src/coremsgsubmit.c | 2 +-
6 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/cpukit/posix/src/mqueuerecvsupp.c b/cpukit/posix/src/mqueuerecvsupp.c
index 5eb856a..04a75a9 100644
--- a/cpukit/posix/src/mqueuerecvsupp.c
+++ b/cpukit/posix/src/mqueuerecvsupp.c
@@ -53,6 +53,7 @@ ssize_t _POSIX_Message_queue_Receive_support(
Objects_Locations location;
size_t length_out;
bool do_wait;
+ Thread_Control *executing;
the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
switch ( location ) {
@@ -88,8 +89,10 @@ ssize_t _POSIX_Message_queue_Receive_support(
/*
* Now perform the actual message receive
*/
+ executing = _Thread_Executing;
_CORE_message_queue_Seize(
&the_mq->Message_queue,
+ executing,
mqdes,
msg_ptr,
&length_out,
@@ -100,16 +103,16 @@ ssize_t _POSIX_Message_queue_Receive_support(
_Objects_Put( &the_mq_fd->Object );
if (msg_prio) {
*msg_prio = _POSIX_Message_queue_Priority_from_core(
- _Thread_Executing->Wait.count
+ executing->Wait.count
);
}
- if ( !_Thread_Executing->Wait.return_code )
+ if ( !executing->Wait.return_code )
return length_out;
rtems_set_errno_and_return_minus_one(
_POSIX_Message_queue_Translate_core_message_queue_return_code(
- _Thread_Executing->Wait.return_code
+ executing->Wait.return_code
)
);
diff --git a/cpukit/posix/src/mqueuesendsupp.c b/cpukit/posix/src/mqueuesendsupp.c
index 2b2acb8..7156763 100644
--- a/cpukit/posix/src/mqueuesendsupp.c
+++ b/cpukit/posix/src/mqueuesendsupp.c
@@ -63,6 +63,7 @@ int _POSIX_Message_queue_Send_support(
Objects_Locations location;
CORE_message_queue_Status msg_status;
bool do_wait;
+ Thread_Control *executing;
/*
* Validate the priority.
@@ -94,8 +95,10 @@ int _POSIX_Message_queue_Send_support(
/*
* Now perform the actual message receive
*/
+ executing = _Thread_Executing;
msg_status = _CORE_message_queue_Submit(
&the_mq->Message_queue,
+ executing,
msg_ptr,
msg_len,
mqdes, /* mqd_t is an object id */
@@ -115,7 +118,7 @@ int _POSIX_Message_queue_Send_support(
*/
if ( msg_status == CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT )
- msg_status = _Thread_Executing->Wait.return_code;
+ msg_status = executing->Wait.return_code;
if ( !msg_status )
return msg_status;
diff --git a/cpukit/rtems/src/msgqreceive.c b/cpukit/rtems/src/msgqreceive.c
index 265e71e..484cb53 100644
--- a/cpukit/rtems/src/msgqreceive.c
+++ b/cpukit/rtems/src/msgqreceive.c
@@ -47,6 +47,7 @@ rtems_status_code rtems_message_queue_receive(
register Message_queue_Control *the_message_queue;
Objects_Locations location;
bool wait;
+ Thread_Control *executing;
if ( !buffer )
return RTEMS_INVALID_ADDRESS;
@@ -63,8 +64,10 @@ rtems_status_code rtems_message_queue_receive(
else
wait = true;
+ executing = _Thread_Executing;
_CORE_message_queue_Seize(
&the_message_queue->message_queue,
+ executing,
the_message_queue->Object.id,
buffer,
size,
@@ -73,7 +76,7 @@ rtems_status_code rtems_message_queue_receive(
);
_Objects_Put( &the_message_queue->Object );
return _Message_queue_Translate_core_message_queue_return_code(
- _Thread_Executing->Wait.return_code
+ executing->Wait.return_code
);
#if defined(RTEMS_MULTIPROCESSING)
diff --git a/cpukit/score/include/rtems/score/coremsgimpl.h b/cpukit/score/include/rtems/score/coremsgimpl.h
index 406a596..f579e63 100644
--- a/cpukit/score/include/rtems/score/coremsgimpl.h
+++ b/cpukit/score/include/rtems/score/coremsgimpl.h
@@ -274,6 +274,7 @@ CORE_message_queue_Status _CORE_message_queue_Broadcast(
*/
CORE_message_queue_Status _CORE_message_queue_Submit(
CORE_message_queue_Control *the_message_queue,
+ Thread_Control *executing,
const void *buffer,
size_t size,
Objects_Id id,
@@ -320,6 +321,7 @@ CORE_message_queue_Status _CORE_message_queue_Submit(
*/
void _CORE_message_queue_Seize(
CORE_message_queue_Control *the_message_queue,
+ Thread_Control *executing,
Objects_Id id,
void *buffer,
size_t *size_p,
@@ -363,6 +365,7 @@ RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Send(
{
return _CORE_message_queue_Submit(
the_message_queue,
+ _Thread_Executing,
buffer,
size,
id,
@@ -388,6 +391,7 @@ RTEMS_INLINE_ROUTINE CORE_message_queue_Status _CORE_message_queue_Urgent(
{
return _CORE_message_queue_Submit(
the_message_queue,
+ _Thread_Executing,
buffer,
size,
id,
diff --git a/cpukit/score/src/coremsgseize.c b/cpukit/score/src/coremsgseize.c
index f0567db..5d64616 100644
--- a/cpukit/score/src/coremsgseize.c
+++ b/cpukit/score/src/coremsgseize.c
@@ -29,6 +29,7 @@
void _CORE_message_queue_Seize(
CORE_message_queue_Control *the_message_queue,
+ Thread_Control *executing,
Objects_Id id,
void *buffer,
size_t *size_p,
@@ -38,9 +39,7 @@ void _CORE_message_queue_Seize(
{
ISR_Level level;
CORE_message_queue_Buffer_control *the_message;
- Thread_Control *executing;
- executing = _Thread_Executing;
executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
_ISR_Disable( level );
the_message = _CORE_message_queue_Get_pending_message( the_message_queue );
@@ -49,7 +48,7 @@ void _CORE_message_queue_Seize(
_ISR_Enable( level );
*size_p = the_message->Contents.size;
- _Thread_Executing->Wait.count =
+ executing->Wait.count =
_CORE_message_queue_Get_message_priority( the_message );
_CORE_message_queue_Copy_buffer(
the_message->Contents.buffer,
diff --git a/cpukit/score/src/coremsgsubmit.c b/cpukit/score/src/coremsgsubmit.c
index c5e9a6b..6acaada 100644
--- a/cpukit/score/src/coremsgsubmit.c
+++ b/cpukit/score/src/coremsgsubmit.c
@@ -30,6 +30,7 @@
CORE_message_queue_Status _CORE_message_queue_Submit(
CORE_message_queue_Control *the_message_queue,
+ Thread_Control *executing,
const void *buffer,
size_t size,
Objects_Id id,
@@ -122,7 +123,6 @@ CORE_message_queue_Status _CORE_message_queue_Submit(
* would be to use this variable prior to here.
*/
{
- Thread_Control *executing = _Thread_Executing;
ISR_Level level;
_ISR_Disable( level );
--
1.7.7
More information about the devel
mailing list