[PATCH 03/19] score: _CORE_message_queue_Close()
Sebastian Huber
sebastian.huber at embedded-brains.de
Fri Apr 29 09:13:03 UTC 2016
Move lock acquire to caller of _CORE_message_queue_Close() to allow
state checks during object close operations under lock protection.
Ensures deletion safety on uni-processor configuration.
---
cpukit/posix/src/mqueuedeletesupp.c | 6 +++++-
cpukit/rtems/src/msgqdelete.c | 27 +++++++++++++-------------
cpukit/score/include/rtems/score/coremsgimpl.h | 20 ++++++++++++-------
cpukit/score/src/coremsgclose.c | 10 ++++------
4 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/cpukit/posix/src/mqueuedeletesupp.c b/cpukit/posix/src/mqueuedeletesupp.c
index b852b04..5382dd4 100644
--- a/cpukit/posix/src/mqueuedeletesupp.c
+++ b/cpukit/posix/src/mqueuedeletesupp.c
@@ -41,6 +41,7 @@ void _POSIX_Message_queue_Delete(
{
if ( !the_mq->linked && !the_mq->open_count ) {
Objects_Control *the_object = &the_mq->Object;
+ ISR_lock_Context lock_context;
#if defined(RTEMS_DEBUG)
/*
@@ -55,12 +56,15 @@ void _POSIX_Message_queue_Delete(
}
#endif
+ _CORE_message_queue_Acquire( &the_mq->Message_queue, &lock_context );
+
_Objects_Close( &_POSIX_Message_queue_Information, the_object );
_CORE_message_queue_Close(
&the_mq->Message_queue,
NULL, /* no MP support */
- 0
+ 0,
+ &lock_context
);
_POSIX_Message_queue_Free( the_mq );
diff --git a/cpukit/rtems/src/msgqdelete.c b/cpukit/rtems/src/msgqdelete.c
index 5adeab7..506c069 100644
--- a/cpukit/rtems/src/msgqdelete.c
+++ b/cpukit/rtems/src/msgqdelete.c
@@ -18,17 +18,8 @@
#include "config.h"
#endif
-#include <rtems/system.h>
-#include <rtems/score/chain.h>
-#include <rtems/score/isr.h>
-#include <rtems/score/coremsgimpl.h>
-#include <rtems/score/thread.h>
-#include <rtems/score/wkspace.h>
-#include <rtems/rtems/status.h>
-#include <rtems/rtems/attrimpl.h>
#include <rtems/rtems/messageimpl.h>
-#include <rtems/rtems/options.h>
-#include <rtems/rtems/support.h>
+#include <rtems/rtems/attrimpl.h>
rtems_status_code rtems_message_queue_delete(
rtems_id id
@@ -36,19 +27,30 @@ rtems_status_code rtems_message_queue_delete(
{
Message_queue_Control *the_message_queue;
Objects_Locations location;
+ ISR_lock_Context lock_context;
_Objects_Allocator_lock();
- the_message_queue = _Message_queue_Get( id, &location );
+ the_message_queue = _Message_queue_Get_interrupt_disable(
+ id,
+ &location,
+ &lock_context
+ );
switch ( location ) {
case OBJECTS_LOCAL:
+ _CORE_message_queue_Acquire_critical(
+ &the_message_queue->message_queue,
+ &lock_context
+ );
+
_Objects_Close( &_Message_queue_Information,
&the_message_queue->Object );
_CORE_message_queue_Close(
&the_message_queue->message_queue,
_Message_queue_MP_Send_object_was_deleted,
- id
+ id,
+ &lock_context
);
#if defined(RTEMS_MULTIPROCESSING)
@@ -66,7 +68,6 @@ rtems_status_code rtems_message_queue_delete(
);
}
#endif
- _Objects_Put( &the_message_queue->Object );
_Message_queue_Free( the_message_queue );
_Objects_Allocator_unlock();
return RTEMS_SUCCESSFUL;
diff --git a/cpukit/score/include/rtems/score/coremsgimpl.h b/cpukit/score/include/rtems/score/coremsgimpl.h
index 98d97dd..b9e4be4 100644
--- a/cpukit/score/include/rtems/score/coremsgimpl.h
+++ b/cpukit/score/include/rtems/score/coremsgimpl.h
@@ -129,12 +129,12 @@ bool _CORE_message_queue_Initialize(
);
void _CORE_message_queue_Do_close(
- CORE_message_queue_Control *the_message_queue
+ CORE_message_queue_Control *the_message_queue,
#if defined(RTEMS_MULTIPROCESSING)
- ,
Thread_queue_MP_callout mp_callout,
- Objects_Id mp_id
+ Objects_Id mp_id,
#endif
+ ISR_lock_Context *lock_context
);
/**
@@ -151,26 +151,32 @@ void _CORE_message_queue_Do_close(
* @param[in] mp_callout is the routine to call for each thread
* that is extracted from the set of waiting threads
* @param[in] mp_id the object identifier of the message queue object
+ * @param[in] lock_context The lock context of the
+ * _CORE_message_queue_Acquire() or _CORE_message_queue_Acquire_critical().
*/
#if defined(RTEMS_MULTIPROCESSING)
#define _CORE_message_queue_Close( \
the_message_queue, \
mp_callout, \
- mp_id \
+ mp_id, \
+ lock_context \
) \
_CORE_message_queue_Do_close( \
the_message_queue, \
mp_callout, \
- mp_id \
+ mp_id, \
+ lock_context \
)
#else
#define _CORE_message_queue_Close( \
the_message_queue, \
mp_callout, \
- mp_id \
+ mp_id, \
+ lock_context \
) \
_CORE_message_queue_Do_close( \
- the_message_queue \
+ the_message_queue, \
+ lock_context \
)
#endif
diff --git a/cpukit/score/src/coremsgclose.c b/cpukit/score/src/coremsgclose.c
index 7184b11..5b53431 100644
--- a/cpukit/score/src/coremsgclose.c
+++ b/cpukit/score/src/coremsgclose.c
@@ -33,29 +33,27 @@ static Thread_Control *_CORE_message_queue_Was_deleted(
}
void _CORE_message_queue_Do_close(
- CORE_message_queue_Control *the_message_queue
+ CORE_message_queue_Control *the_message_queue,
#if defined(RTEMS_MULTIPROCESSING)
- ,
Thread_queue_MP_callout mp_callout,
- Objects_Id mp_id
+ Objects_Id mp_id,
#endif
+ ISR_lock_Context *lock_context
)
{
- ISR_lock_Context lock_context;
/*
* This will flush blocked threads whether they were blocked on
* a send or receive.
*/
- _CORE_message_queue_Acquire( the_message_queue, &lock_context );
_Thread_queue_Flush_critical(
&the_message_queue->Wait_queue.Queue,
the_message_queue->operations,
_CORE_message_queue_Was_deleted,
mp_callout,
mp_id,
- &lock_context
+ lock_context
);
(void) _Workspace_Free( the_message_queue->message_buffers );
--
1.8.4.5
More information about the devel
mailing list