forked from Imagelibrary/rtems
score: Split up objects allocation
Split up the different objects allocation 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. Change license to BSD-2-Clause according to file histories. Update #3053. Update #3835.
This commit is contained in:
@@ -858,6 +858,9 @@ librtemscpu_a_SOURCES += score/src/memoryfill.c
|
||||
librtemscpu_a_SOURCES += score/src/memoryzerobeforeuse.c
|
||||
librtemscpu_a_SOURCES += score/src/memoryzerofreeareas.c
|
||||
librtemscpu_a_SOURCES += score/src/objectallocate.c
|
||||
librtemscpu_a_SOURCES += score/src/objectallocatenone.c
|
||||
librtemscpu_a_SOURCES += score/src/objectallocatestatic.c
|
||||
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
|
||||
|
||||
@@ -162,6 +162,8 @@ typedef void ( *Objects_Thread_queue_Extract_callout )(
|
||||
);
|
||||
#endif
|
||||
|
||||
typedef struct Objects_Information Objects_Information;
|
||||
|
||||
/**
|
||||
* @brief The information structure used to manage each API class of objects.
|
||||
*
|
||||
@@ -171,7 +173,7 @@ typedef void ( *Objects_Thread_queue_Extract_callout )(
|
||||
* allocated and pre-initialized instance for each API class providing zero
|
||||
* objects, see OBJECTS_INFORMATION_DEFINE_ZERO().
|
||||
*/
|
||||
typedef struct {
|
||||
struct Objects_Information {
|
||||
/**
|
||||
* @brief This is the maximum valid ID of this object API class.
|
||||
*
|
||||
@@ -192,6 +194,14 @@ typedef struct {
|
||||
*/
|
||||
Objects_Control **local_table;
|
||||
|
||||
/**
|
||||
* @brief Allocate an object.
|
||||
*
|
||||
* @see _Objects_Allocate_none(), _Objects_Allocate_static(), and
|
||||
* _Objects_Allocate_unlimited().
|
||||
*/
|
||||
Objects_Control *( *allocate )( Objects_Information * );
|
||||
|
||||
/**
|
||||
* @brief This is the number of object control blocks on the inactive chain.
|
||||
*
|
||||
@@ -288,7 +298,38 @@ typedef struct {
|
||||
*/
|
||||
RBTree_Control Global_by_name;
|
||||
#endif
|
||||
} Objects_Information;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Always return NULL.
|
||||
*
|
||||
* @param information The objects information.
|
||||
*
|
||||
* @retval NULL Always.
|
||||
*/
|
||||
Objects_Control *_Objects_Allocate_none( Objects_Information *information );
|
||||
|
||||
/**
|
||||
* @brief Return an inactive object or NULL.
|
||||
*
|
||||
* @param information The objects information.
|
||||
*
|
||||
* @retval NULL No inactive object is available.
|
||||
* @retval object An inactive object.
|
||||
*/
|
||||
Objects_Control *_Objects_Allocate_static( Objects_Information *information );
|
||||
|
||||
/**
|
||||
* @brief Return an inactive object or NULL.
|
||||
*
|
||||
* Try to extend the objects information if necessary.
|
||||
*
|
||||
* @param information The objects information.
|
||||
*
|
||||
* @retval NULL No inactive object is available.
|
||||
* @retval object An inactive object.
|
||||
*/
|
||||
Objects_Control *_Objects_Allocate_unlimited( Objects_Information *information );
|
||||
|
||||
#if defined(RTEMS_MULTIPROCESSING)
|
||||
#define OBJECTS_INFORMATION_MP( name, extract ) \
|
||||
@@ -315,6 +356,7 @@ typedef struct {
|
||||
Objects_Information name##_Information = { \
|
||||
_Objects_Build_id( api, cls, 1, 0 ), \
|
||||
NULL, \
|
||||
_Objects_Allocate_none, \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
@@ -351,6 +393,8 @@ static type name##_Objects[ _Objects_Maximum_per_allocation( max ) ]; \
|
||||
Objects_Information name##_Information = { \
|
||||
_Objects_Build_id( api, cls, 1, _Objects_Maximum_per_allocation( max ) ), \
|
||||
name##_Local_table, \
|
||||
_Objects_Is_unlimited( max ) ? \
|
||||
_Objects_Allocate_unlimited : _Objects_Allocate_static, \
|
||||
0, \
|
||||
_Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \
|
||||
sizeof( type ), \
|
||||
|
||||
@@ -23,7 +23,9 @@
|
||||
|
||||
#include <rtems/score/objectdata.h>
|
||||
#include <rtems/score/apimutex.h>
|
||||
#include <rtems/score/assert.h>
|
||||
#include <rtems/score/isrlock.h>
|
||||
#include <rtems/score/sysstate.h>
|
||||
#include <rtems/score/threaddispatch.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -144,25 +146,6 @@ unsigned int _Objects_API_maximum_class(
|
||||
uint32_t api
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Allocates an object without locking the allocator mutex.
|
||||
*
|
||||
* This function can be called in two contexts
|
||||
* - the executing thread is the owner of the object allocator mutex, or
|
||||
* - in case the system state is not up, e.g. during sequential system
|
||||
* initialization.
|
||||
*
|
||||
* @param[in, out] information The object information block.
|
||||
*
|
||||
* @retval object The allocated object.
|
||||
* @retval NULL No object available.
|
||||
*
|
||||
* @see _Objects_Allocate() and _Objects_Free().
|
||||
*/
|
||||
Objects_Control *_Objects_Allocate_unprotected(
|
||||
Objects_Information *information
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Allocates an object.
|
||||
*
|
||||
@@ -702,6 +685,19 @@ RTEMS_INLINE_ROUTINE Objects_Maximum _Objects_Get_maximum_index(
|
||||
return _Objects_Get_index( information->maximum_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get an inactive object or NULL.
|
||||
*
|
||||
* @retval NULL No inactive object is available.
|
||||
* @retval object An inactive object.
|
||||
*/
|
||||
RTEMS_INLINE_ROUTINE Objects_Control *_Objects_Get_inactive(
|
||||
Objects_Information *information
|
||||
)
|
||||
{
|
||||
return (Objects_Control *) _Chain_Get_unprotected( &information->Inactive );
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the automatic object extension (unlimited objects) is
|
||||
* enabled.
|
||||
@@ -902,6 +898,33 @@ RTEMS_INLINE_ROUTINE bool _Objects_Allocator_is_owner( void )
|
||||
return _RTEMS_Allocator_is_owner();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Allocates an object without locking the allocator mutex.
|
||||
*
|
||||
* This function can be called in two contexts
|
||||
* - the executing thread is the owner of the object allocator mutex, or
|
||||
* - in case the system state is not up, e.g. during sequential system
|
||||
* initialization.
|
||||
*
|
||||
* @param[in, out] information The object information block.
|
||||
*
|
||||
* @retval object The allocated object.
|
||||
* @retval NULL No object available.
|
||||
*
|
||||
* @see _Objects_Allocate() and _Objects_Free().
|
||||
*/
|
||||
RTEMS_INLINE_ROUTINE Objects_Control *_Objects_Allocate_unprotected(
|
||||
Objects_Information *information
|
||||
)
|
||||
{
|
||||
_Assert(
|
||||
_Objects_Allocator_is_owner()
|
||||
|| !_System_state_Is_up( _System_state_Get() )
|
||||
);
|
||||
|
||||
return ( *information->allocate )( information );
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -1023,6 +1023,7 @@ Thread_Information name##_Information = { \
|
||||
{ \
|
||||
_Objects_Build_id( api, cls, 1, 0 ), \
|
||||
NULL, \
|
||||
_Objects_Allocate_none, \
|
||||
0, \
|
||||
0, \
|
||||
0, \
|
||||
@@ -1048,6 +1049,8 @@ Thread_Information name##_Information = { \
|
||||
{ \
|
||||
_Objects_Build_id( api, cls, 1, _Objects_Maximum_per_allocation( max ) ), \
|
||||
name##_Local_table, \
|
||||
_Objects_Is_unlimited( max ) ? \
|
||||
_Objects_Allocate_unlimited : _Objects_Allocate_static, \
|
||||
0, \
|
||||
_Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \
|
||||
sizeof( Thread_Configured_control ), \
|
||||
|
||||
@@ -1,17 +1,36 @@
|
||||
/**
|
||||
* @file
|
||||
* @file
|
||||
*
|
||||
* @brief Allocate Object
|
||||
* @ingroup RTEMSScoreObject
|
||||
* @ingroup RTEMSScoreObject
|
||||
*
|
||||
* @brief Allocate Object
|
||||
*/
|
||||
|
||||
/*
|
||||
* COPYRIGHT (c) 1989-1999.
|
||||
* On-Line Applications Research Corporation (OAR).
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rtems.org/license/LICENSE.
|
||||
* Copyright (C) 2014 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
|
||||
@@ -19,72 +38,6 @@
|
||||
#endif
|
||||
|
||||
#include <rtems/score/objectimpl.h>
|
||||
#include <rtems/score/assert.h>
|
||||
#include <rtems/score/chainimpl.h>
|
||||
#include <rtems/score/sysstate.h>
|
||||
|
||||
static Objects_Control *_Objects_Get_inactive(
|
||||
Objects_Information *information
|
||||
)
|
||||
{
|
||||
return (Objects_Control *) _Chain_Get_unprotected( &information->Inactive );
|
||||
}
|
||||
|
||||
Objects_Control *_Objects_Allocate_unprotected(
|
||||
Objects_Information *information
|
||||
)
|
||||
{
|
||||
Objects_Control *the_object;
|
||||
|
||||
_Assert(
|
||||
_Objects_Allocator_is_owner()
|
||||
|| !_System_state_Is_up( _System_state_Get() )
|
||||
);
|
||||
|
||||
/*
|
||||
* If the application is using the optional manager stubs and
|
||||
* still attempts to create the object, the information block
|
||||
* should be all zeroed out because it is in the BSS. So let's
|
||||
* check that code for this manager is even present.
|
||||
*/
|
||||
if ( information->object_size == 0 )
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* OK. The manager should be initialized and configured to have objects.
|
||||
* With any luck, it is safe to attempt to allocate an object.
|
||||
*/
|
||||
the_object = _Objects_Get_inactive( information );
|
||||
|
||||
if ( _Objects_Is_auto_extend( information ) ) {
|
||||
/*
|
||||
* If the list is empty then we are out of objects and need to
|
||||
* extend information base.
|
||||
*/
|
||||
|
||||
if ( the_object == NULL ) {
|
||||
_Objects_Extend_information( information );
|
||||
the_object = _Objects_Get_inactive( information );
|
||||
}
|
||||
|
||||
if ( the_object != NULL ) {
|
||||
Objects_Maximum objects_per_block;
|
||||
Objects_Maximum block;
|
||||
|
||||
objects_per_block = information->objects_per_block;
|
||||
block = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM;
|
||||
|
||||
if ( block > objects_per_block ) {
|
||||
block /= objects_per_block;
|
||||
|
||||
information->inactive_per_block[ block ]--;
|
||||
information->inactive--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return the_object;
|
||||
}
|
||||
|
||||
Objects_Control *_Objects_Allocate( Objects_Information *information )
|
||||
{
|
||||
|
||||
45
cpukit/score/src/objectallocatenone.c
Normal file
45
cpukit/score/src/objectallocatenone.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* @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>
|
||||
|
||||
Objects_Control *_Objects_Allocate_none( Objects_Information *information )
|
||||
{
|
||||
(void) information;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
44
cpukit/score/src/objectallocatestatic.c
Normal file
44
cpukit/score/src/objectallocatestatic.c
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @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/objectimpl.h>
|
||||
|
||||
Objects_Control *_Objects_Allocate_static( Objects_Information *information )
|
||||
{
|
||||
return _Objects_Get_inactive( information );
|
||||
}
|
||||
79
cpukit/score/src/objectallocateunlimited.c
Normal file
79
cpukit/score/src/objectallocateunlimited.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/**
|
||||
* @file
|
||||
*
|
||||
* @ingroup RTEMSScoreObject
|
||||
*/
|
||||
|
||||
/*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (C) 1989, 2007 On-Line Applications Research Corporation (OAR)
|
||||
*
|
||||
* 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/objectimpl.h>
|
||||
|
||||
Objects_Control *_Objects_Allocate_unlimited( Objects_Information *information )
|
||||
{
|
||||
Objects_Control *the_object;
|
||||
|
||||
_Assert( _Objects_Is_auto_extend( information ) );
|
||||
|
||||
/*
|
||||
* OK. The manager should be initialized and configured to have objects.
|
||||
* With any luck, it is safe to attempt to allocate an object.
|
||||
*/
|
||||
the_object = _Objects_Get_inactive( information );
|
||||
|
||||
/*
|
||||
* If the list is empty then we are out of objects and need to
|
||||
* extend information base.
|
||||
*/
|
||||
|
||||
if ( the_object == NULL ) {
|
||||
_Objects_Extend_information( information );
|
||||
the_object = _Objects_Get_inactive( information );
|
||||
}
|
||||
|
||||
if ( the_object != NULL ) {
|
||||
Objects_Maximum objects_per_block;
|
||||
Objects_Maximum block;
|
||||
|
||||
objects_per_block = information->objects_per_block;
|
||||
block = _Objects_Get_index( the_object->id ) - OBJECTS_INDEX_MINIMUM;
|
||||
|
||||
if ( block > objects_per_block ) {
|
||||
block /= objects_per_block;
|
||||
|
||||
information->inactive_per_block[ block ]--;
|
||||
information->inactive--;
|
||||
}
|
||||
}
|
||||
|
||||
return the_object;
|
||||
}
|
||||
Reference in New Issue
Block a user