[PATCH 14/21] score: Split up objects free
Sebastian Huber
sebastian.huber at embedded-brains.de
Mon Dec 16 14:28:19 UTC 2019
Split up the different objects free methods into separate functions.
This helps to avoid a dependency on the workspace in case no objects or
a static set of objects is configured.
Update #3835.
---
cpukit/Makefile.am | 2 +
cpukit/include/rtems/score/objectdata.h | 51 ++++++++++++++++
cpukit/include/rtems/score/objectimpl.h | 102 +++++++++++++++++---------------
cpukit/include/rtems/score/thread.h | 3 +
cpukit/score/src/objectfree.c | 5 +-
cpukit/score/src/objectfreenone.c | 47 +++++++++++++++
cpukit/score/src/objectfreestatic.c | 47 +++++++++++++++
7 files changed, 204 insertions(+), 53 deletions(-)
create mode 100644 cpukit/score/src/objectfreenone.c
create mode 100644 cpukit/score/src/objectfreestatic.c
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am
index aed67f3f13..950b73a70a 100644
--- a/cpukit/Makefile.am
+++ b/cpukit/Makefile.am
@@ -861,6 +861,8 @@ librtemscpu_a_SOURCES += score/src/objectallocateunlimited.c
librtemscpu_a_SOURCES += score/src/objectclose.c
librtemscpu_a_SOURCES += score/src/objectextendinformation.c
librtemscpu_a_SOURCES += score/src/objectfree.c
+librtemscpu_a_SOURCES += score/src/objectfreenone.c
+librtemscpu_a_SOURCES += score/src/objectfreestatic.c
librtemscpu_a_SOURCES += score/src/objectgetnext.c
librtemscpu_a_SOURCES += score/src/objectinitializeinformation.c
librtemscpu_a_SOURCES += score/src/objectnametoid.c
diff --git a/cpukit/include/rtems/score/objectdata.h b/cpukit/include/rtems/score/objectdata.h
index b923c45d25..158d6ab97f 100644
--- a/cpukit/include/rtems/score/objectdata.h
+++ b/cpukit/include/rtems/score/objectdata.h
@@ -202,6 +202,14 @@ struct Objects_Information {
*/
Objects_Control *( *allocate )( Objects_Information * );
+ /**
+ * @brief Free an object.
+ *
+ * @see _Objects_Free_none(), _Objects_Free_static(), and
+ * _Objects_Free_unlimited().
+ */
+ void ( *free )( Objects_Information *, Objects_Control * );
+
/**
* @brief This is the number of object control blocks on the inactive chain.
*
@@ -331,6 +339,46 @@ Objects_Control *_Objects_Allocate_static( Objects_Information *information );
*/
Objects_Control *_Objects_Allocate_unlimited( Objects_Information *information );
+/**
+ * @brief Free the object.
+ *
+ * This function does nothing.
+ *
+ * @param information The objects information.
+ * @param the_object The object to free.
+ */
+void _Objects_Free_none(
+ Objects_Information *information,
+ Objects_Control *the_object
+);
+
+/**
+ * @brief Free the object.
+ *
+ * Append the object to the inactive chain of the objects information.
+ *
+ * @param information The objects information.
+ * @param the_object The object to free.
+ */
+void _Objects_Free_static(
+ Objects_Information *information,
+ Objects_Control *the_object
+);
+
+/**
+ * @brief Free the object.
+ *
+ * Append the object to the inactive chain of the objects information and shrink
+ * the objects information if necessary.
+ *
+ * @param information The objects information.
+ * @param the_object The object to free.
+ */
+void _Objects_Free_unlimited(
+ Objects_Information *information,
+ Objects_Control *the_object
+);
+
#if defined(RTEMS_MULTIPROCESSING)
#define OBJECTS_INFORMATION_MP( name, extract ) \
, \
@@ -357,6 +405,7 @@ Objects_Information name##_Information = { \
_Objects_Build_id( api, cls, 1, 0 ), \
NULL, \
_Objects_Allocate_none, \
+ _Objects_Free_none, \
0, \
0, \
0, \
@@ -395,6 +444,8 @@ Objects_Information name##_Information = { \
name##_Local_table, \
_Objects_Is_unlimited( max ) ? \
_Objects_Allocate_unlimited : _Objects_Allocate_static, \
+ _Objects_Is_unlimited( max ) ? \
+ _Objects_Free_unlimited : _Objects_Free_static, \
0, \
_Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \
sizeof( type ), \
diff --git a/cpukit/include/rtems/score/objectimpl.h b/cpukit/include/rtems/score/objectimpl.h
index a2548dd980..a11d3a5a29 100644
--- a/cpukit/include/rtems/score/objectimpl.h
+++ b/cpukit/include/rtems/score/objectimpl.h
@@ -187,55 +187,6 @@ unsigned int _Objects_API_maximum_class(
*/
Objects_Control *_Objects_Allocate( Objects_Information *information );
-/**
- * @brief Frees an object.
- *
- * Appends the object to the chain of inactive objects.
- *
- * @param information The object information block.
- * @param[out] the_object The object to free.
- *
- * @see _Objects_Allocate().
- *
- * A typical object deletion code looks like this:
- * @code
- * rtems_status_code some_delete( rtems_id id )
- * {
- * Some_Control *some;
- *
- * // The object allocator mutex protects the executing thread from
- * // asynchronous thread restart and deletion.
- * _Objects_Allocator_lock();
- *
- * // Get the object under protection of the object allocator mutex.
- * some = (Semaphore_Control *)
- * _Objects_Get_no_protection( id, &_Some_Information );
- *
- * if ( some == NULL ) {
- * _Objects_Allocator_unlock();
- * return RTEMS_INVALID_ID;
- * }
- *
- * // After the object close an object get with this identifier will
- * // fail.
- * _Objects_Close( &_Some_Information, &some->Object );
- *
- * _Some_Delete( some );
- *
- * // Thread dispatching is enabled. The object free is only protected
- * // by the object allocator mutex.
- * _Objects_Free( &_Some_Information, &some->Object );
- *
- * _Objects_Allocator_unlock();
- * return RTEMS_SUCCESSFUL;
- * }
- * @endcode
- */
-void _Objects_Free(
- Objects_Information *information,
- Objects_Control *the_object
-);
-
/**
* This function implements the common portion of the object
* identification directives. This directive returns the object
@@ -925,6 +876,59 @@ RTEMS_INLINE_ROUTINE Objects_Control *_Objects_Allocate_unprotected(
return ( *information->allocate )( information );
}
+/**
+ * @brief Frees an object.
+ *
+ * Appends the object to the chain of inactive objects.
+ *
+ * @param information The object information block.
+ * @param[out] the_object The object to free.
+ *
+ * @see _Objects_Allocate().
+ *
+ * A typical object deletion code looks like this:
+ * @code
+ * rtems_status_code some_delete( rtems_id id )
+ * {
+ * Some_Control *some;
+ *
+ * // The object allocator mutex protects the executing thread from
+ * // asynchronous thread restart and deletion.
+ * _Objects_Allocator_lock();
+ *
+ * // Get the object under protection of the object allocator mutex.
+ * some = (Semaphore_Control *)
+ * _Objects_Get_no_protection( id, &_Some_Information );
+ *
+ * if ( some == NULL ) {
+ * _Objects_Allocator_unlock();
+ * return RTEMS_INVALID_ID;
+ * }
+ *
+ * // After the object close an object get with this identifier will
+ * // fail.
+ * _Objects_Close( &_Some_Information, &some->Object );
+ *
+ * _Some_Delete( some );
+ *
+ * // Thread dispatching is enabled. The object free is only protected
+ * // by the object allocator mutex.
+ * _Objects_Free( &_Some_Information, &some->Object );
+ *
+ * _Objects_Allocator_unlock();
+ * return RTEMS_SUCCESSFUL;
+ * }
+ * @endcode
+ */
+RTEMS_INLINE_ROUTINE void _Objects_Free(
+ Objects_Information *information,
+ Objects_Control *the_object
+)
+{
+ _Assert( _Objects_Allocator_is_owner() );
+ ( *information->free )( information, the_object );
+}
+
/** @} */
#ifdef __cplusplus
diff --git a/cpukit/include/rtems/score/thread.h b/cpukit/include/rtems/score/thread.h
index 3d977749ff..ab640c3595 100644
--- a/cpukit/include/rtems/score/thread.h
+++ b/cpukit/include/rtems/score/thread.h
@@ -1024,6 +1024,7 @@ Thread_Information name##_Information = { \
_Objects_Build_id( api, cls, 1, 0 ), \
NULL, \
_Objects_Allocate_none, \
+ _Objects_Free_none, \
0, \
0, \
0, \
@@ -1051,6 +1052,8 @@ Thread_Information name##_Information = { \
name##_Local_table, \
_Objects_Is_unlimited( max ) ? \
_Objects_Allocate_unlimited : _Objects_Allocate_static, \
+ _Objects_Is_unlimited( max ) ? \
+ _Objects_Free_unlimited : _Objects_Free_static, \
0, \
_Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \
sizeof( Thread_Configured_control ), \
diff --git a/cpukit/score/src/objectfree.c b/cpukit/score/src/objectfree.c
index af71245689..fff3cc13be 100644
--- a/cpukit/score/src/objectfree.c
+++ b/cpukit/score/src/objectfree.c
@@ -19,16 +19,13 @@
#endif
#include <rtems/score/objectimpl.h>
-#include <rtems/score/assert.h>
#include <rtems/score/chainimpl.h>
-void _Objects_Free(
+void _Objects_Free_unlimited(
Objects_Information *information,
Objects_Control *the_object
)
{
- _Assert( _Objects_Allocator_is_owner() );
-
_Chain_Append_unprotected( &information->Inactive, &the_object->Node );
if ( _Objects_Is_auto_extend( information ) ) {
diff --git a/cpukit/score/src/objectfreenone.c b/cpukit/score/src/objectfreenone.c
new file mode 100644
index 0000000000..ec6f89ccb5
--- /dev/null
+++ b/cpukit/score/src/objectfreenone.c
@@ -0,0 +1,47 @@
+/**
+ * @file
+ *
+ * @ingroup RTEMSScoreObject
+ */
+
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2019 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/score/objectdata.h>
+
+void _Objects_Free_none(
+ Objects_Information *information,
+ Objects_Control *the_object
+)
+{
+ (void) information;
+ (void) the_object;
+}
diff --git a/cpukit/score/src/objectfreestatic.c b/cpukit/score/src/objectfreestatic.c
new file mode 100644
index 0000000000..5992c1eca2
--- /dev/null
+++ b/cpukit/score/src/objectfreestatic.c
@@ -0,0 +1,47 @@
+/**
+ * @file
+ *
+ * @ingroup RTEMSScoreObject
+ */
+
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (C) 2019 embedded brains GmbH
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/score/objectdata.h>
+#include <rtems/score/chainimpl.h>
+
+void _Objects_Free_static(
+ Objects_Information *information,
+ Objects_Control *the_object
+)
+{
+ _Chain_Append_unprotected( &information->Inactive, &the_object->Node );
+}
--
2.16.4
More information about the devel
mailing list