Embedded Artistry Framework
Embedded Systems C++ Framework
Functions | Variables
malloc_threadx.c File Reference
#include <assert.h>
#include <malloc.h>
#include <stdbool.h>
#include <stdint.h>
#include <threadx/tx_api.h>
Include dependency graph for malloc_threadx.c:

Functions

 __attribute__ ((weak))
 
void malloc_addblock (void *addr, size_t size)
 malloc_addblock must be called before memory allocation calls are made. More...
 
void * malloc (size_t size)
 Allocates size bytes of uninitialized storage. More...
 
void free (void *ptr)
 Deallocates allocated memory space. More...
 

Variables

static TX_BYTE_POOL malloc_pool_
 ThreadX internal memory pool stucture. More...
 
static volatile bool initialized_ = false
 Flag that is used in malloc() to cause competing threads to wait until initialization is completed before allocating memory. More...
 

Function Documentation

◆ __attribute__()

__attribute__ ( (weak)  )

◆ free()

void free ( void *  ptr)

Deallocates allocated memory space.

Deallocates the space previously allocated by

See also
malloc,
calloc,
realloc. If ptr is a null pointer, the function does nothing.

The behavior is undefined if the value of ptr does not equal a value returned earlier by

See also
malloc,
calloc,
realloc.

The behavior is undefined if the memory area referred to by ptr has already been deallocated, that is, free() or realloc has already been called with ptr as the argument and no calls to malloc, calloc or realloc resulted in a pointer equal to ptr afterwards.

The behavior is undefined if after free returns, an access is made through the pointer ptr (unless another allocation function happened to result in a pointer value equal to ptr)

Parameters
ptrpointer to the memory to deallocate

free should NEVER be called before malloc is init'd

References assert, initialized_, r, tx_byte_release(), and TX_SUCCESS.

Referenced by _readMemory(), aligned_free(), calloc_test(), char_test(), embvm::VirtualHeap< THeapImpl >::free(), heapsort(), heapsort_r(), realloc(), reallocf(), strdup_test(), strndup_test(), and t_choose().

Here is the caller graph for this function:

◆ malloc()

void* malloc ( size_t  size)

Allocates size bytes of uninitialized storage.

If size is zero, the behavior is implementation defined (null pointer may be returned, or some non-null pointer may be returned that may not be used to access storage, but has to be passed to

See also
free). malloc is thread-safe: it behaves as though only accessing the memory locations visible through its argument, and not any static storage.
Parameters
sizenumber of bytes to allocate
Returns
On success, returns the pointer to the beginning of newly allocated memory. The returned pointer must be deallocated with
See also
free() or
realloc(). On failure, returns a null pointer.

In the ThreadX implementaiton, we make sure the ThreadX pool has been created before we try to allocate memory, or there will be an error. We sleep our threads until memory has been added.

References assert, initialized_, malloc_pool_, NULL, r, tx_byte_allocate(), TX_SUCCESS, tx_thread_sleep(), and TX_WAIT_FOREVER.

Referenced by _readMemory(), aligned_malloc(), calloc(), char_test(), heapsort(), heapsort_r(), realloc(), strdup(), strndup(), t_choose(), and vasprintf().

Here is the caller graph for this function:

◆ malloc_addblock()

void malloc_addblock ( void *  addr,
size_t  size 
)

malloc_addblock must be called before memory allocation calls are made.

Assign blocks of memory for use by malloc().

In this ThreadX implementation, malloc() calls will block until memory has been allocated

References assert, initialized_, malloc_pool_, r, tx_byte_pool_create, and TX_SUCCESS.

Referenced by allocate_memory(), NRF52DongleHWPlatform::earlyInitHook_(), and nRF52DK_FrameworkDemoPlatform::earlyInitHook_().

Here is the caller graph for this function:

Variable Documentation

◆ initialized_

volatile bool initialized_ = false
static

Flag that is used in malloc() to cause competing threads to wait until initialization is completed before allocating memory.

Referenced by free(), malloc(), and malloc_addblock().

◆ malloc_pool_

TX_BYTE_POOL malloc_pool_
static

ThreadX internal memory pool stucture.

Referenced by malloc(), and malloc_addblock().