A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 67 lines 2.0 kB view raw
1 2#ifndef __CORE_ALLOC_H__ 3#define __CORE_ALLOC_H__ 4#include <string.h> 5#include <stdbool.h> 6#include "config.h" 7#include "buflib.h" 8#include "chunk_alloc.h" 9 10/* All functions below are wrappers for functions in buflib.h, except 11 * they have a predefined context 12 */ 13void core_allocator_init(void) INIT_ATTR; 14int core_alloc(size_t size); 15int core_alloc_ex(size_t size, struct buflib_callbacks *ops); 16int core_alloc_maximum(size_t *size, struct buflib_callbacks *ops); 17bool core_shrink(int handle, void* new_start, size_t new_size); 18void core_pin(int handle); 19void core_unpin(int handle); 20unsigned core_pin_count(int handle); 21int core_free(int handle); 22size_t core_available(void); 23size_t core_allocatable(void); 24 25#ifdef BUFLIB_DEBUG_CHECK_VALID 26void core_check_valid(void); 27#endif 28 29/* DO NOT ADD wrappers for buflib_buffer_out/in. They do not call 30 * the move callbacks and are therefore unsafe in the core */ 31 32#ifdef BUFLIB_DEBUG_PRINT 33int core_get_num_blocks(void); 34bool core_print_block_at(int block_num, char* buf, size_t bufsize); 35 36/* frees the debug test alloc created at initialization, 37 * since this is the first any further alloc should force a compaction run 38 * only used if debug print is active */ 39bool core_test_free(void); 40#endif 41 42static inline void* core_get_data(int handle) 43{ 44 extern struct buflib_context core_ctx; 45 return buflib_get_data(&core_ctx, handle); 46} 47 48static inline void* core_get_data_pinned(int handle) 49{ 50 extern struct buflib_context core_ctx; 51 return buflib_get_data_pinned(&core_ctx, handle); 52} 53 54static inline void core_put_data_pinned(void *data) 55{ 56 extern struct buflib_context core_ctx; 57 buflib_put_data_pinned(&core_ctx, data); 58} 59 60/* core context chunk_alloc */ 61static inline bool core_chunk_alloc_init(struct chunk_alloc_header *hdr, 62 size_t chunk_size, size_t max_chunks) 63{ 64 extern struct buflib_context core_ctx; 65 return chunk_alloc_init(hdr, &core_ctx, chunk_size, max_chunks); 66} 67#endif /* __CORE_ALLOC_H__ */