2011-08-30 14:01:33 +00:00
|
|
|
|
|
|
|
#ifndef __CORE_ALLOC_H__
|
|
|
|
#define __CORE_ALLOC_H__
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdbool.h>
|
2011-12-19 20:12:52 +00:00
|
|
|
#include "config.h"
|
2023-01-02 19:49:56 +00:00
|
|
|
#include "buflib.h"
|
2023-01-08 06:42:27 +00:00
|
|
|
#include "chunk_alloc.h"
|
2011-08-30 14:01:33 +00:00
|
|
|
|
|
|
|
/* All functions below are wrappers for functions in buflib.h, except
|
|
|
|
* they have a predefined context
|
|
|
|
*/
|
2011-12-19 20:12:52 +00:00
|
|
|
void core_allocator_init(void) INIT_ATTR;
|
2022-10-15 22:55:39 +00:00
|
|
|
int core_alloc(size_t size);
|
|
|
|
int core_alloc_ex(size_t size, struct buflib_callbacks *ops);
|
|
|
|
int core_alloc_maximum(size_t *size, struct buflib_callbacks *ops);
|
2011-08-30 14:01:33 +00:00
|
|
|
bool core_shrink(int handle, void* new_start, size_t new_size);
|
2022-04-03 09:48:14 +00:00
|
|
|
void core_pin(int handle);
|
|
|
|
void core_unpin(int handle);
|
|
|
|
unsigned core_pin_count(int handle);
|
2011-08-30 14:01:33 +00:00
|
|
|
int core_free(int handle);
|
|
|
|
size_t core_available(void);
|
2013-05-29 05:07:34 +00:00
|
|
|
size_t core_allocatable(void);
|
2023-01-02 19:18:02 +00:00
|
|
|
|
|
|
|
#ifdef BUFLIB_DEBUG_CHECK_VALID
|
2014-01-09 20:37:07 +00:00
|
|
|
void core_check_valid(void);
|
|
|
|
#endif
|
2011-08-30 14:01:33 +00:00
|
|
|
|
|
|
|
/* DO NOT ADD wrappers for buflib_buffer_out/in. They do not call
|
|
|
|
* the move callbacks and are therefore unsafe in the core */
|
|
|
|
|
2023-01-02 19:18:02 +00:00
|
|
|
#ifdef BUFLIB_DEBUG_PRINT
|
|
|
|
int core_get_num_blocks(void);
|
|
|
|
bool core_print_block_at(int block_num, char* buf, size_t bufsize);
|
2011-08-30 14:01:33 +00:00
|
|
|
|
2011-10-05 18:32:19 +00:00
|
|
|
/* frees the debug test alloc created at initialization,
|
2023-01-02 19:18:02 +00:00
|
|
|
* since this is the first any further alloc should force a compaction run
|
|
|
|
* only used if debug print is active */
|
2011-10-05 18:32:19 +00:00
|
|
|
bool core_test_free(void);
|
2023-01-02 19:18:02 +00:00
|
|
|
#endif
|
2011-10-05 18:32:19 +00:00
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
static inline void* core_get_data(int handle)
|
|
|
|
{
|
|
|
|
extern struct buflib_context core_ctx;
|
|
|
|
return buflib_get_data(&core_ctx, handle);
|
|
|
|
}
|
2011-09-24 13:19:34 +00:00
|
|
|
|
2023-01-14 18:50:15 +00:00
|
|
|
static inline void* core_get_data_pinned(int handle)
|
|
|
|
{
|
|
|
|
extern struct buflib_context core_ctx;
|
|
|
|
return buflib_get_data_pinned(&core_ctx, handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void core_put_data_pinned(void *data)
|
|
|
|
{
|
|
|
|
extern struct buflib_context core_ctx;
|
|
|
|
buflib_put_data_pinned(&core_ctx, data);
|
|
|
|
}
|
|
|
|
|
2023-01-08 06:42:27 +00:00
|
|
|
/* core context chunk_alloc */
|
|
|
|
static inline bool core_chunk_alloc_init(struct chunk_alloc_header *hdr,
|
|
|
|
size_t chunk_size, size_t max_chunks)
|
|
|
|
{
|
|
|
|
extern struct buflib_context core_ctx;
|
|
|
|
return chunk_alloc_init(hdr, &core_ctx, chunk_size, max_chunks);
|
|
|
|
}
|
2011-08-30 14:01:33 +00:00
|
|
|
#endif /* __CORE_ALLOC_H__ */
|