Blender
V3.3
|
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "MEM_guardedalloc.h"
#include "../../source/blender/blenlib/BLI_strict_flags.h"
#include "atomic_ops.h"
#include "mallocn_intern.h"
Go to the source code of this file.
Classes | |
struct | MemHead |
struct | MemHeadAligned |
Macros | |
#define | MEMHEAD_FROM_PTR(ptr) (((MemHead *)ptr) - 1) |
#define | PTR_FROM_MEMHEAD(memhead) (memhead + 1) |
#define | MEMHEAD_ALIGNED_FROM_PTR(ptr) (((MemHeadAligned *)ptr) - 1) |
#define | MEMHEAD_IS_ALIGNED(memhead) ((memhead)->len & (size_t)MEMHEAD_ALIGN_FLAG) |
#define | MEMHEAD_LEN(memhead) ((memhead)->len & ~((size_t)(MEMHEAD_ALIGN_FLAG))) |
#define | USE_ATOMIC_MAX |
Typedefs | |
typedef struct MemHead | MemHead |
typedef struct MemHeadAligned | MemHeadAligned |
Enumerations | |
enum | { MEMHEAD_ALIGN_FLAG = 1 } |
Variables | |
static unsigned int | totblock = 0 |
static size_t | mem_in_use = 0 |
static size_t | peak_mem = 0 |
static bool | malloc_debug_memset = false |
static void(* | error_callback )(const char *) = NULL |
Memory allocation which keeps track on allocated memory counters
Definition in file mallocn_lockfree_impl.c.
#define MEMHEAD_ALIGNED_FROM_PTR | ( | ptr | ) | (((MemHeadAligned *)ptr) - 1) |
Definition at line 45 of file mallocn_lockfree_impl.c.
Definition at line 43 of file mallocn_lockfree_impl.c.
#define MEMHEAD_IS_ALIGNED | ( | memhead | ) | ((memhead)->len & (size_t)MEMHEAD_ALIGN_FLAG) |
Definition at line 46 of file mallocn_lockfree_impl.c.
#define MEMHEAD_LEN | ( | memhead | ) | ((memhead)->len & ~((size_t)(MEMHEAD_ALIGN_FLAG))) |
Definition at line 47 of file mallocn_lockfree_impl.c.
#define PTR_FROM_MEMHEAD | ( | memhead | ) | (memhead + 1) |
Definition at line 44 of file mallocn_lockfree_impl.c.
#define USE_ATOMIC_MAX |
Definition at line 50 of file mallocn_lockfree_impl.c.
typedef struct MemHeadAligned MemHeadAligned |
anonymous enum |
Enumerator | |
---|---|
MEMHEAD_ALIGN_FLAG |
Definition at line 39 of file mallocn_lockfree_impl.c.
size_t MEM_lockfree_allocN_len | ( | const void * | vmemh | ) |
Definition at line 80 of file mallocn_lockfree_impl.c.
References LIKELY, MEMHEAD_FROM_PTR, and MEMHEAD_LEN.
Referenced by MEM_lockfree_dupallocN(), MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
Definition at line 365 of file mallocn_lockfree_impl.c.
References void.
Referenced by MEM_use_lockfree_allocator().
void* MEM_lockfree_calloc_arrayN | ( | size_t | len, |
size_t | size, | ||
const char * | str | ||
) |
Definition at line 240 of file mallocn_lockfree_impl.c.
References len, mem_in_use, MEM_lockfree_callocN(), MEM_size_safe_multiply(), NULL, print_error(), size(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
void* MEM_lockfree_callocN | ( | size_t | len, |
const char * | str | ||
) |
Definition at line 217 of file mallocn_lockfree_impl.c.
References atomic_add_and_fetch_u(), atomic_add_and_fetch_z(), MemHead::len, len, LIKELY, mem_in_use, NULL, peak_mem, print_error(), PTR_FROM_MEMHEAD, SIZET_ALIGN_4, SIZET_ARG, SIZET_FORMAT, str, totblock, and update_maximum().
Referenced by MEM_lockfree_calloc_arrayN(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
Definition at line 389 of file mallocn_lockfree_impl.c.
Referenced by MEM_use_lockfree_allocator().
Definition at line 121 of file mallocn_lockfree_impl.c.
References MemHeadAligned::alignment, MEM_lockfree_allocN_len(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), MEMHEAD_ALIGNED_FROM_PTR, MEMHEAD_FROM_PTR, MEMHEAD_IS_ALIGNED, NULL, and UNLIKELY.
Referenced by MEM_use_lockfree_allocator().
Definition at line 89 of file mallocn_lockfree_impl.c.
References aligned_free(), atomic_sub_and_fetch_u(), atomic_sub_and_fetch_z(), free(), free_after_leak_detection_message, leak_detector_has_run, len, malloc_debug_memset, mem_in_use, MEMHEAD_ALIGNED_FROM_PTR, MEMHEAD_FROM_PTR, MEMHEAD_IS_ALIGNED, MEMHEAD_LEN, MEMHEAD_REAL_PTR, NULL, print_error(), totblock, and UNLIKELY.
Referenced by MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
unsigned int MEM_lockfree_get_memory_blocks_in_use | ( | void | ) |
Definition at line 404 of file mallocn_lockfree_impl.c.
References totblock.
Referenced by MEM_use_lockfree_allocator().
size_t MEM_lockfree_get_memory_in_use | ( | void | ) |
Definition at line 399 of file mallocn_lockfree_impl.c.
References mem_in_use.
Referenced by MEM_use_lockfree_allocator().
size_t MEM_lockfree_get_peak_memory | ( | void | ) |
Definition at line 415 of file mallocn_lockfree_impl.c.
References peak_mem.
Referenced by MEM_use_lockfree_allocator().
void* MEM_lockfree_malloc_arrayN | ( | size_t | len, |
size_t | size, | ||
const char * | str | ||
) |
Definition at line 285 of file mallocn_lockfree_impl.c.
References len, mem_in_use, MEM_lockfree_mallocN(), MEM_size_safe_multiply(), NULL, print_error(), size(), SIZET_ARG, SIZET_FORMAT, str, and UNLIKELY.
void* MEM_lockfree_mallocN | ( | size_t | len, |
const char * | str | ||
) |
Definition at line 258 of file mallocn_lockfree_impl.c.
References atomic_add_and_fetch_u(), atomic_add_and_fetch_z(), MemHead::len, len, LIKELY, malloc_debug_memset, mem_in_use, NULL, peak_mem, print_error(), PTR_FROM_MEMHEAD, SIZET_ALIGN_4, SIZET_ARG, SIZET_FORMAT, str, totblock, UNLIKELY, and update_maximum().
Referenced by MEM_lockfree_dupallocN(), MEM_lockfree_malloc_arrayN(), MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
void* MEM_lockfree_mallocN_aligned | ( | size_t | len, |
size_t | alignment, | ||
const char * | str | ||
) |
Definition at line 303 of file mallocn_lockfree_impl.c.
References aligned_malloc(), ALIGNED_MALLOC_MINIMUM_ALIGNMENT, MemHeadAligned::alignment, atomic_add_and_fetch_u(), atomic_add_and_fetch_z(), IS_POW2, MemHeadAligned::len, len, LIKELY, malloc_debug_memset, mem_in_use, MEMHEAD_ALIGN_FLAG, MEMHEAD_ALIGN_PADDING, NULL, peak_mem, print_error(), PTR_FROM_MEMHEAD, SIZET_ALIGN_4, SIZET_ARG, SIZET_FORMAT, str, totblock, UNLIKELY, and update_maximum().
Referenced by MEM_lockfree_dupallocN(), MEM_lockfree_reallocN_id(), MEM_lockfree_recallocN_id(), and MEM_use_lockfree_allocator().
const char* MEM_lockfree_name_ptr | ( | void * | vmemh | ) |
Definition at line 421 of file mallocn_lockfree_impl.c.
Referenced by MEM_use_lockfree_allocator().
Definition at line 360 of file mallocn_lockfree_impl.c.
Referenced by MEM_use_lockfree_allocator().
Definition at line 356 of file mallocn_lockfree_impl.c.
Referenced by MEM_use_lockfree_allocator().
Definition at line 370 of file mallocn_lockfree_impl.c.
References mem_in_use, and peak_mem.
Referenced by MEM_use_lockfree_allocator().
Definition at line 140 of file mallocn_lockfree_impl.c.
References MemHeadAligned::alignment, len, LIKELY, MEM_lockfree_allocN_len(), MEM_lockfree_freeN(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), MEMHEAD_ALIGNED_FROM_PTR, MEMHEAD_FROM_PTR, MEMHEAD_IS_ALIGNED, NULL, and str.
Referenced by MEM_use_lockfree_allocator().
Definition at line 176 of file mallocn_lockfree_impl.c.
References MemHeadAligned::alignment, len, LIKELY, MEM_lockfree_allocN_len(), MEM_lockfree_callocN(), MEM_lockfree_freeN(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), MEMHEAD_ALIGNED_FROM_PTR, MEMHEAD_FROM_PTR, MEMHEAD_IS_ALIGNED, NULL, and str.
Referenced by MEM_use_lockfree_allocator().
Definition at line 410 of file mallocn_lockfree_impl.c.
References mem_in_use, and peak_mem.
Referenced by MEM_use_lockfree_allocator().
Definition at line 384 of file mallocn_lockfree_impl.c.
References error_callback.
Referenced by MEM_use_lockfree_allocator().
Definition at line 394 of file mallocn_lockfree_impl.c.
References malloc_debug_memset.
Referenced by MEM_use_lockfree_allocator().
|
static |
Definition at line 65 of file mallocn_lockfree_impl.c.
References error_callback, and str.
Referenced by MEM_lockfree_calloc_arrayN(), MEM_lockfree_callocN(), MEM_lockfree_freeN(), MEM_lockfree_malloc_arrayN(), MEM_lockfree_mallocN(), and MEM_lockfree_mallocN_aligned().
MEM_INLINE void update_maximum | ( | size_t * | maximum_value, |
size_t | value | ||
) |
Definition at line 52 of file mallocn_lockfree_impl.c.
References atomic_fetch_and_update_max_z().
Referenced by MEM_lockfree_callocN(), MEM_lockfree_mallocN(), and MEM_lockfree_mallocN_aligned().
Definition at line 37 of file mallocn_lockfree_impl.c.
Referenced by MEM_lockfree_set_error_callback(), and print_error().
|
static |
Definition at line 35 of file mallocn_lockfree_impl.c.
Referenced by MEM_lockfree_freeN(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), and MEM_lockfree_set_memory_debug().
|
static |
Definition at line 34 of file mallocn_lockfree_impl.c.
Referenced by MEM_lockfree_calloc_arrayN(), MEM_lockfree_callocN(), MEM_lockfree_freeN(), MEM_lockfree_get_memory_in_use(), MEM_lockfree_malloc_arrayN(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), MEM_lockfree_printmemlist_stats(), and MEM_lockfree_reset_peak_memory().
|
static |
Definition at line 34 of file mallocn_lockfree_impl.c.
Referenced by MEM_lockfree_callocN(), MEM_lockfree_get_peak_memory(), MEM_lockfree_mallocN(), MEM_lockfree_mallocN_aligned(), MEM_lockfree_printmemlist_stats(), and MEM_lockfree_reset_peak_memory().
|
static |
Definition at line 33 of file mallocn_lockfree_impl.c.
Referenced by MEM_lockfree_callocN(), MEM_lockfree_freeN(), MEM_lockfree_get_memory_blocks_in_use(), MEM_lockfree_mallocN(), and MEM_lockfree_mallocN_aligned().