summaryrefslogtreecommitdiff
path: root/apps/plugins/lib/buflib.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/lib/buflib.h')
-rw-r--r--apps/plugins/lib/buflib.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/apps/plugins/lib/buflib.h b/apps/plugins/lib/buflib.h
new file mode 100644
index 0000000000..ddadb1b9a9
--- /dev/null
+++ b/apps/plugins/lib/buflib.h
@@ -0,0 +1,58 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* This is a memory allocator designed to provide reasonable management of free
11* space and fast access to allocated data. More than one allocator can be used
12* at a time by initializing multiple contexts.
13*
14* Copyright (C) 2009 Andrew Mahone
15*
16* This program is free software; you can redistribute it and/or
17* modify it under the terms of the GNU General Public License
18* as published by the Free Software Foundation; either version 2
19* of the License, or (at your option) any later version.
20*
21* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22* KIND, either express or implied.
23*
24****************************************************************************/
25
26#ifndef _BUFLIB_H_
27#include <plugin.h>
28
29union buflib_data
30{
31 intptr_t val;
32 union buflib_data *ptr;
33};
34
35struct buflib_context
36{
37 union buflib_data *handle_table;
38 union buflib_data *first_free_handle;
39 union buflib_data *last_handle;
40 union buflib_data *first_free_block;
41 union buflib_data *alloc_end;
42 bool compact;
43};
44
45void buflib_init(struct buflib_context *context, void *buf, size_t size);
46int buflib_alloc(struct buflib_context *context, size_t size);
47void buflib_free(struct buflib_context *context, int handle);
48
49/* always_inline is due to this not getting inlined when not optimizing, which
50 * leads to an unresolved reference since it doesn't exist as a non-inline
51 * function
52 */
53extern inline __attribute__((always_inline))
54void* buflib_get_data(struct buflib_context *context, int handle)
55{
56 return (void*)(context->handle_table[-handle].ptr);
57}
58#endif