#include <assert.h>
#include <debug.h>
#include <interrupt.h>
#include <mempool.h>
#include <physmem.h>
#include <util.h>

Go to the source code of this file.
Functions | |
| void | mem_pool_init (struct mem_pool *pool, void *start, size_t size, size_t objsize, unsigned int align_order) |
| Initialize a memory pool. | |
| void | mem_pool_init_physmem (struct mem_pool *mempool, struct physmem_pool *phys_pool, unsigned int nr_objects, size_t objsize, unsigned int align_order) |
| Initialize a memory pool using the physmem allocator. | |
| void * | mem_pool_alloc (struct mem_pool *pool) |
| Allocate an object from a memory pool. | |
| void | mem_pool_free (struct mem_pool *pool, const void *obj) |
| Free an object previously allocated from a memory pool. | |
This file implements the memory pool interface defined by mempool.h.
Definition in file mempool.c.
| void* mem_pool_alloc | ( | struct mem_pool * | pool | ) |
Allocate an object from a memory pool.
| pool | The memory pool from which the object is allocated. |
Definition at line 170 of file mempool.c.
References assert, cpu_irq_restore(), cpu_irq_save(), and mem_pool::freelist.
Referenced by usb_req_alloc().

| void mem_pool_free | ( | struct mem_pool * | pool, | |
| const void * | obj | |||
| ) |
Free an object previously allocated from a memory pool.
The caller is responsible for making sure obj was originally allocated from pool. If an object is freed into a different pool, the integrity of the pool can no longer be guaranteed.
| pool | The memory pool which the object belongs to. | |
| obj | The object to be freed. |
Definition at line 202 of file mempool.c.
References assert, cpu_irq_restore(), cpu_irq_save(), and mem_pool::freelist.
Referenced by usb_req_free().

| void mem_pool_init | ( | struct mem_pool * | pool, | |
| void * | start, | |||
| size_t | size, | |||
| size_t | objsize, | |||
| unsigned int | align_order | |||
| ) |
Initialize a memory pool.
This function will initialize a memory pool, populating its freelist with objects tightly packed into the specified memory range.
All objects in the pool are guaranteed to be aligned to a multiple of
bytes. For example, if align_order is 4, each object will start on a 16-byte boundary.
| pool | The memory pool to be initialized. | |
| start | The memory area to be used for object storage. | |
| size | The size of the memory area in bytes. | |
| objsize | The size of each object in bytes. | |
| align_order | log2 of the minimum object alignment in bytes. |
size must be large enough to hold at least one object.
Definition at line 88 of file mempool.c.
References assert, dbg_printf, mem_pool::freelist, and round_up().
Referenced by mem_pool_init_physmem().

| void mem_pool_init_physmem | ( | struct mem_pool * | mempool, | |
| struct physmem_pool * | phys_pool, | |||
| unsigned int | nr_objects, | |||
| size_t | objsize, | |||
| unsigned int | align_order | |||
| ) |
Initialize a memory pool using the physmem allocator.
This function will grab enough physical memory for nr_objects and use this to initialize mempool.
| mempool | The memory pool to be initialized. | |
| phys_pool | The physical memory pool from which to grab memory | |
| nr_objects | The number of objects in the pool | |
| objsize | The size of each object in bytes. | |
| align_order | log2 of the minimum object alignment in bytes. |
There must be enough available memory in phys_pool.
objsize must be larger than the size of a pointer.
Definition at line 139 of file mempool.c.
References assert, mem_pool_init(), PHYS_MAP_WRBACK, PHYS_MAP_WRBUF, physmem_alloc(), PHYSMEM_ALLOC_ERR, physmem_map(), and round_up().
Referenced by usb_init().

1.5.8