Classes | Macros | Typedefs | Functions | Variables
tlsf.c File Reference
#include "../fosi.h"
#include <string.h>
#include "target.h"
#include "tlsf.h"
#include <stdio.h>
Include dependency graph for tlsf.c:

Go to the source code of this file.

Classes

struct  area_info_struct
 
struct  bhdr_struct
 
struct  free_ptr_struct
 
struct  TLSF_struct
 

Macros

#define __inline__
 
#define _DEBUG_TLSF_   (0)
 
#define BHDR_OVERHEAD   (sizeof (bhdr_t) - MIN_BLOCK_SIZE)
 
#define BLOCK_ALIGN   (sizeof(void *) * 2)
 
#define BLOCK_SIZE   ((intptr_t)~PTR_MASK)
 
#define BLOCK_STATE   (0x1)
 
#define DEFAULT_AREA_SIZE   (1024*10)
 
#define ERROR_MSG(fmt, args...)   printf(fmt, ## args)
 
#define EXTRACT_BLOCK(_b, _tlsf, _fl, _sl)
 
#define EXTRACT_BLOCK_HDR(_b, _tlsf, _fl, _sl)
 
#define FLI_OFFSET   (6) /* tlsf structure just will manage blocks bigger */
 
#define FPRINT_MSG(ff, fmt, args...)   fprintf(ff, fmt, ## args)
 
#define FREE_BLOCK   (0x1)
 
#define GET_NEXT_BLOCK(_addr, _r)   TYPE_PUN(bhdr_t, char, (char *) (_addr) + (_r))
 
#define INSERT_BLOCK(_b, _tlsf, _fl, _sl)
 
#define MAX_FLI   (30)
 
#define MAX_LOG2_SLI   (5)
 
#define MAX_SLI   (1 << MAX_LOG2_SLI) /* MAX_SLI = 2^MAX_LOG2_SLI */
 
#define MEM_ALIGN   ((BLOCK_ALIGN) - 1)
 
#define MIN_BLOCK_SIZE   (sizeof (free_ptr_t))
 
#define ORO_MEMORY_POOL
 
#define PREV_FREE   (0x2)
 
#define PREV_STATE   (0x2)
 
#define PREV_USED   (0x0)
 
#define PRINT_MSG(fmt, args...)   printf(fmt, ## args)
 
#define PTR_MASK   (sizeof(void *) - 1)
 
#define REAL_FLI   (MAX_FLI - FLI_OFFSET)
 
#define ROUNDDOWN_SIZE(_r)   ((_r) & ~MEM_ALIGN)
 
#define ROUNDUP(_x, _v)   ((((~(_x)) + 1) & ((_v)-1)) + (_x))
 
#define ROUNDUP_SIZE(_r)   (((_r) + MEM_ALIGN) & ~MEM_ALIGN)
 
#define SMALL_BLOCK   (128)
 
#define STATE_MASK   (BLOCK_STATE | PREV_STATE)
 
#define TLSF_ADD_SIZE(tlsf, b)   do{}while(0)
 
#define TLSF_REMOVE_SIZE(tlsf, b)   do{}while(0)
 
#define TLSF_SIGNATURE   (0x2A59FA59)
 
#define TLSF_STATISTIC   (0)
 
#define TLSF_USE_LOCKS   (1)
 
#define TYPE_PUN(dsttype, srctype, x)   ( (dsttype*)(x) )
 
#define USE_MMAP   (0)
 
#define USE_PRINTF   (1)
 
#define USE_SBRK   (0)
 
#define USED_BLOCK   (0x0)
 

Typedefs

typedef struct area_info_struct area_info_t
 
typedef struct bhdr_struct bhdr_t
 
typedef struct free_ptr_struct free_ptr_t
 
typedef struct TLSF_struct tlsf_t
 
typedef unsigned int u32_t
 
typedef unsigned char u8_t
 

Functions

void abort (void)
 
size_t add_new_area (void *area, size_t area_size, void *mem_pool)
 
void * calloc_ex (size_t nelem, size_t elem_size, void *mem_pool)
 
static __inline__ void clear_bit (int nr, u32_t *addr)
 
static __inline__ void corrupt (const char *s)
 
void destroy_memory_pool (void *mem_pool)
 
static __inline__ bhdr_tencode_prev_block (bhdr_t *prev, size_t size)
 
static __inline__ bhdr_tFIND_SUITABLE_BLOCK (tlsf_t *_tlsf, int *_fl, int *_sl)
 
void free_ex (void *ptr, void *mem_pool)
 
size_t get_max_size (void *mem_pool)
 
size_t get_max_size_mp (void)
 
size_t get_overhead_size (void *mem_pool)
 
size_t get_overhead_size_mp (void)
 
size_t get_pool_size (void *mem_pool)
 
size_t get_pool_size_mp (void)
 
size_t get_used_size (void *mem_pool)
 
size_t get_used_size_mp (void)
 
size_t init_memory_pool (size_t mem_pool_size, void *mem_pool)
 
static __inline__ int ls_bit (int x)
 
void * malloc_ex (size_t size, void *mem_pool)
 
static __inline__ void MAPPING_INSERT (size_t _r, int *_fl, int *_sl)
 
static __inline__ void MAPPING_SEARCH (size_t *_r, int *_fl, int *_sl)
 
static __inline__ int ms_bit (int x)
 
static __inline__ bhdr_tprocess_area (void *area, size_t size)
 
void * realloc_ex (void *ptr, size_t new_size, void *mem_pool)
 
static __inline__ void set_bit (int nr, u32_t *addr)
 
void * tlsf_calloc (size_t nelem, size_t elem_size)
 
void tlsf_free (void *ptr)
 
void * tlsf_malloc (size_t size)
 
void * tlsf_realloc (void *ptr, size_t size)
 

Variables

static char * mp = NULL
 
static const int table []
 

Macro Definition Documentation

#define __inline__

Definition at line 123 of file tlsf.c.

#define _DEBUG_TLSF_   (0)

Definition at line 129 of file tlsf.c.

#define BHDR_OVERHEAD   (sizeof (bhdr_t) - MIN_BLOCK_SIZE)

Definition at line 149 of file tlsf.c.

#define BLOCK_ALIGN   (sizeof(void *) * 2)

Definition at line 138 of file tlsf.c.

#define BLOCK_SIZE   ((intptr_t)~PTR_MASK)

Definition at line 153 of file tlsf.c.

#define BLOCK_STATE   (0x1)

Definition at line 172 of file tlsf.c.

#define DEFAULT_AREA_SIZE   (1024*10)

Definition at line 185 of file tlsf.c.

#define ERROR_MSG (   fmt,
  args... 
)    printf(fmt, ## args)

Definition at line 195 of file tlsf.c.

#define EXTRACT_BLOCK (   _b,
  _tlsf,
  _fl,
  _sl 
)
Value:
do { \
if (_b -> ptr.free_ptr.next) \
_b -> ptr.free_ptr.next -> ptr.free_ptr.prev = _b -> ptr.free_ptr.prev; \
if (_b -> ptr.free_ptr.prev) \
_b -> ptr.free_ptr.prev -> ptr.free_ptr.next = _b -> ptr.free_ptr.next; \
if (_tlsf -> matrix [_fl][_sl] == _b) { \
_tlsf -> matrix [_fl][_sl] = _b -> ptr.free_ptr.next; \
if (!_tlsf -> matrix [_fl][_sl]) { \
clear_bit (_sl, &_tlsf -> sl_bitmap[_fl]); \
if (!_tlsf -> sl_bitmap [_fl]) \
clear_bit (_fl, &_tlsf -> fl_bitmap); \
} \
} \
_b -> ptr.free_ptr.prev = NULL; \
_b -> ptr.free_ptr.next = NULL; \
} while(0)
static __inline__ void clear_bit(int nr, u32_t *addr)
Definition: tlsf.c:337

Definition at line 414 of file tlsf.c.

#define EXTRACT_BLOCK_HDR (   _b,
  _tlsf,
  _fl,
  _sl 
)
Value:
do { \
_tlsf -> matrix [_fl] [_sl] = _b -> ptr.free_ptr.next; \
if (_tlsf -> matrix[_fl][_sl]) \
_tlsf -> matrix[_fl][_sl] -> ptr.free_ptr.prev = NULL; \
else { \
clear_bit (_sl, &_tlsf -> sl_bitmap [_fl]); \
if (!_tlsf -> sl_bitmap [_fl]) \
clear_bit (_fl, &_tlsf -> fl_bitmap); \
} \
_b -> ptr.free_ptr.prev = NULL; \
_b -> ptr.free_ptr.next = NULL; \
}while(0)
static __inline__ void clear_bit(int nr, u32_t *addr)
Definition: tlsf.c:337

Definition at line 400 of file tlsf.c.

#define FLI_OFFSET   (6) /* tlsf structure just will manage blocks bigger */

Definition at line 144 of file tlsf.c.

#define FPRINT_MSG (   ff,
  fmt,
  args... 
)    fprintf(ff, fmt, ## args)

Definition at line 194 of file tlsf.c.

#define FREE_BLOCK   (0x1)

Definition at line 177 of file tlsf.c.

#define GET_NEXT_BLOCK (   _addr,
  _r 
)    TYPE_PUN(bhdr_t, char, (char *) (_addr) + (_r))

Definition at line 165 of file tlsf.c.

#define INSERT_BLOCK (   _b,
  _tlsf,
  _fl,
  _sl 
)
Value:
do { \
_b -> ptr.free_ptr.prev = NULL; \
_b -> ptr.free_ptr.next = _tlsf -> matrix [_fl][_sl]; \
if (_tlsf -> matrix [_fl][_sl]) \
_tlsf -> matrix [_fl][_sl] -> ptr.free_ptr.prev = _b; \
_tlsf -> matrix [_fl][_sl] = _b; \
set_bit (_sl, &_tlsf -> sl_bitmap [_fl]); \
set_bit (_fl, &_tlsf -> fl_bitmap); \
} while(0)
static __inline__ void set_bit(int nr, u32_t *addr)
Definition: tlsf.c:332

Definition at line 431 of file tlsf.c.

#define MAX_FLI   (30)

Definition at line 140 of file tlsf.c.

#define MAX_LOG2_SLI   (5)

Definition at line 141 of file tlsf.c.

#define MAX_SLI   (1 << MAX_LOG2_SLI) /* MAX_SLI = 2^MAX_LOG2_SLI */

Definition at line 142 of file tlsf.c.

#define MEM_ALIGN   ((BLOCK_ALIGN) - 1)

Definition at line 167 of file tlsf.c.

#define MIN_BLOCK_SIZE   (sizeof (free_ptr_t))

Definition at line 148 of file tlsf.c.

#define ORO_MEMORY_POOL

Definition at line 118 of file tlsf.c.

#define PREV_FREE   (0x2)

Definition at line 181 of file tlsf.c.

#define PREV_STATE   (0x2)

Definition at line 173 of file tlsf.c.

#define PREV_USED   (0x0)

Definition at line 182 of file tlsf.c.

#define PRINT_MSG (   fmt,
  args... 
)    printf(fmt, ## args)

Definition at line 193 of file tlsf.c.

#define PTR_MASK   (sizeof(void *) - 1)

Definition at line 152 of file tlsf.c.

#define REAL_FLI   (MAX_FLI - FLI_OFFSET)

Definition at line 147 of file tlsf.c.

#define ROUNDDOWN_SIZE (   _r)    ((_r) & ~MEM_ALIGN)

Definition at line 169 of file tlsf.c.

#define ROUNDUP (   _x,
  _v 
)    ((((~(_x)) + 1) & ((_v)-1)) + (_x))

Definition at line 170 of file tlsf.c.

#define ROUNDUP_SIZE (   _r)    (((_r) + MEM_ALIGN) & ~MEM_ALIGN)

Definition at line 168 of file tlsf.c.

#define SMALL_BLOCK   (128)

Definition at line 146 of file tlsf.c.

#define STATE_MASK   (BLOCK_STATE | PREV_STATE)

Definition at line 174 of file tlsf.c.

#define TLSF_ADD_SIZE (   tlsf,
 
)    do{}while(0)

Definition at line 106 of file tlsf.c.

#define TLSF_REMOVE_SIZE (   tlsf,
 
)    do{}while(0)

Definition at line 107 of file tlsf.c.

#define TLSF_SIGNATURE   (0x2A59FA59)

Definition at line 150 of file tlsf.c.

#define TLSF_STATISTIC   (0)

Definition at line 74 of file tlsf.c.

#define TLSF_USE_LOCKS   (1)

Definition at line 70 of file tlsf.c.

#define TYPE_PUN (   dsttype,
  srctype,
 
)    ( (dsttype*)(x) )

Definition at line 162 of file tlsf.c.

#define USE_MMAP   (0)

Definition at line 78 of file tlsf.c.

#define USE_PRINTF   (1)

Definition at line 64 of file tlsf.c.

#define USE_SBRK   (0)

Definition at line 82 of file tlsf.c.

#define USED_BLOCK   (0x0)

Definition at line 178 of file tlsf.c.

Typedef Documentation

typedef struct area_info_struct area_info_t
typedef struct bhdr_struct bhdr_t
typedef struct free_ptr_struct free_ptr_t
typedef struct TLSF_struct tlsf_t
typedef unsigned int u32_t

Definition at line 205 of file tlsf.c.

typedef unsigned char u8_t

Definition at line 206 of file tlsf.c.

Function Documentation

void abort ( void  )
size_t add_new_area ( void *  area,
size_t  area_size,
void *  mem_pool 
)

Definition at line 546 of file tlsf.c.

void* calloc_ex ( size_t  nelem,
size_t  elem_size,
void *  mem_pool 
)

Definition at line 1021 of file tlsf.c.

static __inline__ void clear_bit ( int  nr,
u32_t addr 
)
static

Definition at line 337 of file tlsf.c.

static __inline__ void corrupt ( const char *  s)
static

Definition at line 393 of file tlsf.c.

void destroy_memory_pool ( void *  mem_pool)

Definition at line 717 of file tlsf.c.

static __inline__ bhdr_t* encode_prev_block ( bhdr_t prev,
size_t  size 
)
static

Definition at line 283 of file tlsf.c.

static __inline__ bhdr_t * FIND_SUITABLE_BLOCK ( tlsf_t _tlsf,
int *  _fl,
int *  _sl 
)
static

Definition at line 375 of file tlsf.c.

void free_ex ( void *  ptr,
void *  mem_pool 
)

Definition at line 879 of file tlsf.c.

size_t get_max_size ( void *  mem_pool)

Definition at line 694 of file tlsf.c.

size_t get_max_size_mp ( void  )

Definition at line 706 of file tlsf.c.

size_t get_overhead_size ( void *  mem_pool)

Definition at line 648 of file tlsf.c.

size_t get_overhead_size_mp ( void  )

Definition at line 660 of file tlsf.c.

size_t get_pool_size ( void *  mem_pool)

Definition at line 625 of file tlsf.c.

size_t get_pool_size_mp ( void  )

Definition at line 637 of file tlsf.c.

size_t get_used_size ( void *  mem_pool)

Definition at line 671 of file tlsf.c.

size_t get_used_size_mp ( void  )

Definition at line 683 of file tlsf.c.

size_t init_memory_pool ( size_t  mem_pool_size,
void *  mem_pool 
)

Definition at line 497 of file tlsf.c.

static __inline__ int ls_bit ( int  x)
static

Definition at line 314 of file tlsf.c.

void* malloc_ex ( size_t  size,
void *  mem_pool 
)

Definition at line 811 of file tlsf.c.

static __inline__ void MAPPING_INSERT ( size_t  _r,
int *  _fl,
int *  _sl 
)
static

Definition at line 362 of file tlsf.c.

static __inline__ void MAPPING_SEARCH ( size_t *  _r,
int *  _fl,
int *  _sl 
)
static

Definition at line 342 of file tlsf.c.

static __inline__ int ms_bit ( int  x)
static

Definition at line 323 of file tlsf.c.

static __inline__ bhdr_t * process_area ( void *  area,
size_t  size 
)
static

Definition at line 467 of file tlsf.c.

void* realloc_ex ( void *  ptr,
size_t  new_size,
void *  mem_pool 
)

Definition at line 929 of file tlsf.c.

static __inline__ void set_bit ( int  nr,
u32_t addr 
)
static

Definition at line 332 of file tlsf.c.

void* tlsf_calloc ( size_t  nelem,
size_t  elem_size 
)

Definition at line 796 of file tlsf.c.

void tlsf_free ( void *  ptr)

Definition at line 762 of file tlsf.c.

void* tlsf_malloc ( size_t  size)

Definition at line 733 of file tlsf.c.

void* tlsf_realloc ( void *  ptr,
size_t  size 
)

Definition at line 775 of file tlsf.c.

Variable Documentation

char* mp = NULL
static

Definition at line 494 of file tlsf.c.

const int table[]
static
Initial value:
= {
-1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4,
4, 4,
4, 4, 4, 4, 4, 4, 4,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5,
5, 5, 5, 5, 5, 5, 5,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6,
6, 6, 6, 6, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
6,
6, 6, 6, 6, 6, 6, 6,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7,
7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7,
7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7,
7, 7, 7, 7, 7, 7, 7,
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
7,
7, 7, 7, 7, 7, 7, 7
}

Definition at line 287 of file tlsf.c.



rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:40