LispBM
Macros | Functions | Variables
lbm_memory.c File Reference
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include "lbm_memory.h"
#include "platform_mutex.h"
Include dependency graph for lbm_memory.c:

Macros

#define FREE_OR_USED   0
 
#define END   1
 
#define START   2
 
#define START_END   3
 
#define INIT   0
 
#define FREE_LENGTH_CHECK   1
 
#define SKIP   2
 
#define ALLOC_DONE   0xF00DF00D
 
#define ALLOC_FAILED   0xDEADBEAF
 
#define WORD_IX_SHIFT   5
 
#define WORD_MOD_MASK   0x1F
 
#define BITMAP_SIZE_SHIFT   4
 

Functions

void lbm_request_gc (void)
 
int lbm_memory_init (lbm_uint *data, lbm_uint data_size, lbm_uint *bits, lbm_uint bits_size)
 
void lbm_memory_set_reserve (lbm_uint num_words)
 
lbm_uint lbm_memory_get_reserve (void)
 
static lbm_uint address_to_bitmap_ix (lbm_uint *ptr)
 
lbm_int lbm_memory_address_to_ix (lbm_uint *ptr)
 
static lbm_uintbitmap_ix_to_address (lbm_uint ix)
 
static lbm_uint status (lbm_uint i)
 
static void set_status (lbm_uint i, lbm_uint status)
 
lbm_uint lbm_memory_num_words (void)
 
lbm_uint lbm_memory_num_free (void)
 
lbm_uint lbm_memory_longest_free (void)
 
static lbm_uintlbm_memory_allocate_internal (lbm_uint num_words)
 
lbm_uintlbm_memory_allocate (lbm_uint num_words)
 
int lbm_memory_free (lbm_uint *ptr)
 
void * lbm_malloc (size_t size)
 
void * lbm_malloc_reserve (size_t size)
 
void lbm_free (void *ptr)
 
int lbm_memory_shrink (lbm_uint *ptr, lbm_uint n)
 
int lbm_memory_ptr_inside (lbm_uint *ptr)
 

Variables

static lbm_uintbitmap = NULL
 
static lbm_uintmemory = NULL
 
static lbm_uint memory_size
 
static lbm_uint bitmap_size
 
static lbm_uint memory_base_address = 0
 
static lbm_uint memory_num_free = 0
 
static volatile lbm_uint memory_reserve_level = 0
 
static mutex_t lbm_mem_mutex
 
static bool lbm_mem_mutex_initialized
 
static lbm_uint alloc_offset = 0
 

Macro Definition Documentation

◆ ALLOC_DONE

#define ALLOC_DONE   0xF00DF00D

◆ ALLOC_FAILED

#define ALLOC_FAILED   0xDEADBEAF

◆ BITMAP_SIZE_SHIFT

#define BITMAP_SIZE_SHIFT   4

◆ END

#define END   1

◆ FREE_LENGTH_CHECK

#define FREE_LENGTH_CHECK   1

◆ FREE_OR_USED

#define FREE_OR_USED   0

◆ INIT

#define INIT   0

◆ SKIP

#define SKIP   2

◆ START

#define START   2

◆ START_END

#define START_END   3

◆ WORD_IX_SHIFT

#define WORD_IX_SHIFT   5

◆ WORD_MOD_MASK

#define WORD_MOD_MASK   0x1F

Function Documentation

◆ address_to_bitmap_ix()

static lbm_uint address_to_bitmap_ix ( lbm_uint ptr)
inlinestatic

◆ bitmap_ix_to_address()

static lbm_uint* bitmap_ix_to_address ( lbm_uint  ix)
inlinestatic

◆ lbm_free()

void lbm_free ( void *  ptr)

Free memory allocated with lbm_malloc

Parameters
Pointerto array to free

◆ lbm_malloc()

void* lbm_malloc ( size_t  size)

Malloc like interface to lbm_memory

Parameters
sizeSize in bytes of memory to allocate.
Returns
Pointer to array or NULL.

◆ lbm_malloc_reserve()

void* lbm_malloc_reserve ( size_t  size)

Allocate memory potentially from the reserved memory.

Parameters
sizeSize in bytes of memory to allocate.
Returns
Pointer to array or NULL.

◆ lbm_memory_address_to_ix()

lbm_int lbm_memory_address_to_ix ( lbm_uint ptr)

◆ lbm_memory_allocate()

lbm_uint* lbm_memory_allocate ( lbm_uint  num_words)

Allocate a number of words from the symbols and arrays memory.

Parameters
num_wordsNumber of words to allocate.
Returns
pointer to allocated array or NULL.

◆ lbm_memory_allocate_internal()

static lbm_uint* lbm_memory_allocate_internal ( lbm_uint  num_words)
static

◆ lbm_memory_free()

int lbm_memory_free ( lbm_uint ptr)

Free an allocated array int the symbols and arrays memory.

Parameters
ptrPointer to array to free.
Returns
1 on success and 0 on failure.

◆ lbm_memory_get_reserve()

lbm_uint lbm_memory_get_reserve ( void  )

Get the number of words of memory that is treated as reserve.

Returns
Number of words that are reserved

◆ lbm_memory_init()

int lbm_memory_init ( lbm_uint data,
lbm_uint  data_size,
lbm_uint bitmap,
lbm_uint  bitmap_size 
)

Initialize the symbols and arrays memory

Parameters
dataPointer to an array of uint32_t for data storage.
data_sizeThe size of the data storage array in number of uint32_t elements.
bitmapPointer to an array of uint32_t for memory allocator meta-data.
bitmap_sizeThe size of the meta-data in number of uint32_t elements.
Returns

◆ lbm_memory_longest_free()

lbm_uint lbm_memory_longest_free ( void  )

Find the length of the longest run of consecutire free indices in the LBM memory.

◆ lbm_memory_num_free()

lbm_uint lbm_memory_num_free ( void  )
Returns
The number of free words in the symbols and arrays memory.

◆ lbm_memory_num_words()

lbm_uint lbm_memory_num_words ( void  )

Size of of the symbols and arrays memory in uint32_t chunks.

Returns
Number of uint32_t words.

◆ lbm_memory_ptr_inside()

int lbm_memory_ptr_inside ( lbm_uint ptr)

Check if a pointer points into the lbm_memory

Parameters
ptr
Returns
1 for yes and 0 for no.

◆ lbm_memory_set_reserve()

void lbm_memory_set_reserve ( lbm_uint  num_words)

Set the size of the memory reserve in words.

Parameters
num_wordsNumber of words to treat as reserve.

◆ lbm_memory_shrink()

int lbm_memory_shrink ( lbm_uint ptr,
lbm_uint  n 
)

Shrink an allocated array.

Parameters
ptrPointer to array to shrink
nNew smaller size of array
Returns
1 on success and 0 on failure.

◆ lbm_request_gc()

void lbm_request_gc ( void  )

Request that the runtime system performs a garbage collection on its earliers convenience. Can be called from any thread and does NOT require that the evaluator is paused.

◆ set_status()

static void set_status ( lbm_uint  i,
lbm_uint  status 
)
inlinestatic

◆ status()

static lbm_uint status ( lbm_uint  i)
inlinestatic

Variable Documentation

◆ alloc_offset

lbm_uint alloc_offset = 0
static

◆ bitmap

lbm_uint* bitmap = NULL
static

◆ bitmap_size

lbm_uint bitmap_size
static

◆ lbm_mem_mutex

mutex_t lbm_mem_mutex
static

◆ lbm_mem_mutex_initialized

bool lbm_mem_mutex_initialized
static

◆ memory

lbm_uint* memory = NULL
static

◆ memory_base_address

lbm_uint memory_base_address = 0
static

◆ memory_num_free

lbm_uint memory_num_free = 0
static

◆ memory_reserve_level

volatile lbm_uint memory_reserve_level = 0
static

◆ memory_size

lbm_uint memory_size
static