A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
tlsf.cc File Reference
#include <assert.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "tlsf.h"
+ Include dependency graph for tlsf.cc:

Go to the source code of this file.

Classes

struct  block_header_t
 
struct  control_t
 
struct  integrity_t
 

Macros

#define tlsf_decl   static
 
#define tlsf_fls_sizet   tlsf_fls
 
#define tlsf_cast(t, exp)   ((t)(exp))
 
#define tlsf_min(a, b)   ((a) < (b) ? (a) : (b))
 
#define tlsf_max(a, b)   ((a) > (b) ? (a) : (b))
 
#define tlsf_assert   assert
 
#define _tlsf_glue2(x, y)   x##y
 
#define _tlsf_glue(x, y)   _tlsf_glue2(x, y)
 
#define tlsf_static_assert(exp)   typedef char _tlsf_glue(static_assert, __LINE__)[(exp) ? 1 : -1]
 
#define TLSF_INCREASE_REAL_USED(control, increment)
 
#define TLSF_INCREASE_FRAGMENTS(control)
 
#define tlsf_insist(x)
 

Typedefs

typedef struct block_header_t block_header_t
 
typedef struct control_t control_t
 
typedef ptrdiff_t tlsfptr_t
 
typedef struct integrity_t integrity_t
 

Enumerations

enum  tlsf_public { SL_INDEX_COUNT_LOG2 = 5 }
 
enum  tlsf_private {
  ALIGN_SIZE_LOG2 = 2, ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2), FL_INDEX_MAX = 30, SL_INDEX_COUNT = (1 << SL_INDEX_COUNT_LOG2),
  FL_INDEX_SHIFT = (SL_INDEX_COUNT_LOG2 + ALIGN_SIZE_LOG2), FL_INDEX_COUNT = (FL_INDEX_MAX - FL_INDEX_SHIFT + 1), SMALL_BLOCK_SIZE = (1 << FL_INDEX_SHIFT)
}
 

Functions

tlsf_decl int tlsf_fls_generic (unsigned int word)
 
tlsf_decl int tlsf_ffs (unsigned int word)
 
tlsf_decl int tlsf_fls (unsigned int word)
 
 tlsf_static_assert (sizeof(int)*CHAR_BIT==32)
 
 tlsf_static_assert (sizeof(size_t)*CHAR_BIT >=32)
 
 tlsf_static_assert (sizeof(size_t)*CHAR_BIT<=64)
 
 tlsf_static_assert (sizeof(unsigned int)*CHAR_BIT >=SL_INDEX_COUNT)
 
 tlsf_static_assert (ALIGN_SIZE==SMALL_BLOCK_SIZE/SL_INDEX_COUNT)
 
static size_t block_size (const block_header_t *block)
 
static void block_set_size (block_header_t *block, size_t size)
 
static int block_is_last (const block_header_t *block)
 
static int block_is_free (const block_header_t *block)
 
static void block_set_free (block_header_t *block)
 
static void block_set_used (block_header_t *block)
 
static int block_is_prev_free (const block_header_t *block)
 
static void block_set_prev_free (block_header_t *block)
 
static void block_set_prev_used (block_header_t *block)
 
static block_header_tblock_from_ptr (const void *ptr)
 
static void * block_to_ptr (const block_header_t *block)
 
static block_header_toffset_to_block (const void *ptr, size_t size)
 
static block_header_tblock_prev (const block_header_t *block)
 
static block_header_tblock_next (const block_header_t *block)
 
static block_header_tblock_link_next (block_header_t *block)
 
static void block_mark_as_free (block_header_t *block)
 
static void block_mark_as_used (block_header_t *block)
 
static size_t align_up (size_t x, size_t align)
 
static size_t align_down (size_t x, size_t align)
 
static void * align_ptr (const void *ptr, size_t align)
 
static size_t adjust_request_size (size_t size, size_t align)
 
static void mapping_insert (size_t size, int *fli, int *sli)
 
static void mapping_search (size_t size, int *fli, int *sli)
 
static block_header_tsearch_suitable_block (control_t *control, int *fli, int *sli)
 
static void remove_free_block (control_t *control, block_header_t *block, int fl, int sl)
 
static void insert_free_block (control_t *control, block_header_t *block, int fl, int sl)
 
static void block_remove (control_t *control, block_header_t *block)
 
static void block_insert (control_t *control, block_header_t *block)
 
static int block_can_split (block_header_t *block, size_t size)
 
static block_header_tblock_split (block_header_t *block, size_t size)
 
static block_header_tblock_absorb (block_header_t *prev, block_header_t *block)
 
static block_header_tblock_merge_prev (control_t *control, block_header_t *block)
 
static block_header_tblock_merge_next (control_t *control, block_header_t *block)
 
static void block_trim_free (control_t *control, block_header_t *block, size_t size)
 
static void block_trim_used (control_t *control, block_header_t *block, size_t size)
 
static block_header_tblock_trim_free_leading (control_t *control, block_header_t *block, size_t size)
 
static block_header_tblock_locate_free (control_t *control, size_t size)
 
static void * block_prepare_used (control_t *control, block_header_t *block, size_t size)
 
static void control_construct (control_t *control)
 
static void integrity_walker (void *ptr, size_t size, int used, void *user)
 
static void default_walker (void *ptr, size_t size, int used, void *user)
 

Variables

static const size_t block_header_free_bit = 1 << 0
 
static const size_t block_header_prev_free_bit = 1 << 1
 
static const size_t block_header_overhead = sizeof(size_t)
 
static const size_t block_start_offset = offsetof(block_header_t, size) + sizeof(size_t)
 
static const size_t block_size_min = sizeof(block_header_t) - sizeof(block_header_t*)
 
static const size_t block_size_max = tlsf_cast(size_t, 1) << FL_INDEX_MAX
 

Macro Definition Documentation

#define _tlsf_glue (   x,
 
)    _tlsf_glue2(x, y)

Definition at line 201 of file tlsf.cc.

#define _tlsf_glue2 (   x,
 
)    x##y

Definition at line 200 of file tlsf.cc.

#define tlsf_assert   assert

Definition at line 193 of file tlsf.cc.

#define tlsf_cast (   t,
  exp 
)    ((t)(exp))

Definition at line 185 of file tlsf.cc.

#define tlsf_decl   static

Definition at line 13 of file tlsf.cc.

#define tlsf_fls_sizet   tlsf_fls

Definition at line 125 of file tlsf.cc.

#define TLSF_INCREASE_FRAGMENTS (   control)
Value:
do { \
control->fragments++; \
control->max_fragments = tlsf_max(control->fragments, control->max_fragments); \
} while (0)
#define tlsf_max(a, b)
Definition: tlsf.cc:187

Definition at line 273 of file tlsf.cc.

#define TLSF_INCREASE_REAL_USED (   control,
  increment 
)
Value:
do { \
control->real_used += (increment); \
control->max_used = tlsf_max(control->real_used, control->max_used); \
} while (0)
#define tlsf_max(a, b)
Definition: tlsf.cc:187

Definition at line 268 of file tlsf.cc.

#define tlsf_insist (   x)
Value:
{ \
if (!(x)) { \
status--; \
} \
}
#define tlsf_assert
Definition: tlsf.cc:193

Definition at line 695 of file tlsf.cc.

#define tlsf_max (   a,
 
)    ((a) > (b) ? (a) : (b))

Definition at line 187 of file tlsf.cc.

#define tlsf_min (   a,
 
)    ((a) < (b) ? (a) : (b))

Definition at line 186 of file tlsf.cc.

#define tlsf_static_assert (   exp)    typedef char _tlsf_glue(static_assert, __LINE__)[(exp) ? 1 : -1]

Definition at line 202 of file tlsf.cc.

Typedef Documentation

typedef struct control_t control_t
typedef struct integrity_t integrity_t
typedef ptrdiff_t tlsfptr_t

Definition at line 299 of file tlsf.cc.

Enumeration Type Documentation

Enumerator
ALIGN_SIZE_LOG2 
ALIGN_SIZE 
FL_INDEX_MAX 
SL_INDEX_COUNT 
FL_INDEX_SHIFT 
FL_INDEX_COUNT 
SMALL_BLOCK_SIZE 

Definition at line 144 of file tlsf.cc.

Enumerator
SL_INDEX_COUNT_LOG2 

Definition at line 135 of file tlsf.cc.

Function Documentation

static size_t adjust_request_size ( size_t  size,
size_t  align 
)
static

Definition at line 409 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static size_t align_down ( size_t  x,
size_t  align 
)
static

Definition at line 394 of file tlsf.cc.

+ Here is the caller graph for this function:

static void* align_ptr ( const void *  ptr,
size_t  align 
)
static

Definition at line 399 of file tlsf.cc.

+ Here is the caller graph for this function:

static size_t align_up ( size_t  x,
size_t  align 
)
static

Definition at line 389 of file tlsf.cc.

+ Here is the caller graph for this function:

static block_header_t* block_absorb ( block_header_t prev,
block_header_t block 
)
static

Definition at line 561 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int block_can_split ( block_header_t block,
size_t  size 
)
static

Definition at line 536 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static block_header_t* block_from_ptr ( const void *  ptr)
static

Definition at line 342 of file tlsf.cc.

+ Here is the caller graph for this function:

static void block_insert ( control_t control,
block_header_t block 
)
static

Definition at line 530 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int block_is_free ( const block_header_t block)
static

Definition at line 318 of file tlsf.cc.

+ Here is the caller graph for this function:

static int block_is_last ( const block_header_t block)
static

Definition at line 314 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int block_is_prev_free ( const block_header_t block)
static

Definition at line 330 of file tlsf.cc.

+ Here is the caller graph for this function:

static block_header_t* block_link_next ( block_header_t block)
static

Definition at line 370 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static block_header_t* block_locate_free ( control_t control,
size_t  size 
)
static

Definition at line 636 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void block_mark_as_free ( block_header_t block)
static

Definition at line 376 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void block_mark_as_used ( block_header_t block)
static

Definition at line 383 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static block_header_t* block_merge_next ( control_t control,
block_header_t block 
)
static

Definition at line 583 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static block_header_t* block_merge_prev ( control_t control,
block_header_t block 
)
static

Definition at line 570 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static block_header_t* block_next ( const block_header_t block)
static

Definition at line 362 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void* block_prepare_used ( control_t control,
block_header_t block,
size_t  size 
)
static

Definition at line 653 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static block_header_t* block_prev ( const block_header_t block)
static

Definition at line 356 of file tlsf.cc.

+ Here is the caller graph for this function:

static void block_remove ( control_t control,
block_header_t block 
)
static

Definition at line 523 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void block_set_free ( block_header_t block)
static

Definition at line 322 of file tlsf.cc.

+ Here is the caller graph for this function:

static void block_set_prev_free ( block_header_t block)
static

Definition at line 334 of file tlsf.cc.

+ Here is the caller graph for this function:

static void block_set_prev_used ( block_header_t block)
static

Definition at line 338 of file tlsf.cc.

+ Here is the caller graph for this function:

static void block_set_size ( block_header_t block,
size_t  size 
)
static

Definition at line 309 of file tlsf.cc.

+ Here is the caller graph for this function:

static void block_set_used ( block_header_t block)
static

Definition at line 326 of file tlsf.cc.

+ Here is the caller graph for this function:

static size_t block_size ( const block_header_t block)
static

Definition at line 305 of file tlsf.cc.

+ Here is the caller graph for this function:

static block_header_t* block_split ( block_header_t block,
size_t  size 
)
static

Definition at line 541 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void* block_to_ptr ( const block_header_t block)
static

Definition at line 346 of file tlsf.cc.

+ Here is the caller graph for this function:

static void block_trim_free ( control_t control,
block_header_t block,
size_t  size 
)
static

Definition at line 597 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static block_header_t* block_trim_free_leading ( control_t control,
block_header_t block,
size_t  size 
)
static

Definition at line 620 of file tlsf.cc.

+ Here is the call graph for this function:

static void block_trim_used ( control_t control,
block_header_t block,
size_t  size 
)
static

Definition at line 608 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void control_construct ( control_t control)
static

Definition at line 671 of file tlsf.cc.

+ Here is the caller graph for this function:

static void default_walker ( void *  ptr,
size_t  size,
int  used,
void *  user 
)
static

Definition at line 767 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void insert_free_block ( control_t control,
block_header_t block,
int  fl,
int  sl 
)
static

Definition at line 502 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void integrity_walker ( void *  ptr,
size_t  size,
int  used,
void *  user 
)
static

Definition at line 703 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void mapping_insert ( size_t  size,
int *  fli,
int *  sli 
)
static

Definition at line 423 of file tlsf.cc.

+ Here is the caller graph for this function:

static void mapping_search ( size_t  size,
int *  fli,
int *  sli 
)
static

Definition at line 439 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static block_header_t* offset_to_block ( const void *  ptr,
size_t  size 
)
static

Definition at line 351 of file tlsf.cc.

+ Here is the caller graph for this function:

static void remove_free_block ( control_t control,
block_header_t block,
int  fl,
int  sl 
)
static

Definition at line 477 of file tlsf.cc.

+ Here is the caller graph for this function:

static block_header_t* search_suitable_block ( control_t control,
int *  fli,
int *  sli 
)
static

Definition at line 447 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

tlsf_decl int tlsf_ffs ( unsigned int  word)

Definition at line 101 of file tlsf.cc.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

tlsf_decl int tlsf_fls ( unsigned int  word)

Definition at line 105 of file tlsf.cc.

+ Here is the call graph for this function:

tlsf_decl int tlsf_fls_generic ( unsigned int  word)

Definition at line 71 of file tlsf.cc.

+ Here is the caller graph for this function:

tlsf_static_assert ( sizeof(int)*  CHAR_BIT = =32)
tlsf_static_assert ( sizeof(size_t)*CHAR_BIT >=  32)
tlsf_static_assert ( sizeof(size_t)*CHAR_BIT<=  64)
tlsf_static_assert ( sizeof(unsigned int)*CHAR_BIT >=  SL_INDEX_COUNT)
tlsf_static_assert ( ALIGN_SIZE  = =SMALL_BLOCK_SIZE/SL_INDEX_COUNT)

Variable Documentation

const size_t block_header_free_bit = 1 << 0
static

Definition at line 247 of file tlsf.cc.

const size_t block_header_overhead = sizeof(size_t)
static

Definition at line 254 of file tlsf.cc.

const size_t block_header_prev_free_bit = 1 << 1
static

Definition at line 248 of file tlsf.cc.

const size_t block_size_max = tlsf_cast(size_t, 1) << FL_INDEX_MAX
static

Definition at line 265 of file tlsf.cc.

const size_t block_size_min = sizeof(block_header_t) - sizeof(block_header_t*)
static

Definition at line 264 of file tlsf.cc.

const size_t block_start_offset = offsetof(block_header_t, size) + sizeof(size_t)
static

Definition at line 257 of file tlsf.cc.