diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2019-12-16 14:50:59 +0100 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2020-02-12 09:08:37 +0100 |
commit | 61357479894b08c9017ba39f90572c57dc307869 (patch) | |
tree | 3be2b2696a480dd5ffef351663a0ca944e26bbfd | |
parent | 24851567c38f573e9176529e9ca431fbf80c6cef (diff) |
score: Split up objects free
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.
-rw-r--r-- | cpukit/Makefile.am | 1 | ||||
-rw-r--r-- | cpukit/include/rtems/score/objectdata.h | 40 | ||||
-rw-r--r-- | cpukit/include/rtems/score/objectimpl.h | 103 | ||||
-rw-r--r-- | cpukit/include/rtems/score/thread.h | 3 | ||||
-rw-r--r-- | cpukit/score/src/objectfree.c | 5 | ||||
-rw-r--r-- | cpukit/score/src/objectfreestatic.c | 47 |
6 files changed, 146 insertions, 53 deletions
diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index 25dbd58813..86a406e6dd 100644 --- a/cpukit/Makefile.am +++ b/cpukit/Makefile.am @@ -864,6 +864,7 @@ 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/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..3d1a79c38b 100644 --- a/cpukit/include/rtems/score/objectdata.h +++ b/cpukit/include/rtems/score/objectdata.h @@ -203,6 +203,16 @@ struct Objects_Information { Objects_Control *( *allocate )( Objects_Information * ); /** + * @brief Free an object. + * + * In case _Objects_Allocate_none() is used, then this may be the NULL + * pointer. + * + * @see _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. * * This member is only used if unlimited objects are configured for this API @@ -331,6 +341,33 @@ Objects_Control *_Objects_Allocate_static( Objects_Information *information ); */ Objects_Control *_Objects_Allocate_unlimited( Objects_Information *information ); +/** + * @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 +394,7 @@ Objects_Information name##_Information = { \ _Objects_Build_id( api, cls, 1, 0 ), \ NULL, \ _Objects_Allocate_none, \ + NULL, \ 0, \ 0, \ 0, \ @@ -395,6 +433,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..c683e6b800 100644 --- a/cpukit/include/rtems/score/objectimpl.h +++ b/cpukit/include/rtems/score/objectimpl.h @@ -188,55 +188,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 * id associated with name. If more than one object of this class @@ -925,6 +876,60 @@ 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() ); + _Assert( information->free != NULL ); + ( *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..d666944dcf 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, \ + NULL, \ 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/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 ); +} |