/** * @brief Allocate an object clearing it. */ void *osPoolCAlloc(osPoolId pool_id) { void *object; object = chPoolAllocI((memory_pool_t *)pool_id); memset(object, 0, pool_id->mp_object_size); return object; }
/** * * @brief Appends an item to a queue from ISR context. * * @param[in] queuep pointer to instance of @p struct pios_queue * @param[in] itemp pointer to item which will be appended to the queue * @param[in] timeout_ms timeout for appending item to queue in milliseconds * * @returns true on success or false on timeout or failure * */ bool PIOS_Queue_Send_FromISR(struct pios_queue *queuep, const void *itemp, bool *wokenp) { chSysLockFromIsr(); void *buf = chPoolAllocI(&queuep->mp); if (buf == NULL) { chSysUnlockFromIsr(); return false; } memcpy(buf, itemp, queuep->mp.mp_object_size); msg_t result = chMBPostI(&queuep->mb, (msg_t)buf); if (result != RDY_OK) { chPoolFreeI(&queuep->mp, buf); chSysUnlockFromIsr(); return false; } chSysUnlockFromIsr(); return true; }
/** * @brief Allocates an object from a memory pool. * * @param[in] mp pointer to a @p MemoryPool structure * @return The pointer to the allocated object. * @retval NULL if pool is empty. * * @api */ void *chPoolAlloc(MemoryPool *mp) { void *objp; chSysLock(); objp = chPoolAllocI(mp); chSysUnlock(); return objp; }
/** * @brief Allocates an object from a memory pool. * @pre The memory pool must be already been initialized. * * @param[in] mp pointer to a @p memory_pool_t structure * @return The pointer to the allocated object. * @retval NULL if pool is empty. * * @api */ void *chPoolAlloc(memory_pool_t *mp) { void *objp; chSysLock(); objp = chPoolAllocI(mp); chSysUnlock(); return objp; }
/** * @brief Allocate an object. */ void *osPoolAlloc(osPoolId pool_id) { void *object; syssts_t sts = chSysGetStatusAndLockX(); object = chPoolAllocI((memory_pool_t *)pool_id); chSysRestoreStatusX(sts); return object; }
/** * @brief Allocates an object from a guarded memory pool. * @pre The guarded memory pool must already be initialized. * * @param[in] gmp pointer to a @p guarded_memory_pool_t structure * @param[in] timeout the number of ticks before the operation timeouts, * the following special values are allowed: * - @a TIME_IMMEDIATE immediate timeout. * - @a TIME_INFINITE no timeout. * . * @return The pointer to the allocated object. * @retval NULL if the operation timed out. * * @sclass */ void *chGuardedPoolAllocTimeoutS(guarded_memory_pool_t *gmp, sysinterval_t timeout) { msg_t msg; msg = chSemWaitTimeoutS(&gmp->sem, timeout); if (msg != MSG_OK) { return NULL; } return chPoolAllocI(&gmp->pool); }
void *MemoryPool::allocI(void) { return chPoolAllocI(&pool); }