ChibiOS/RT  5.1.0
chfactory.c
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio.
3 
4  This file is part of ChibiOS.
5 
6  ChibiOS is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 3 of the License, or
9  (at your option) any later version.
10 
11  ChibiOS is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 /**
21  * @file chfactory.c
22  * @brief ChibiOS objects factory and registry code.
23  *
24  * @addtogroup objects_factory
25  * @details The object factory is a subsystem that allows to:
26  * - Register static objects by name.
27  * - Dynamically create objects and assign them a name.
28  * - Retrieve existing objects by name.
29  * - Free objects by reference.
30  * .
31  * Allocated OS objects are handled using a reference counter, only
32  * when all references have been released then the object memory is
33  * freed in a pool.<br>
34  * @pre This subsystem requires the @p CH_CFG_USE_MEMCORE and
35  * @p CH_CFG_USE_MEMPOOLS options to be set to @p TRUE. The
36  * option @p CH_CFG_USE_HEAP is also required if the support
37  * for variable length objects is enabled.
38  * @note Compatible with RT and NIL.
39  * @{
40  */
41 
42 #include <string.h>
43 
44 #include "ch.h"
45 
46 #if (CH_CFG_USE_FACTORY == TRUE) || defined(__DOXYGEN__)
47 
48 /*===========================================================================*/
49 /* Module local definitions. */
50 /*===========================================================================*/
51 
52 /*
53  * Defaults on the best synchronization mechanism available.
54  */
55 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
56 #define F_LOCK() chMtxLock(&ch_factory.mtx)
57 #define F_UNLOCK() chMtxUnlock(&ch_factory.mtx)
58 #else
59 #define F_LOCK() (void) chSemWait(&ch_factory.sem)
60 #define F_UNLOCK() chSemSignal(&ch_factory.sem)
61 #endif
62 
63 /*===========================================================================*/
64 /* Module exported variables. */
65 /*===========================================================================*/
66 
67 /**
68  * @brief Factory object static instance.
69  * @note It is a global object because it could be accessed through
70  * a specific debugger plugin.
71  */
73 
74 /*===========================================================================*/
75 /* Module local types. */
76 /*===========================================================================*/
77 
78 /*===========================================================================*/
79 /* Module local variables. */
80 /*===========================================================================*/
81 
82 /*===========================================================================*/
83 /* Module local functions. */
84 /*===========================================================================*/
85 
86 static inline void dyn_list_init(dyn_list_t *dlp) {
87 
88  dlp->next = (dyn_element_t *)dlp;
89 }
90 
91 static dyn_element_t *dyn_list_find(const char *name, dyn_list_t *dlp) {
92  dyn_element_t *p = dlp->next;
93 
94  while (p != (dyn_element_t *)dlp) {
95  if (strncmp(p->name, name, CH_CFG_FACTORY_MAX_NAMES_LENGTH) == 0) {
96  return p;
97  }
98  p = p->next;
99  }
100 
101  return NULL;
102 }
103 
104 static dyn_element_t *dyn_list_unlink(dyn_element_t *element,
105  dyn_list_t *dlp) {
106  dyn_element_t *prev = (dyn_element_t *)dlp;
107 
108  /* Scanning the list.*/
109  while (prev->next != (dyn_element_t *)dlp) {
110  if (prev->next == element) {
111  /* Found.*/
112  prev->next = element->next;
113  return element;
114  }
115 
116  /* Next element in the list.*/
117  prev = prev->next;
118  }
119 
120  return NULL;
121 }
122 
123 #if CH_FACTORY_REQUIRES_HEAP || defined(__DOXYGEN__)
124 static dyn_element_t *dyn_create_object_heap(const char *name,
125  dyn_list_t *dlp,
126  size_t size) {
127  dyn_element_t *dep;
128 
129  chDbgCheck(name != NULL);
130 
131  /* Checking if an object with this name has already been created.*/
132  dep = dyn_list_find(name, dlp);
133  if (dep != NULL) {
134  return NULL;
135  }
136 
137  /* Allocating space for the new buffer object.*/
138  /*lint -save -e668 [] Lint is confused by the above chDbgCheck() and
139  incorrectly assumes that strncpy() could receive a NULL pointer.*/
140  dep = (dyn_element_t *)chHeapAlloc(NULL, size);
141  if (dep == NULL) {
142  return NULL;
143  }
144 
145  /* Initializing object list element.*/
146  strncpy(dep->name, name, CH_CFG_FACTORY_MAX_NAMES_LENGTH);
147  /*lint -restore*/
148  dep->refs = (ucnt_t)1;
149  dep->next = dlp->next;
150 
151  /* Updating factory list.*/
152  dlp->next = dep;
153 
154  return dep;
155 }
156 
157 static void dyn_release_object_heap(dyn_element_t *dep,
158  dyn_list_t *dlp) {
159 
160  chDbgCheck(dep != NULL);
161  chDbgAssert(dep->refs > (ucnt_t)0, "invalid references number");
162 
163 
164  dep->refs--;
165  if (dep->refs == (ucnt_t)0) {
166  dep = dyn_list_unlink(dep, dlp);
167  chHeapFree((void *)dep);
168  }
169 }
170 #endif /* CH_FACTORY_REQUIRES_HEAP */
171 
172 #if CH_FACTORY_REQUIRES_POOLS || defined(__DOXYGEN__)
173 static dyn_element_t *dyn_create_object_pool(const char *name,
174  dyn_list_t *dlp,
175  memory_pool_t *mp) {
176  dyn_element_t *dep;
177 
178  chDbgCheck(name != NULL);
179 
180  /* Checking if an object object with this name has already been created.*/
181  dep = dyn_list_find(name, dlp);
182  if (dep != NULL) {
183  return NULL;
184  }
185 
186  /* Allocating space for the new object.*/
187  dep = (dyn_element_t *)chPoolAlloc(mp);
188  if (dep == NULL) {
189  return NULL;
190  }
191 
192  /* Initializing object list element.*/
193  /*lint -save -e668 [] Lint is confused by the above chDbgCheck() and
194  incorrectly assumes that strncpy() could receive a NULL pointer.*/
195  strncpy(dep->name, name, CH_CFG_FACTORY_MAX_NAMES_LENGTH);
196  /*lint -restore*/
197  dep->refs = (ucnt_t)1;
198  dep->next = dlp->next;
199 
200  /* Updating factory list.*/
201  dlp->next = (dyn_element_t *)dep;
202 
203  return dep;
204 }
205 
206 static void dyn_release_object_pool(dyn_element_t *dep,
207  dyn_list_t *dlp,
208  memory_pool_t *mp) {
209 
210  chDbgCheck(dep != NULL);
211  chDbgAssert(dep->refs > (ucnt_t)0, "invalid references number");
212 
213  dep->refs--;
214  if (dep->refs == (ucnt_t)0) {
215  dep = dyn_list_unlink(dep, dlp);
216  chPoolFree(mp, (void *)dep);
217  }
218 }
219 #endif /* CH_FACTORY_REQUIRES_POOLS */
220 
221 static dyn_element_t *dyn_find_object(const char *name, dyn_list_t *dlp) {
222  dyn_element_t *dep;
223 
224  chDbgCheck(name != NULL);
225 
226  /* Checking if an object with this name has already been created.*/
227  dep = dyn_list_find(name, dlp);
228  if (dep != NULL) {
229  /* Increasing references counter.*/
230  dep->refs++;
231  }
232 
233  return dep;
234 }
235 
236 /*===========================================================================*/
237 /* Module exported functions. */
238 /*===========================================================================*/
239 
240 /**
241  * @brief Initializes the objects factory.
242  *
243  * @init
244  */
245 void _factory_init(void) {
246 
247 #if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
248  chMtxObjectInit(&ch_factory.mtx);
249 #else
250  chSemObjectInit(&ch_factory.sem, (cnt_t)1);
251 #endif
252 
253 #if CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE
254  dyn_list_init(&ch_factory.obj_list);
255  chPoolObjectInit(&ch_factory.obj_pool,
256  sizeof (registered_object_t),
258 #endif
259 #if CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE
260  dyn_list_init(&ch_factory.buf_list);
261 #endif
262 #if CH_CFG_FACTORY_SEMAPHORES == TRUE
263  dyn_list_init(&ch_factory.sem_list);
264  chPoolObjectInit(&ch_factory.sem_pool,
265  sizeof (dyn_semaphore_t),
267 #endif
268 #if CH_CFG_FACTORY_MAILBOXES == TRUE
269  dyn_list_init(&ch_factory.mbx_list);
270 #endif
271 #if CH_CFG_FACTORY_OBJ_FIFOS == TRUE
272  dyn_list_init(&ch_factory.fifo_list);
273 #endif
274 }
275 
276 #if (CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE) || defined(__DOXIGEN__)
277 /**
278  * @brief Registers a generic object.
279  * @post A reference to the registered object is returned and the
280  * reference counter is initialized to one.
281  *
282  * @param[in] name name to be assigned to the registered object
283  * @param[in] objp pointer to the object to be registered
284  *
285  * @return The reference to the registered object.
286  * @retval NULL if the object to be registered cannot be allocated or
287  * a registered object with the same name exists.
288  *
289  * @api
290  */
292  void *objp) {
293  registered_object_t *rop;
294 
295  F_LOCK();
296 
297  rop = (registered_object_t *)dyn_create_object_pool(name,
298  &ch_factory.obj_list,
299  &ch_factory.obj_pool);
300  if (rop != NULL) {
301  /* Initializing registered object data.*/
302  rop->objp = objp;
303  }
304 
305  F_UNLOCK();
306 
307  return rop;
308 }
309 
310 /**
311  * @brief Retrieves a registered object.
312  * @post A reference to the registered object is returned with the
313  * reference counter increased by one.
314  *
315  * @param[in] name name of the registered object
316  *
317  * @return The reference to the found registered object.
318  * @retval NULL if a registered object with the specified name
319  * does not exist.
320  *
321  * @api
322  */
324  registered_object_t *rop;
325 
326  F_LOCK();
327 
328  rop = (registered_object_t *)dyn_find_object(name, &ch_factory.obj_list);
329 
330  F_UNLOCK();
331 
332  return rop;
333 }
334 
335 /**
336  * @brief Retrieves a registered object by pointer.
337  * @post A reference to the registered object is returned with the
338  * reference counter increased by one.
339  *
340  * @param[in] objp pointer to the object to be retrieved
341  *
342  * @return The reference to the found registered object.
343  * @retval NULL if a registered object with the specified pointer
344  * does not exist.
345  *
346  * @api
347  */
349  registered_object_t *rop = (registered_object_t *)ch_factory.obj_list.next;
350 
351  F_LOCK();
352 
353  while ((void *)rop != (void *)&ch_factory.obj_list) {
354  if (rop->objp == objp) {
355  rop->element.refs++;
356 
357  F_UNLOCK();
358 
359  return rop;
360  }
361  rop = (registered_object_t *)rop->element.next;
362  }
363 
364  F_UNLOCK();
365 
366  return NULL;
367 }
368 
369 /**
370  * @brief Releases a registered object.
371  * @details The reference counter of the registered object is decreased
372  * by one, if reaches zero then the registered object memory
373  * is freed.
374  * @note The object itself is not freed, it could be static, only the
375  * allocated list element is freed.
376  *
377  * @param[in] rop registered object reference
378  *
379  * @api
380  */
382 
383  F_LOCK();
384 
385  dyn_release_object_pool(&rop->element,
386  &ch_factory.obj_list,
387  &ch_factory.obj_pool);
388 
389  F_UNLOCK();
390 }
391 #endif /* CH_CFG_FACTORY_OBJECTS_REGISTRY == TRUE */
392 
393 #if (CH_CFG_FACTORY_GENERIC_BUFFERS == TRUE) || defined(__DOXIGEN__)
394 /**
395  * @brief Creates a generic dynamic buffer object.
396  * @post A reference to the dynamic buffer object is returned and the
397  * reference counter is initialized to one.
398  * @post The dynamic buffer object is filled with zeros.
399  *
400  * @param[in] name name to be assigned to the new dynamic buffer object
401  * @param[in] size payload size of the dynamic buffer object to be created
402  *
403  * @return The reference to the created dynamic buffer object.
404  * @retval NULL if the dynamic buffer object cannot be allocated or
405  * a dynamic buffer object with the same name exists.
406  *
407  * @api
408  */
409 dyn_buffer_t *chFactoryCreateBuffer(const char *name, size_t size) {
410  dyn_buffer_t *dbp;
411 
412  F_LOCK();
413 
414  dbp = (dyn_buffer_t *)dyn_create_object_heap(name,
415  &ch_factory.buf_list,
416  size);
417  if (dbp != NULL) {
418  /* Initializing buffer object data.*/
419  memset((void *)dbp->buffer, 0, size);
420  }
421 
422  F_UNLOCK();
423 
424  return dbp;
425 }
426 
427 /**
428  * @brief Retrieves a dynamic buffer object.
429  * @post A reference to the dynamic buffer object is returned with the
430  * reference counter increased by one.
431  *
432  * @param[in] name name of the dynamic buffer object
433  *
434  * @return The reference to the found dynamic buffer object.
435  * @retval NULL if a dynamic buffer object with the specified name
436  * does not exist.
437  *
438  * @api
439  */
440 dyn_buffer_t *chFactoryFindBuffer(const char *name) {
441  dyn_buffer_t *dbp;
442 
443  F_LOCK();
444 
445  dbp = (dyn_buffer_t *)dyn_find_object(name, &ch_factory.buf_list);
446 
447  F_UNLOCK();
448 
449  return dbp;
450 }
451 
452 /**
453  * @brief Releases a dynamic buffer object.
454  * @details The reference counter of the dynamic buffer object is decreased
455  * by one, if reaches zero then the dynamic buffer object memory
456  * is freed.
457  *
458  * @param[in] dbp dynamic buffer object reference
459  *
460  * @api
461  */
463 
464  F_LOCK();
465 
466  dyn_release_object_heap(&dbp->element, &ch_factory.buf_list);
467 
468  F_UNLOCK();
469 }
470 #endif /* CH_CFG_FACTORY_GENERIC_BUFFERS = TRUE */
471 
472 #if (CH_CFG_FACTORY_SEMAPHORES == TRUE) || defined(__DOXIGEN__)
473 /**
474  * @brief Creates a dynamic semaphore object.
475  * @post A reference to the dynamic semaphore object is returned and the
476  * reference counter is initialized to one.
477  * @post The dynamic semaphore object is initialized and ready to use.
478  *
479  * @param[in] name name to be assigned to the new dynamic semaphore object
480  * @param[in] n dynamic semaphore object counter initialization value
481  *
482  * @return The reference to the created dynamic semaphore object.
483  * @retval NULL if the dynamic semaphore object cannot be allocated or
484  * a dynamic semaphore with the same name exists.
485  *
486  * @api
487  */
488 dyn_semaphore_t *chFactoryCreateSemaphore(const char *name, cnt_t n) {
489  dyn_semaphore_t *dsp;
490 
491  F_LOCK();
492 
493  dsp = (dyn_semaphore_t *)dyn_create_object_pool(name,
494  &ch_factory.sem_list,
495  &ch_factory.sem_pool);
496  if (dsp != NULL) {
497  /* Initializing semaphore object dataa.*/
498  chSemObjectInit(&dsp->sem, n);
499  }
500 
501  F_UNLOCK();
502 
503  return dsp;
504 }
505 
506 /**
507  * @brief Retrieves a dynamic semaphore object.
508  * @post A reference to the dynamic semaphore object is returned with the
509  * reference counter increased by one.
510  *
511  * @param[in] name name of the dynamic semaphore object
512  *
513  * @return The reference to the found dynamic semaphore object.
514  * @retval NULL if a dynamic semaphore object with the specified name
515  * does not exist.
516  *
517  * @api
518  */
520  dyn_semaphore_t *dsp;
521 
522  F_LOCK();
523 
524  dsp = (dyn_semaphore_t *)dyn_find_object(name, &ch_factory.sem_list);
525 
526  F_UNLOCK();
527 
528  return dsp;
529 }
530 
531 /**
532  * @brief Releases a dynamic semaphore object.
533  * @details The reference counter of the dynamic semaphore object is decreased
534  * by one, if reaches zero then the dynamic semaphore object memory
535  * is freed.
536  *
537  * @param[in] dsp dynamic semaphore object reference
538  *
539  * @api
540  */
542 
543  F_LOCK();
544 
545  dyn_release_object_pool(&dsp->element,
546  &ch_factory.sem_list,
547  &ch_factory.sem_pool);
548 
549  F_UNLOCK();
550 }
551 #endif /* CH_CFG_FACTORY_SEMAPHORES = TRUE */
552 
553 #if (CH_CFG_FACTORY_MAILBOXES == TRUE) || defined(__DOXIGEN__)
554 /**
555  * @brief Creates a dynamic mailbox object.
556  * @post A reference to the dynamic mailbox object is returned and the
557  * reference counter is initialized to one.
558  * @post The dynamic mailbox object is initialized and ready to use.
559  *
560  * @param[in] name name to be assigned to the new dynamic mailbox object
561  * @param[in] n mailbox buffer size as number of messages
562  *
563  * @return The reference to the created dynamic mailbox object.
564  * @retval NULL if the dynamic mailbox object cannot be allocated or
565  * a dynamic mailbox object with the same name exists.
566  *
567  * @api
568  */
569 dyn_mailbox_t *chFactoryCreateMailbox(const char *name, size_t n) {
570  dyn_mailbox_t *dmp;
571 
572  F_LOCK();
573 
574  dmp = (dyn_mailbox_t *)dyn_create_object_heap(name,
575  &ch_factory.mbx_list,
576  sizeof (dyn_mailbox_t) +
577  (n * sizeof (msg_t)));
578  if (dmp != NULL) {
579  /* Initializing mailbox object data.*/
580  chMBObjectInit(&dmp->mbx, dmp->msgbuf, n);
581  }
582 
583  F_UNLOCK();
584 
585  return dmp;
586 }
587 
588 /**
589  * @brief Retrieves a dynamic mailbox object.
590  * @post A reference to the dynamic mailbox object is returned with the
591  * reference counter increased by one.
592  *
593  * @param[in] name name of the dynamic mailbox object
594  *
595  * @return The reference to the found dynamic mailbox object.
596  * @retval NULL if a dynamic mailbox object with the specified name
597  * does not exist.
598  *
599  * @api
600  */
602  dyn_mailbox_t *dmp;
603 
604  F_LOCK();
605 
606  dmp = (dyn_mailbox_t *)dyn_find_object(name, &ch_factory.mbx_list);
607 
608  F_UNLOCK();
609 
610  return dmp;
611 }
612 
613 /**
614  * @brief Releases a dynamic mailbox object.
615  * @details The reference counter of the dynamic mailbox object is decreased
616  * by one, if reaches zero then the dynamic mailbox object memory
617  * is freed.
618  *
619  * @param[in] dmp dynamic mailbox object reference
620  *
621  * @api
622  */
624 
625  F_LOCK();
626 
627  dyn_release_object_heap(&dmp->element, &ch_factory.mbx_list);
628 
629  F_UNLOCK();
630 }
631 #endif /* CH_CFG_FACTORY_MAILBOXES = TRUE */
632 
633 #if (CH_CFG_FACTORY_OBJ_FIFOS == TRUE) || defined(__DOXIGEN__)
634 /**
635  * @brief Creates a dynamic "objects FIFO" object.
636  * @post A reference to the dynamic "objects FIFO" object is returned and
637  * the reference counter is initialized to one.
638  * @post The dynamic "objects FIFO" object is initialized and ready to use.
639  *
640  * @param[in] name name to be assigned to the new dynamic "objects FIFO"
641  * object
642  * @param[in] objsize size of objects
643  * @param[in] objn number of objects available
644  * @param[in] objalign required objects alignment
645  * @return The reference to the created dynamic "objects FIFO"
646  * object.
647  * @retval NULL if the dynamic "objects FIFO" object cannot be
648  * allocated or a dynamic "objects FIFO" object with
649  * the same name exists.
650  *
651  * @api
652  */
654  size_t objsize,
655  size_t objn,
656  unsigned objalign) {
657  dyn_objects_fifo_t *dofp;
658 
659  F_LOCK();
660 
661  dofp = (dyn_objects_fifo_t *)dyn_create_object_heap(name,
662  &ch_factory.fifo_list,
663  sizeof (dyn_objects_fifo_t) +
664  (objn * sizeof (msg_t)) +
665  (objn * objsize));
666  if (dofp != NULL) {
667  /* Initializing mailbox object data.*/
668  chFifoObjectInit(&dofp->fifo, objsize, objn, objalign,
669  (void *)&dofp->msgbuf[objn], dofp->msgbuf);
670  }
671 
672  F_UNLOCK();
673 
674  return dofp;
675 }
676 
677 /**
678  * @brief Retrieves a dynamic "objects FIFO" object.
679  * @post A reference to the dynamic "objects FIFO" object is returned with
680  * the reference counter increased by one.
681  *
682  * @param[in] name name of the dynamic "objects FIFO" object
683  *
684  * @return The reference to the found dynamic "objects FIFO"
685  * object.
686  * @retval NULL if a dynamic "objects FIFO" object with the specified
687  * name does not exist.
688  *
689  * @api
690  */
692  dyn_objects_fifo_t *dofp;
693 
694  F_LOCK();
695 
696  dofp = (dyn_objects_fifo_t *)dyn_find_object(name, &ch_factory.fifo_list);
697 
698  F_UNLOCK();
699 
700  return dofp;
701 }
702 
703 /**
704  * @brief Releases a dynamic "objects FIFO" object.
705  * @details The reference counter of the dynamic "objects FIFO" object is
706  * decreased by one, if reaches zero then the dynamic "objects FIFO"
707  * object memory is freed.
708  *
709  * @param[in] dofp dynamic "objects FIFO" object reference
710  *
711  * @api
712  */
714 
715  F_LOCK();
716 
717  dyn_release_object_heap(&dofp->element, &ch_factory.fifo_list);
718 
719  F_UNLOCK();
720 }
721 #endif /* CH_CFG_FACTORY_OBJ_FIFOS = TRUE */
722 
723 #endif /* CH_CFG_USE_FACTORY == TRUE */
724 
725 /** @} */
Memory pool descriptor.
Definition: chmempools.h:68
Type of a dynamic buffer object.
Definition: chfactory.h:230
static void chFifoObjectInit(objects_fifo_t *ofp, size_t objsize, size_t objn, unsigned objalign, void *objbuf, msg_t *msgbuf)
Initializes a FIFO object.
Definition: chfifo.h:132
mailbox_t mbx
The mailbox.
Definition: chfactory.h:238
static void chPoolObjectInit(memory_pool_t *mp, size_t size, memgetfunc_t provider)
Initializes an empty memory pool.
Definition: chmempools.h:193
dyn_element_t element
List element of the dynamic buffer object.
Definition: chfactory.h:234
void chPoolFree(memory_pool_t *mp, void *objp)
Releases an object into a memory pool.
Definition: chmempools.c:202
uint8_t buffer[]
The buffer.
Definition: chfactory.h:205
void _factory_init(void)
Initializes the objects factory.
Definition: chfactory.c:245
struct ch_dyn_element * next
Next dynamic object in the list.
Definition: chfactory.h:155
Type of a dynamic object list element.
Definition: chfactory.h:151
void chFactoryReleaseSemaphore(dyn_semaphore_t *dsp)
Releases a dynamic semaphore object.
Definition: chfactory.c:541
registered_object_t * chFactoryFindObject(const char *name)
Retrieves a registered object.
Definition: chfactory.c:323
void chHeapFree(void *p)
Frees a previously allocated memory block.
Definition: chheap.c:293
semaphore_t sem
The semaphore.
Definition: chfactory.h:222
Type of a dynamic buffer object.
Definition: chfactory.h:195
dyn_element_t element
List element of the dynamic semaphore.
Definition: chfactory.h:218
dyn_mailbox_t * chFactoryCreateMailbox(const char *name, size_t n)
Creates a dynamic mailbox object.
Definition: chfactory.c:569
void * chPoolAlloc(memory_pool_t *mp)
Allocates an object from a memory pool.
Definition: chmempools.c:155
msg_t msgbuf[]
Messages buffer.
Definition: chfactory.h:244
dyn_element_t element
List element of the dynamic buffer object.
Definition: chfactory.h:199
void chFactoryReleaseObjectsFIFO(dyn_objects_fifo_t *dofp)
Releases a dynamic "objects FIFO" object.
Definition: chfactory.c:713
Type of a dynamic semaphore.
Definition: chfactory.h:214
msg_t msgbuf[]
Messages buffer.
Definition: chfactory.h:269
#define chDbgCheck(c)
Function parameters check.
Definition: chdebug.h:101
dyn_mailbox_t * chFactoryFindMailbox(const char *name)
Retrieves a dynamic mailbox object.
Definition: chfactory.c:601
memory_pool_t sem_pool
Pool of the available semaphores.
Definition: chfactory.h:308
Type of a registered object.
Definition: chfactory.h:178
dyn_buffer_t * chFactoryCreateBuffer(const char *name, size_t size)
Creates a generic dynamic buffer object.
Definition: chfactory.c:409
registered_object_t * chFactoryRegisterObject(const char *name, void *objp)
Registers a generic object.
Definition: chfactory.c:291
ucnt_t refs
Number of references to this object.
Definition: chfactory.h:159
#define chDbgAssert(c, r)
Condition assertion.
Definition: chdebug.h:127
mutex_t mtx
Factory access mutex or semaphore.
Definition: chfactory.h:282
dyn_list_t buf_list
List of the allocated buffer objects.
Definition: chfactory.h:298
registered_object_t * chFactoryFindObjectByPointer(void *objp)
Retrieves a registered object by pointer.
Definition: chfactory.c:348
void chSemObjectInit(semaphore_t *sp, cnt_t n)
Initializes a semaphore with the specified counter value.
Definition: chsem.c:97
dyn_list_t sem_list
List of the allocated semaphores.
Definition: chfactory.h:304
dyn_semaphore_t * chFactoryCreateSemaphore(const char *name, cnt_t n)
Creates a dynamic semaphore object.
Definition: chfactory.c:488
static void * chHeapAlloc(memory_heap_t *heapp, size_t size)
Allocates a block of memory from the heap by using the first-fit algorithm.
Definition: chheap.h:158
dyn_objects_fifo_t * chFactoryCreateObjectsFIFO(const char *name, size_t objsize, size_t objn, unsigned objalign)
Creates a dynamic "objects FIFO" object.
Definition: chfactory.c:653
void chFactoryReleaseBuffer(dyn_buffer_t *dbp)
Releases a dynamic buffer object.
Definition: chfactory.c:462
dyn_list_t obj_list
List of the registered objects.
Definition: chfactory.h:289
void * objp
Pointer to the object.
Definition: chfactory.h:187
dyn_semaphore_t * chFactoryFindSemaphore(const char *name)
Retrieves a dynamic semaphore object.
Definition: chfactory.c:519
memory_pool_t obj_pool
Pool of the available registered objects.
Definition: chfactory.h:293
dyn_element_t element
List element of the dynamic buffer object.
Definition: chfactory.h:257
void chFactoryReleaseMailbox(dyn_mailbox_t *dmp)
Releases a dynamic mailbox object.
Definition: chfactory.c:623
dyn_buffer_t * chFactoryFindBuffer(const char *name)
Retrieves a dynamic buffer object.
Definition: chfactory.c:440
void chMtxObjectInit(mutex_t *mp)
Initializes s mutex_t structure.
Definition: chmtx.c:103
Type of a dynamic buffer object.
Definition: chfactory.h:253
ChibiOS/RT main include file.
dyn_element_t element
List element of the registered object.
Definition: chfactory.h:182
objects_fifo_t fifo
The objects FIFO.
Definition: chfactory.h:261
static void * chCoreAllocAlignedI(size_t size, unsigned align)
Allocates a memory block.
Definition: chmemcore.h:139
dyn_objects_fifo_t * chFactoryFindObjectsFIFO(const char *name)
Retrieves a dynamic "objects FIFO" object.
Definition: chfactory.c:691
void chFactoryReleaseObject(registered_object_t *rop)
Releases a registered object.
Definition: chfactory.c:381
objects_factory_t ch_factory
Factory object static instance.
Definition: chfactory.c:72
dyn_list_t fifo_list
List of the allocated "objects FIFO" objects.
Definition: chfactory.h:320
Type of the factory main object.
Definition: chfactory.h:277
void chMBObjectInit(mailbox_t *mbp, msg_t *buf, size_t n)
Initializes a mailbox_t object.
Definition: chmboxes.c:87
dyn_list_t mbx_list
List of the allocated buffer objects.
Definition: chfactory.h:314
#define CH_CFG_FACTORY_MAX_NAMES_LENGTH
Maximum length for object names.
Definition: chconf.h:412
Type of a dynamic object list.
Definition: chfactory.h:170