Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:13

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSScoreObject
0007  *
0008  * @brief This header file provides data structures used by the implementation
0009  *   and the @ref RTEMSImplApplConfig to define instances of
0010  *   ::Objects_Information, ::_Objects_MP_Controls, and ultimately
0011  *   ::Thread_Configured_control.
0012  */
0013 
0014 /*
0015  *  COPYRIGHT (c) 1989-2011.
0016  *  On-Line Applications Research Corporation (OAR).
0017  *
0018  * Redistribution and use in source and binary forms, with or without
0019  * modification, are permitted provided that the following conditions
0020  * are met:
0021  * 1. Redistributions of source code must retain the above copyright
0022  *    notice, this list of conditions and the following disclaimer.
0023  * 2. Redistributions in binary form must reproduce the above copyright
0024  *    notice, this list of conditions and the following disclaimer in the
0025  *    documentation and/or other materials provided with the distribution.
0026  *
0027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0037  * POSSIBILITY OF SUCH DAMAGE.
0038  */
0039 
0040 #ifndef _RTEMS_SCORE_OBJECTDATA_H
0041 #define _RTEMS_SCORE_OBJECTDATA_H
0042 
0043 #include <rtems/score/object.h>
0044 #include <rtems/score/chainimpl.h>
0045 #include <rtems/score/rbtree.h>
0046 
0047 #ifdef __cplusplus
0048 extern "C" {
0049 #endif
0050 
0051 /**
0052  * @addtogroup RTEMSScoreObject
0053  *
0054  * @{
0055  */
0056 
0057 /**
0058  *  The following defines the Object Control Block used to manage
0059  *  each object local to this node.
0060  */
0061 typedef struct {
0062   /** This is the chain node portion of an object. */
0063   Chain_Node     Node;
0064   /** This is the object's ID. */
0065   Objects_Id     id;
0066   /** This is the object's name. */
0067   Objects_Name   name;
0068 } Objects_Control;
0069 
0070 /**
0071  *  This enumerated type is used in the class field of the object ID
0072  *  for RTEMS internal object classes.
0073  */
0074 typedef enum {
0075   OBJECTS_INTERNAL_NO_CLASS = 0,
0076 
0077   /* Must be one, see _Thread_Get_objects_information_by_id() */
0078   OBJECTS_INTERNAL_THREADS = 1
0079 } Objects_Internal_API;
0080 
0081 /**
0082  *  This enumerated type is used in the class field of the object ID
0083  *  for the RTEMS Classic API.
0084  */
0085 typedef enum {
0086   OBJECTS_CLASSIC_NO_CLASS = 0,
0087 
0088   /* Must be one, see _Thread_Get_objects_information_by_id() */
0089   OBJECTS_RTEMS_TASKS = 1,
0090 
0091   OBJECTS_RTEMS_TIMERS,
0092   OBJECTS_RTEMS_SEMAPHORES,
0093   OBJECTS_RTEMS_MESSAGE_QUEUES,
0094   OBJECTS_RTEMS_PARTITIONS,
0095   OBJECTS_RTEMS_REGIONS,
0096   OBJECTS_RTEMS_PORTS,
0097   OBJECTS_RTEMS_PERIODS,
0098   OBJECTS_RTEMS_EXTENSIONS,
0099   OBJECTS_RTEMS_BARRIERS
0100 } Objects_Classic_API;
0101 
0102 /**
0103  *  This enumerated type is used in the class field of the object ID
0104  *  for the POSIX API.
0105  */
0106 typedef enum {
0107   OBJECTS_POSIX_NO_CLASS = 0,
0108 
0109   /* Must be one, see _Thread_Get_objects_information_by_id() */
0110   OBJECTS_POSIX_THREADS = 1,
0111 
0112   OBJECTS_POSIX_KEYS,
0113   OBJECTS_POSIX_MESSAGE_QUEUES,
0114   OBJECTS_POSIX_SEMAPHORES,
0115   OBJECTS_POSIX_TIMERS,
0116   OBJECTS_POSIX_SHMS
0117 } Objects_POSIX_API;
0118 
0119 /**
0120  * @brief Constant for the object information string name length to indicate
0121  * that this object class has no string names.
0122  */
0123 #define OBJECTS_NO_STRING_NAME 0
0124 
0125 #if defined( RTEMS_MULTIPROCESSING )
0126 struct _Thread_Control;
0127 
0128 /**
0129  * @brief This defines the Global Object Control Block used to manage objects
0130  * resident on other nodes.
0131  */
0132 typedef struct {
0133   /**
0134    * @brief Nodes to manage active and inactive global objects.
0135    */
0136   union {
0137     /**
0138      * @brief Inactive global objects reside on a chain.
0139      */
0140     Chain_Node Inactive;
0141 
0142     struct {
0143       /**
0144        * @brief Node to lookup an active global object by identifier.
0145        */
0146       RBTree_Node Id_lookup;
0147 
0148       /**
0149        * @brief Node to lookup an active global object by name.
0150        */
0151       RBTree_Node Name_lookup;
0152     } Active;
0153   } Nodes;
0154 
0155   /**
0156    * @brief The global object identifier.
0157    */
0158   Objects_Id id;
0159 
0160   /**
0161    * @brief The global object name.
0162    *
0163    * Using an unsigned thirty two bit value is broken but works.  If any API is
0164    * MP with variable length names .. BOOM!!!!
0165    */
0166   uint32_t name;
0167 } Objects_MP_Control;
0168 
0169 /**
0170  * @brief The MP object controls.
0171  *
0172  * Provided by the application via <rtems/confdefs.h>.
0173  */
0174 extern Objects_MP_Control _Objects_MP_Controls[];
0175 
0176 /**
0177  *  The following type defines the callout used when a local task
0178  *  is extracted from a remote thread queue (i.e. it's proxy must
0179  *  extracted from the remote queue).
0180  */
0181 typedef void ( *Objects_Thread_queue_Extract_callout )(
0182   struct _Thread_Control *,
0183   Objects_Id
0184 );
0185 #endif
0186 
0187 typedef struct Objects_Information Objects_Information;
0188 
0189 /**
0190  * @brief The information structure used to manage each API class of objects.
0191  *
0192  * If objects for the API class are configured, an instance of this structure
0193  * is statically allocated and pre-initialized by OBJECTS_INFORMATION_DEFINE()
0194  * through <rtems/confdefs.h>.  The RTEMS library contains a statically
0195  * allocated and pre-initialized instance for each API class providing zero
0196  * objects, see OBJECTS_INFORMATION_DEFINE_ZERO().
0197  */
0198 struct Objects_Information {
0199   /**
0200    * @brief This is the maximum valid ID of this object API class.
0201    *
0202    * This member is statically initialized and provides also the object API,
0203    * class and multiprocessing node information.
0204    *
0205    * It is used by _Objects_Get() to validate an object ID.
0206    */
0207   Objects_Id maximum_id;
0208 
0209   /**
0210    * @brief This points to the table of local object control blocks.
0211    *
0212    * This member is statically initialized.  In case objects for this API class
0213    * are configured, it initially points to a statically allocated table
0214    * defined by <rtems/confdefs.h>.  _Objects_Extend_information() may replace
0215    * the table with a larger one on demand.
0216    */
0217   Objects_Control **local_table;
0218 
0219   /**
0220    * @brief Allocate an object.
0221    *
0222    * @see _Objects_Allocate_none(), _Objects_Allocate_static(), and
0223    *   _Objects_Allocate_unlimited().
0224    */
0225   Objects_Control *( *allocate )( Objects_Information * );
0226 
0227   /**
0228    * @brief Free an object.
0229    *
0230    * In case _Objects_Allocate_none() is used, then this may be the NULL
0231    * pointer.
0232    *
0233    * @see _Objects_Free_static(), and _Objects_Free_unlimited().
0234    */
0235   void ( *deallocate )( Objects_Information *, Objects_Control * );
0236 
0237   /**
0238    * @brief This is the number of object control blocks on the inactive chain.
0239    *
0240    * This member is only used if unlimited objects are configured for this API
0241    * class.  It is used to trigger calls to _Objects_Shrink_information() in
0242    * _Objects_Free().
0243    */
0244   Objects_Maximum inactive;
0245 
0246   /**
0247    * @brief This is the number of object control blocks in an allocation block.
0248    *
0249    * This member is statically initialized and read-only.  It is only used if
0250    * unlimited objects are configured for this API class.  It defines the count
0251    * of object control blocks used to extend and shrink this API class.
0252    */
0253   Objects_Maximum objects_per_block;
0254 
0255   /**
0256    * @brief This is the size in bytes of each object control block.
0257    *
0258    * This member is statically initialized and read-only.
0259    */
0260   uint16_t object_size;
0261 
0262   /**
0263    * @brief This is the maximum length of names.
0264    *
0265    * This member is statically initialized and read-only.  A length of zero
0266    * indicates that this API class has a no string name
0267    * (OBJECTS_NO_STRING_NAME).
0268    */
0269   uint16_t name_length;
0270 
0271   /**
0272    * @brief This is the chain of inactive object control blocks.
0273    *
0274    * This member is statically initialized to an empty chain.  The
0275    * _Objects_Initialize_information() will populate this chain with the
0276    * object control blocks initially configured.
0277    */
0278   Chain_Control Inactive;
0279 
0280   /**
0281    * @brief This is the number of inactive object control blocks per allocation
0282    * block.
0283    *
0284    * It is only used if unlimited objects are configured for this API class.
0285    */
0286   Objects_Maximum *inactive_per_block;
0287 
0288   /**
0289    * @brief This is a table to allocation blocks of object control blocks.
0290    *
0291    * It is only used if unlimited objects are configured for this API class.
0292    * The object control blocks extend and shrink by these allocation blocks.
0293    */
0294   Objects_Control **object_blocks;
0295 
0296   /**
0297    * @brief This points to the object control blocks initially available.
0298    *
0299    * This member is statically initialized and read-only.  In case objects for
0300    * this API class are configured, it points to a statically allocated table
0301    * of object control blocks defined by <rtems/confdefs.h>, otherwise this
0302    * member is NULL.
0303    */
0304   Objects_Control *initial_objects;
0305 
0306 #if defined(RTEMS_MULTIPROCESSING)
0307   /**
0308    * @brief This method is used by _Thread_MP_Extract_proxy().
0309    *
0310    * This member is statically initialized and read-only.
0311    */
0312   Objects_Thread_queue_Extract_callout extract;
0313 
0314   /**
0315    * @brief The global objects of this object information sorted by object ID.
0316    *
0317    * This member is statically initialized to an empty tree.  The
0318    * _Objects_MP_Open() and _Objects_MP_Close() functions alter this tree.
0319    */
0320   RBTree_Control Global_by_id;
0321 
0322   /**
0323    * @brief The global objects of this object information sorted by object
0324    * name.
0325    *
0326    * This member is statically initialized to an empty tree.  The
0327    * _Objects_MP_Open() and _Objects_MP_Close() functions alter this tree.
0328    *
0329    * Objects with the same name are sorted according to their ID.
0330    */
0331   RBTree_Control Global_by_name;
0332 #endif
0333 };
0334 
0335 /**
0336  * @brief Always return NULL.
0337  *
0338  * @param information The objects information.
0339  *
0340  * @retval NULL Always.
0341  */
0342 Objects_Control *_Objects_Allocate_none( Objects_Information *information );
0343 
0344 /**
0345  * @brief Return an inactive object or NULL.
0346  *
0347  * @param information The objects information.
0348  *
0349  * @retval NULL No inactive object is available.
0350  * @retval object An inactive object.
0351  */
0352 Objects_Control *_Objects_Allocate_static( Objects_Information *information );
0353 
0354 /**
0355  * @brief Return an inactive object or NULL.
0356  *
0357  * Try to extend the objects information if necessary.
0358  *
0359  * @param information The objects information.
0360  *
0361  * @retval NULL No inactive object is available.
0362  * @retval object An inactive object.
0363  */
0364 Objects_Control *_Objects_Allocate_unlimited( Objects_Information *information );
0365 
0366 /**
0367  * @brief Free the object.
0368  *
0369  * Append the object to the inactive chain of the objects information.
0370  *
0371  * @param information The objects information.
0372  * @param the_object The object to free.
0373  */
0374 void _Objects_Free_static(
0375   Objects_Information *information,
0376   Objects_Control     *the_object
0377 );
0378 
0379 /**
0380  * @brief Free the object.
0381  *
0382  * Append the object to the inactive chain of the objects information and shrink
0383  * the objects information if necessary.
0384  *
0385  * @param information The objects information.
0386  * @param the_object The object to free.
0387  */
0388 void _Objects_Free_unlimited(
0389   Objects_Information *information,
0390   Objects_Control     *the_object
0391 );
0392 
0393 #if defined(RTEMS_MULTIPROCESSING)
0394 #define OBJECTS_INFORMATION_MP( name, extract ) \
0395   , \
0396   extract, \
0397   RBTREE_INITIALIZER_EMPTY( name.Global_by_id ), \
0398   RBTREE_INITIALIZER_EMPTY( name.Global_by_name )
0399 #else
0400 #define OBJECTS_INFORMATION_MP( name, extract )
0401 #endif
0402 
0403 /**
0404  * @brief Statically initializes an objects information.
0405  *
0406  * The initialized objects information contains no objects.
0407  *
0408  * @param name The object class C designator namespace prefix, e.g. _Semaphore.
0409  * @param api The object API number, e.g. OBJECTS_CLASSIC_API.
0410  * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES.
0411  * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for
0412  *   objects without a string name.
0413  */
0414 #define OBJECTS_INFORMATION_DEFINE_ZERO( name, api, cls, nl ) \
0415 Objects_Information name##_Information = { \
0416   _Objects_Build_id( api, cls, 1, 0 ), \
0417   NULL, \
0418   _Objects_Allocate_none, \
0419   NULL, \
0420   0, \
0421   0, \
0422   0, \
0423   nl, \
0424   CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \
0425   NULL, \
0426   NULL, \
0427   NULL \
0428   OBJECTS_INFORMATION_MP( name##_Information, NULL ) \
0429 }
0430 
0431 /**
0432  * @brief Statically initializes an objects information.
0433  *
0434  * The initialized objects information references a table with statically
0435  * allocated objects as specified by the object maximum parameter.  These
0436  * objects must be registered via a call to _Objects_Information().
0437  *
0438  * @param name The object class C designator namespace prefix, e.g. _Semaphore.
0439  * @param api The object API number, e.g. OBJECTS_CLASSIC_API.
0440  * @param cls The object class number, e.g. OBJECTS_RTEMS_SEMAPHORES.
0441  * @param type The object class type.
0442  * @param max The configured object maximum (the OBJECTS_UNLIMITED_OBJECTS flag
0443  *   may be set).
0444  * @param nl The object name string length, use OBJECTS_NO_STRING_NAME for
0445  *   objects without a string name.
0446  * @param ex The optional object extraction method.  Used only if
0447  *   multiprocessing (RTEMS_MULTIPROCESSING) is enabled.
0448  */
0449 #define OBJECTS_INFORMATION_DEFINE( name, api, cls, type, max, nl, ex ) \
0450 static Objects_Control * \
0451 name##_Local_table[ _Objects_Maximum_per_allocation( max ) ]; \
0452 static RTEMS_SECTION( ".noinit.rtems.content.objects." #name ) \
0453 type \
0454 name##_Objects[ _Objects_Maximum_per_allocation( max ) ]; \
0455 Objects_Information name##_Information = { \
0456   _Objects_Build_id( api, cls, 1, _Objects_Maximum_per_allocation( max ) ), \
0457   name##_Local_table, \
0458   _Objects_Is_unlimited( max ) ? \
0459     _Objects_Allocate_unlimited : _Objects_Allocate_static, \
0460   _Objects_Is_unlimited( max ) ? \
0461     _Objects_Free_unlimited : _Objects_Free_static, \
0462   0, \
0463   _Objects_Is_unlimited( max ) ? _Objects_Maximum_per_allocation( max ) : 0, \
0464   sizeof( type ), \
0465   nl, \
0466   CHAIN_INITIALIZER_EMPTY( name##_Information.Inactive ), \
0467   NULL, \
0468   NULL, \
0469   &name##_Objects[ 0 ].Object \
0470   OBJECTS_INFORMATION_MP( name##_Information, ex ) \
0471 }
0472 
0473 /** @} */
0474 
0475 #ifdef __cplusplus
0476 }
0477 #endif
0478 
0479 #endif
0480 /* end of include file */