#include "stdlib.h"
#include "stddef.h"
#include "string.h"
#include "semaphore.h"
gehe zum Quellcode dieser Datei
|
static cell * | check_cell (const allocator *suba, cell *c, char *fn, int ln) |
|
void | suba_getmeminfo (allocator *suba, int *allocated_size, int *allocated_peak, int *allocated_count, int *free_size, int *largest_block, int *free_block_count) |
|
allocator * | suba_init (allocator *suba, size_t size, size_t mincell, char *name) |
|
void * | suba_alloc (allocator *suba, size_t size, int zero) |
|
int | suba_free (allocator *suba, void *ptr) |
|
#define ACTUALSIZE |
( |
|
size) | |
(size + sizeof(cell_hdr)) |
#define ALIGNMASK (sizeof(cell*)-1) |
#define ALLOC2CELL |
( |
|
p) | |
(cell*)((void*)p - sizeof(cell_hdr)) |
#define ALLOCSIZE |
( |
|
size) | |
(size - sizeof(cell_hdr)) |
#define CELL2ALLOC |
( |
|
c) | |
(void*)((void*)c + sizeof(cell_hdr)) |
#define CELL_MAGIC 0x5342434C |
#define CEND |
( |
|
c) | |
((cell*)((char*)c + c->h.size)) |
#define ISADJ |
( |
|
c1, |
|
|
|
c2 |
|
) |
| (CEND(c1) == (c2)) |
#define SUBA_MAGIC 0x53554241 |
#define SUBA_SEMAPHORE_TIMEOUT 1000 |
Definiert in Zeile 69 der Datei suba.c.
71 if (suba && (c > (
cell*)suba) && (c < (
cell*)((
char*)suba + suba->
size))) {
77 sprintf(buf,
"%s bad cell - %x %x",
fn, c, suba);
Definiert in Zeile 306 der Datei suba.c.
313 if (cellsize < suba->mincell) cellsize = suba->
mincell;
319 this_cell =
check_cell(suba, prev_cell->
next,
"suba_alloc", __LINE__);
320 while (this_cell->
h.
size > 0 && this_cell->
h.
size < cellsize) {
321 prev_cell = this_cell;
322 this_cell =
check_cell(suba, this_cell->
next,
"suba_alloc", __LINE__);
326 if (this_cell->
h.
size > 0) {
332 this_cell->
h.
size = this_cell->
h.
size - cellsize;
333 this_cell =
CEND(this_cell);
334 this_cell->
h.
size = cellsize;
340 cellsize = this_cell->
h.
size;
359 DebugAssert(
"suba_alloc TakeSemaphore fail", __LINE__);
364 if (this_cell !=
NULL)
int suba_free |
( |
allocator * |
suba, |
|
|
void * |
ptr |
|
) |
| |
Definiert in Zeile 374 der Datei suba.c.
380 check_cell(suba, this_cell,
"suba_free", __LINE__);
397 while (prev_cell->
next < this_cell) {
398 prev_cell =
check_cell(suba, prev_cell->
next,
"suba_free", __LINE__);
403 if (
ISADJ(prev_cell,this_cell)) {
406 this_cell = prev_cell;
409 prev_cell->
next = this_cell;
415 if (
ISADJ(this_cell,next_cell)) {
430 DebugAssert(
"suba_free TakeSemaphore fail", __LINE__);
void suba_getmeminfo |
( |
allocator * |
suba, |
|
|
int * |
allocated_size, |
|
|
int * |
allocated_peak, |
|
|
int * |
allocated_count, |
|
|
int * |
free_size, |
|
|
int * |
largest_block, |
|
|
int * |
free_block_count |
|
) |
| |
Definiert in Zeile 204 der Datei suba.c.
209 DebugAssert(
"suba_getmeminfo BAD MAGIC", __LINE__);
216 while (c->
h.
size != 0)
240 DebugAssert(
"suba_getmeminfo TakeSemaphore fail", __LINE__);
Definiert in Zeile 245 der Datei suba.c.
250 if (suba ==
NULL || size == 0) {
251 DebugAssert(
"Invalid parameters to 'suba_init'", __LINE__);
274 c1 = (
cell*)((
void*)suba + hdrsiz);
275 c1->
h.
size = size - hdrsiz -
sizeof(
cell);