git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1226 35acf78f-673a-0410-8e92-d51de3d6d3f4

master
gdisirio 2009-10-17 09:21:59 +00:00
parent a7cfbdaf10
commit 34fd822f84
10 changed files with 76 additions and 21 deletions

View File

@ -1299,14 +1299,13 @@ PREDEFINED = __DOXYGEN__ \
CH_USE_WAITEXIT=1 \
CH_USE_SEMAPHORES=1 \
CH_USE_SEMSW=1 \
CH_USE_SEMAPHORES_TIMEOUT=1 \
CH_USE_MUTEXES=1 \
CH_USE_CONDVARS=1 \
CH_USE_CONDVARS_TIMEOUT=1 \
CH_USE_EVENTS=1 \
CH_USE_EVENTS_TIMEOUT=1 \
CH_USE_QUEUES=1 \
CH_USE_SERIAL_FULLDUPLEX=1 \
CH_USE_MEMCORE=1 \
CH_USE_HEAP=1 \
CH_USE_MEMPOOLS=1 \
CH_USE_MESSAGES=1 \

View File

@ -35,7 +35,7 @@
* @a ch\<group\>\<action\>\<suffix\>().
* The possible groups are: @a Sys, @a Sch, @a Time, @a VT, @a Thd, @a Sem,
* @a Mtx, @a Cond, @a Evt, @a Msg, @a IQ, @a OQ, @a IO, @a Dbg,
* @a Heap, @a Pool.
* @a Core, @a Heap, @a Pool.
*
* @section api_suffixes API Names Suffixes
* The suffix can be one of the following:

View File

@ -27,8 +27,6 @@
#ifndef _MEMCORE_H_
#define _MEMCORE_H_
#if CH_USE_MEMCORE
/**
* @brief Memory alignment type.
*/
@ -57,6 +55,8 @@ typedef void *(*memgetfunc_t)(size_t size);
*/
#define MEM_IS_ALIGNED(p) (((size_t)(p) & MEM_ALIGN_MASK) == 0)
#if CH_USE_MEMCORE
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -40,14 +40,19 @@ struct pool_header {
* @brief Memory pool descriptor.
*/
typedef struct {
struct pool_header *mp_next; /**< Pointer to the header.*/
size_t mp_object_size; /**< Memory pool objects size.*/
struct pool_header *mp_next; /**< Pointer to the header. */
size_t mp_object_size; /**< Memory pool objects size. */
#if CH_USE_MEMCORE
bool_t mp_usecore; /**< Feed from the memory code
allocator if empty. */
#endif
} MemoryPool;
/**
* @brief Data part of a static memory pool initializer.
* @details This macro should be used when statically initializing a
* memory pool that is part of a bigger structure.
*
* @param name the name of the memory pool variable
* @param size size of the memory pool contained objects
*/
@ -57,12 +62,25 @@ typedef struct {
* @brief Static memory pool initializer.
* @details Statically initialized memory pools require no explicit
* initialization using @p chPoolInit().
*
* @param name the name of the memory pool variable
* @param size size of the memory pool contained objects
*/
#define MEMORYPOOL_DECL(name, size) \
MemoryPool name = _MEMORYPOOL_DATA(name, size)
#if CH_USE_MEMCORE || defined(__DOXYGEN__)
/**
* @brief Enables or disables the hungry mode.
* @details If enabled, the hungry mode, makes an empty memory pool feed
* new objects from the core memory manager.
*
* @param[in] mp pointer to a @p MemoryPool structure
* @param[in] mode hungry mode flag
*/
#define chPoolSetHungryMode(mp, mode) ((mp)->mp_usecore = (mode))
#endif
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -230,7 +230,28 @@
*/
/**
* @defgroup heap Heap
* @defgroup memcore Core Memory Manager
* Core Memory Manager related APIs.
* <h2>Operation mode</h2>
* The core memory manager is a simplified allocator that only allows to
* allocate memory blocks without the possibility to free them.<br>
* This allocator is meant as a memory blocks provider for the other
* allocators such as:
* - C-Runtime allocator.
* - Heap allocator (see @ref heaps).
* - @ref Memory pools allocator (see @ref pools).
* .
* By having a centralized memory provider the various allocators can coexist
* and share the main memory.<br>
* This allocator, alone, is also useful for very simple applications that
* just require a simple way to get memory blocks.<br>
* In order to use the core memory manager APIs the @p CH_USE_MEMCORE option
* must be specified in @p chconf.h.
* @ingroup memory
*/
/**
* @defgroup heaps Heaps
* Heap Allocator related APIs.
* <h2>Operation mode</h2>
* The heap allocator implements a first-fit strategy and its APIs are

View File

@ -60,7 +60,7 @@ void core_init(void) {
* <code>sizeof(align_t)</code>.
*
*
* @param[in] the size of the block to be allocated
* @param[in] size the size of the block to be allocated
* @return A pointer to the allocated memory block.
* @retval NULL allocation failed, core memory exhausted.
*/
@ -79,7 +79,7 @@ void *chCoreAlloc(size_t size) {
* type @p align_t so it is not possible to allocate less than
* <code>sizeof(align_t)</code>.
*
* @param[in] the size of the block to be allocated.
* @param[in] size the size of the block to be allocated.
* @return A pointer to the allocated memory block.
* @retval NULL allocation failed, core memory exhausted.
*/

View File

@ -32,14 +32,20 @@
*
* @param[out] mp pointer to a @p MemoryPool structure
* @param[in] size the size of the objects contained in this memory pool,
* the minimum accepted size is the size of a pointer to void
* the minimum accepted size is the size of a pointer to void.
*
* @note The size is internally aligned to be a multiple of the @p align_t
* type size.
*/
void chPoolInit(MemoryPool *mp, size_t size) {
chDbgCheck((mp != NULL) && (size >= sizeof(void *)), "chPoolInit");
mp->mp_next = NULL;
mp->mp_object_size = size;
mp->mp_object_size = MEM_ALIGN_SIZE(size);
#if CH_USE_MEMCORE
mp->mp_usecore = FALSE;
#endif
}
/**
@ -56,7 +62,10 @@ void *chPoolAllocI(MemoryPool *mp) {
if ((objp = mp->mp_next) != NULL)
mp->mp_next = mp->mp_next->ph_next;
#if CH_USE_MEMCORE
else if (mp->mp_usecore)
objp = chCoreAllocI(mp->mp_object_size);
#endif
return objp;
}
@ -81,13 +90,17 @@ void *chPoolAlloc(MemoryPool *mp) {
*
* @param[in] mp pointer to a @p MemoryPool structure
* @param[in] objp the pointer to the object to be released or added
* @note the object is assumed to be of the right size for the specified
*
* @note The object is assumed to be of the right size for the specified
* memory pool.
* @note The object is assumed to be memory aligned to the size of @p align_t
* type.
*/
void chPoolFreeI(MemoryPool *mp, void *objp) {
struct pool_header *php = objp;
chDbgCheck((mp != NULL) && (objp != NULL), "chPoolFreeI");
chDbgCheck((mp != NULL) && (objp != NULL) && MEM_IS_ALIGNED(objp),
"chPoolFreeI");
php->ph_next = mp->mp_next;
mp->mp_next = php;

View File

@ -7,11 +7,13 @@
Removed the old EMAC driver, updated the uIP WEB demo to use the new
driver model.
- NEW: Added a simple lwIP demo (web server) for the AT91SAM7X.
- NEW: Centralized memory heap manager. This simple allocator implements a
- NEW: Centralized core memory manager. This simple allocator implements a
sbrk()-like API: chCoreAlloc(). The other allocators now use this manager
in order to get memory blocks.
- NEW: The heap allocator has been modified, now it is possible to have
multiple heaps. The default heap gets its memory from the new heap manager.
- NEW: Added a "hungry" mode to the memory pools allocator, when enabled, this
mode makes a memory pool to feed memory from the core memory manager.
- CHANGE: Because the changes in the allocators some API prototypes changed:
chHeapAlloc(), chHeapStatus(), chThdCreateFromHeap().
- CHANGE: Because the changes in the allocators some configuration options

View File

@ -47,6 +47,7 @@ struct testcase {
void (*execute)(void);
};
#ifndef __DOXYGEN__
union test_buffers {
struct {
WORKING_AREA(waT0, THREADS_STACK_SIZE);
@ -57,6 +58,7 @@ union test_buffers {
};
uint8_t buffer[WA_SIZE * 5];
};
#endif
#ifdef __cplusplus
extern "C" {

View File

@ -85,7 +85,7 @@ static void heap1_execute(void) {
p1 = chHeapAlloc(NULL, SIZE);
test_assert(1, p1 != NULL, "allocation failed");
chHeapFree(p1);
p1 = chHeapAlloc(NULL, 0x1000000);
p1 = chHeapAlloc(NULL, (size_t)-256);
test_assert(2, p1 == NULL, "allocation not failed");
/* Initial local heap state.*/