ChibiOS/RT  5.1.0
Dynamic Objects Factory
Collaboration diagram for Dynamic Objects Factory:

Detailed Description

The object factory is a subsystem that allows to:

Allocated OS objects are handled using a reference counter, only when all references have been released then the object memory is freed in a pool.

Precondition
This subsystem requires the CH_CFG_USE_MEMCORE and CH_CFG_USE_MEMPOOLS options to be set to TRUE. The option CH_CFG_USE_HEAP is also required if the support for variable length objects is enabled.
Note
Compatible with RT and NIL.

Macros

#define CH_CFG_FACTORY_MAX_NAMES_LENGTH   8
 Maximum length for object names. More...
 
#define CH_CFG_FACTORY_OBJECTS_REGISTRY   TRUE
 Enables the registry of generic objects. More...
 
#define CH_CFG_FACTORY_GENERIC_BUFFERS   TRUE
 Enables factory for generic buffers. More...
 
#define CH_CFG_FACTORY_SEMAPHORES   TRUE
 Enables factory for semaphores. More...
 
#define CH_CFG_FACTORY_SEMAPHORES   FALSE
 Enables factory for semaphores. More...
 
#define CH_CFG_FACTORY_MAILBOXES   TRUE
 Enables factory for mailboxes. More...
 
#define CH_CFG_FACTORY_MAILBOXES   FALSE
 Enables factory for mailboxes. More...
 
#define CH_CFG_FACTORY_OBJ_FIFOS   TRUE
 Enables factory for objects FIFOs. More...
 
#define CH_CFG_FACTORY_OBJ_FIFOS   FALSE
 Enables factory for objects FIFOs. More...
 

Typedefs

typedef struct ch_dyn_element dyn_element_t
 Type of a dynamic object list element. More...
 
typedef struct ch_dyn_list dyn_list_t
 Type of a dynamic object list. More...
 
typedef struct ch_registered_static_object registered_object_t
 Type of a registered object. More...
 
typedef struct ch_dyn_object dyn_buffer_t
 Type of a dynamic buffer object. More...
 
typedef struct ch_dyn_semaphore dyn_semaphore_t
 Type of a dynamic semaphore. More...
 
typedef struct ch_dyn_mailbox dyn_mailbox_t
 Type of a dynamic buffer object. More...
 
typedef struct ch_dyn_objects_fifo dyn_objects_fifo_t
 Type of a dynamic buffer object. More...
 
typedef struct ch_objects_factory objects_factory_t
 Type of the factory main object. More...
 

Data Structures

struct  ch_dyn_element
 Type of a dynamic object list element. More...
 
struct  ch_dyn_list
 Type of a dynamic object list. More...
 
struct  ch_registered_static_object
 Type of a registered object. More...
 
struct  ch_dyn_object
 Type of a dynamic buffer object. More...
 
struct  ch_dyn_semaphore
 Type of a dynamic semaphore. More...
 
struct  ch_dyn_mailbox
 Type of a dynamic buffer object. More...
 
struct  ch_dyn_objects_fifo
 Type of a dynamic buffer object. More...
 
struct  ch_objects_factory
 Type of the factory main object. More...
 

Functions

void _factory_init (void)
 Initializes the objects factory. More...
 
registered_object_tchFactoryRegisterObject (const char *name, void *objp)
 Registers a generic object. More...
 
registered_object_tchFactoryFindObject (const char *name)
 Retrieves a registered object. More...
 
registered_object_tchFactoryFindObjectByPointer (void *objp)
 Retrieves a registered object by pointer. More...
 
void chFactoryReleaseObject (registered_object_t *rop)
 Releases a registered object. More...
 
dyn_buffer_tchFactoryCreateBuffer (const char *name, size_t size)
 Creates a generic dynamic buffer object. More...
 
dyn_buffer_tchFactoryFindBuffer (const char *name)
 Retrieves a dynamic buffer object. More...
 
void chFactoryReleaseBuffer (dyn_buffer_t *dbp)
 Releases a dynamic buffer object. More...
 
dyn_semaphore_tchFactoryCreateSemaphore (const char *name, cnt_t n)
 Creates a dynamic semaphore object. More...
 
dyn_semaphore_tchFactoryFindSemaphore (const char *name)
 Retrieves a dynamic semaphore object. More...
 
void chFactoryReleaseSemaphore (dyn_semaphore_t *dsp)
 Releases a dynamic semaphore object. More...
 
dyn_mailbox_tchFactoryCreateMailbox (const char *name, size_t n)
 Creates a dynamic mailbox object. More...
 
dyn_mailbox_tchFactoryFindMailbox (const char *name)
 Retrieves a dynamic mailbox object. More...
 
void chFactoryReleaseMailbox (dyn_mailbox_t *dmp)
 Releases a dynamic mailbox object. More...
 
dyn_objects_fifo_tchFactoryCreateObjectsFIFO (const char *name, size_t objsize, size_t objn, unsigned objalign)
 Creates a dynamic "objects FIFO" object. More...
 
dyn_objects_fifo_tchFactoryFindObjectsFIFO (const char *name)
 Retrieves a dynamic "objects FIFO" object. More...
 
void chFactoryReleaseObjectsFIFO (dyn_objects_fifo_t *dofp)
 Releases a dynamic "objects FIFO" object. More...
 
static dyn_element_tchFactoryDuplicateReference (dyn_element_t *dep)
 Duplicates an object reference. More...
 
static void * chFactoryGetObject (registered_object_t *rop)
 Returns the pointer to the inner registered object. More...
 
static size_t chFactoryGetBufferSize (dyn_buffer_t *dbp)
 Returns the size of a generic dynamic buffer object. More...
 
static uint8_t * chFactoryGetBuffer (dyn_buffer_t *dbp)
 Returns the pointer to the inner buffer. More...
 
static semaphore_tchFactoryGetSemaphore (dyn_semaphore_t *dsp)
 Returns the pointer to the inner semaphore. More...
 
static mailbox_tchFactoryGetMailbox (dyn_mailbox_t *dmp)
 Returns the pointer to the inner mailbox. More...
 
static objects_fifo_tchFactoryGetObjectsFIFO (dyn_objects_fifo_t *dofp)
 Returns the pointer to the inner objects FIFO. More...
 

Variables

objects_factory_t ch_factory
 Factory object static instance. More...
 

Macro Definition Documentation

#define CH_CFG_FACTORY_MAX_NAMES_LENGTH   8

Maximum length for object names.

If the specified length is zero then the name is stored by pointer but this could have unintended side effects.

Definition at line 51 of file chfactory.h.

#define CH_CFG_FACTORY_OBJECTS_REGISTRY   TRUE

Enables the registry of generic objects.

Definition at line 58 of file chfactory.h.

#define CH_CFG_FACTORY_GENERIC_BUFFERS   TRUE

Enables factory for generic buffers.

Definition at line 65 of file chfactory.h.

#define CH_CFG_FACTORY_SEMAPHORES   TRUE

Enables factory for semaphores.

Definition at line 96 of file chfactory.h.

#define CH_CFG_FACTORY_SEMAPHORES   FALSE

Enables factory for semaphores.

Definition at line 96 of file chfactory.h.

#define CH_CFG_FACTORY_MAILBOXES   TRUE

Enables factory for mailboxes.

Definition at line 103 of file chfactory.h.

#define CH_CFG_FACTORY_MAILBOXES   FALSE

Enables factory for mailboxes.

Definition at line 103 of file chfactory.h.

#define CH_CFG_FACTORY_OBJ_FIFOS   TRUE

Enables factory for objects FIFOs.

Definition at line 110 of file chfactory.h.

#define CH_CFG_FACTORY_OBJ_FIFOS   FALSE

Enables factory for objects FIFOs.

Definition at line 110 of file chfactory.h.

Typedef Documentation

typedef struct ch_dyn_element dyn_element_t

Type of a dynamic object list element.

typedef struct ch_dyn_list dyn_list_t

Type of a dynamic object list.

Type of a registered object.

typedef struct ch_dyn_object dyn_buffer_t

Type of a dynamic buffer object.

Type of a dynamic semaphore.

typedef struct ch_dyn_mailbox dyn_mailbox_t

Type of a dynamic buffer object.

Type of a dynamic buffer object.

Type of the factory main object.

Function Documentation

void _factory_init ( void  )

Initializes the objects factory.

Function Class:
Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 245 of file chfactory.c.

References ch_objects_factory::buf_list, chCoreAllocAlignedI(), chMtxObjectInit(), chPoolObjectInit(), chSemObjectInit(), ch_objects_factory::fifo_list, ch_objects_factory::mbx_list, ch_objects_factory::mtx, ch_objects_factory::obj_list, ch_objects_factory::obj_pool, ch_objects_factory::sem_list, and ch_objects_factory::sem_pool.

Referenced by chSysInit().

Here is the call graph for this function:

registered_object_t * chFactoryRegisterObject ( const char *  name,
void *  objp 
)

Registers a generic object.

Postcondition
A reference to the registered object is returned and the reference counter is initialized to one.
Parameters
[in]namename to be assigned to the registered object
[in]objppointer to the object to be registered
Returns
The reference to the registered object.
Return values
NULLif the object to be registered cannot be allocated or a registered object with the same name exists.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 291 of file chfactory.c.

References ch_objects_factory::obj_list, ch_objects_factory::obj_pool, and ch_registered_static_object::objp.

registered_object_t * chFactoryFindObject ( const char *  name)

Retrieves a registered object.

Postcondition
A reference to the registered object is returned with the reference counter increased by one.
Parameters
[in]namename of the registered object
Returns
The reference to the found registered object.
Return values
NULLif a registered object with the specified name does not exist.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 323 of file chfactory.c.

References ch_objects_factory::obj_list.

registered_object_t * chFactoryFindObjectByPointer ( void *  objp)

Retrieves a registered object by pointer.

Postcondition
A reference to the registered object is returned with the reference counter increased by one.
Parameters
[in]objppointer to the object to be retrieved
Returns
The reference to the found registered object.
Return values
NULLif a registered object with the specified pointer does not exist.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 348 of file chfactory.c.

References ch_registered_static_object::element, ch_dyn_element::next, ch_objects_factory::obj_list, ch_registered_static_object::objp, and ch_dyn_element::refs.

void chFactoryReleaseObject ( registered_object_t rop)

Releases a registered object.

The reference counter of the registered object is decreased by one, if reaches zero then the registered object memory is freed.

Note
The object itself is not freed, it could be static, only the allocated list element is freed.
Parameters
[in]ropregistered object reference
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 381 of file chfactory.c.

References ch_registered_static_object::element, ch_objects_factory::obj_list, and ch_objects_factory::obj_pool.

dyn_buffer_t * chFactoryCreateBuffer ( const char *  name,
size_t  size 
)

Creates a generic dynamic buffer object.

Postcondition
A reference to the dynamic buffer object is returned and the reference counter is initialized to one.
The dynamic buffer object is filled with zeros.
Parameters
[in]namename to be assigned to the new dynamic buffer object
[in]sizepayload size of the dynamic buffer object to be created
Returns
The reference to the created dynamic buffer object.
Return values
NULLif the dynamic buffer object cannot be allocated or a dynamic buffer object with the same name exists.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 409 of file chfactory.c.

References ch_objects_factory::buf_list, and ch_dyn_object::buffer.

dyn_buffer_t * chFactoryFindBuffer ( const char *  name)

Retrieves a dynamic buffer object.

Postcondition
A reference to the dynamic buffer object is returned with the reference counter increased by one.
Parameters
[in]namename of the dynamic buffer object
Returns
The reference to the found dynamic buffer object.
Return values
NULLif a dynamic buffer object with the specified name does not exist.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 440 of file chfactory.c.

References ch_objects_factory::buf_list.

void chFactoryReleaseBuffer ( dyn_buffer_t dbp)

Releases a dynamic buffer object.

The reference counter of the dynamic buffer object is decreased by one, if reaches zero then the dynamic buffer object memory is freed.

Parameters
[in]dbpdynamic buffer object reference
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 462 of file chfactory.c.

References ch_objects_factory::buf_list, and ch_dyn_object::element.

dyn_semaphore_t * chFactoryCreateSemaphore ( const char *  name,
cnt_t  n 
)

Creates a dynamic semaphore object.

Postcondition
A reference to the dynamic semaphore object is returned and the reference counter is initialized to one.
The dynamic semaphore object is initialized and ready to use.
Parameters
[in]namename to be assigned to the new dynamic semaphore object
[in]ndynamic semaphore object counter initialization value
Returns
The reference to the created dynamic semaphore object.
Return values
NULLif the dynamic semaphore object cannot be allocated or a dynamic semaphore with the same name exists.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 488 of file chfactory.c.

References chSemObjectInit(), ch_dyn_semaphore::sem, ch_objects_factory::sem_list, and ch_objects_factory::sem_pool.

Here is the call graph for this function:

dyn_semaphore_t * chFactoryFindSemaphore ( const char *  name)

Retrieves a dynamic semaphore object.

Postcondition
A reference to the dynamic semaphore object is returned with the reference counter increased by one.
Parameters
[in]namename of the dynamic semaphore object
Returns
The reference to the found dynamic semaphore object.
Return values
NULLif a dynamic semaphore object with the specified name does not exist.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 519 of file chfactory.c.

References ch_objects_factory::sem_list.

void chFactoryReleaseSemaphore ( dyn_semaphore_t dsp)

Releases a dynamic semaphore object.

The reference counter of the dynamic semaphore object is decreased by one, if reaches zero then the dynamic semaphore object memory is freed.

Parameters
[in]dspdynamic semaphore object reference
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 541 of file chfactory.c.

References ch_dyn_semaphore::element, ch_objects_factory::sem_list, and ch_objects_factory::sem_pool.

dyn_mailbox_t * chFactoryCreateMailbox ( const char *  name,
size_t  n 
)

Creates a dynamic mailbox object.

Postcondition
A reference to the dynamic mailbox object is returned and the reference counter is initialized to one.
The dynamic mailbox object is initialized and ready to use.
Parameters
[in]namename to be assigned to the new dynamic mailbox object
[in]nmailbox buffer size as number of messages
Returns
The reference to the created dynamic mailbox object.
Return values
NULLif the dynamic mailbox object cannot be allocated or a dynamic mailbox object with the same name exists.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 569 of file chfactory.c.

References chMBObjectInit(), ch_dyn_mailbox::mbx, ch_objects_factory::mbx_list, and ch_dyn_mailbox::msgbuf.

Here is the call graph for this function:

dyn_mailbox_t * chFactoryFindMailbox ( const char *  name)

Retrieves a dynamic mailbox object.

Postcondition
A reference to the dynamic mailbox object is returned with the reference counter increased by one.
Parameters
[in]namename of the dynamic mailbox object
Returns
The reference to the found dynamic mailbox object.
Return values
NULLif a dynamic mailbox object with the specified name does not exist.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 601 of file chfactory.c.

References ch_objects_factory::mbx_list.

void chFactoryReleaseMailbox ( dyn_mailbox_t dmp)

Releases a dynamic mailbox object.

The reference counter of the dynamic mailbox object is decreased by one, if reaches zero then the dynamic mailbox object memory is freed.

Parameters
[in]dmpdynamic mailbox object reference
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 623 of file chfactory.c.

References ch_dyn_mailbox::element, and ch_objects_factory::mbx_list.

dyn_objects_fifo_t * chFactoryCreateObjectsFIFO ( const char *  name,
size_t  objsize,
size_t  objn,
unsigned  objalign 
)

Creates a dynamic "objects FIFO" object.

Postcondition
A reference to the dynamic "objects FIFO" object is returned and the reference counter is initialized to one.
The dynamic "objects FIFO" object is initialized and ready to use.
Parameters
[in]namename to be assigned to the new dynamic "objects FIFO" object
[in]objsizesize of objects
[in]objnnumber of objects available
[in]objalignrequired objects alignment
Returns
The reference to the created dynamic "objects FIFO" object.
Return values
NULLif the dynamic "objects FIFO" object cannot be allocated or a dynamic "objects FIFO" object with the same name exists.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 653 of file chfactory.c.

References chFifoObjectInit(), ch_dyn_objects_fifo::fifo, ch_objects_factory::fifo_list, and ch_dyn_objects_fifo::msgbuf.

Here is the call graph for this function:

dyn_objects_fifo_t * chFactoryFindObjectsFIFO ( const char *  name)

Retrieves a dynamic "objects FIFO" object.

Postcondition
A reference to the dynamic "objects FIFO" object is returned with the reference counter increased by one.
Parameters
[in]namename of the dynamic "objects FIFO" object
Returns
The reference to the found dynamic "objects FIFO" object.
Return values
NULLif a dynamic "objects FIFO" object with the specified name does not exist.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 691 of file chfactory.c.

References ch_objects_factory::fifo_list.

void chFactoryReleaseObjectsFIFO ( dyn_objects_fifo_t dofp)

Releases a dynamic "objects FIFO" object.

The reference counter of the dynamic "objects FIFO" object is decreased by one, if reaches zero then the dynamic "objects FIFO" object memory is freed.

Parameters
[in]dofpdynamic "objects FIFO" object reference
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 713 of file chfactory.c.

References ch_dyn_objects_fifo::element, and ch_objects_factory::fifo_list.

static dyn_element_t* chFactoryDuplicateReference ( dyn_element_t dep)
inlinestatic

Duplicates an object reference.

Note
This function can be used on any kind of dynamic object.
Parameters
[in]deppointer to the element field of the object
Returns
The duplicated object reference.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 387 of file chfactory.h.

References ch_dyn_element::refs.

static void* chFactoryGetObject ( registered_object_t rop)
inlinestatic

Returns the pointer to the inner registered object.

Parameters
[in]ropregistered object reference
Returns
The pointer to the registered object.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 403 of file chfactory.h.

References ch_registered_static_object::objp.

static size_t chFactoryGetBufferSize ( dyn_buffer_t dbp)
inlinestatic

Returns the size of a generic dynamic buffer object.

Parameters
[in]dbpdynamic buffer object reference
Returns
The size of the buffer object in bytes.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 418 of file chfactory.h.

References chHeapGetSize().

Here is the call graph for this function:

static uint8_t* chFactoryGetBuffer ( dyn_buffer_t dbp)
inlinestatic

Returns the pointer to the inner buffer.

Parameters
[in]dbpdynamic buffer object reference
Returns
The pointer to the dynamic buffer.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 431 of file chfactory.h.

References ch_dyn_object::buffer.

static semaphore_t* chFactoryGetSemaphore ( dyn_semaphore_t dsp)
inlinestatic

Returns the pointer to the inner semaphore.

Parameters
[in]dspdynamic semaphore object reference
Returns
The pointer to the semaphore.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 446 of file chfactory.h.

References ch_dyn_semaphore::sem.

static mailbox_t* chFactoryGetMailbox ( dyn_mailbox_t dmp)
inlinestatic

Returns the pointer to the inner mailbox.

Parameters
[in]dmpdynamic mailbox object reference
Returns
The pointer to the mailbox.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 461 of file chfactory.h.

References ch_dyn_mailbox::mbx.

static objects_fifo_t* chFactoryGetObjectsFIFO ( dyn_objects_fifo_t dofp)
inlinestatic

Returns the pointer to the inner objects FIFO.

Parameters
[in]dofpdynamic "objects FIFO" object reference
Returns
The pointer to the objects FIFO.
Function Class:
Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 476 of file chfactory.h.

References ch_dyn_objects_fifo::fifo.

Variable Documentation

objects_factory_t ch_factory

Factory object static instance.

Note
It is a global object because it could be accessed through a specific debugger plugin.

Definition at line 72 of file chfactory.c.