diff options
author | Andrew Mahone <andrew.mahone@gmail.com> | 2009-03-04 21:11:12 +0000 |
---|---|---|
committer | Andrew Mahone <andrew.mahone@gmail.com> | 2009-03-04 21:11:12 +0000 |
commit | b727de604ddab15fe809303181ba18e53197708d (patch) | |
tree | a3d6880b77982fc417e7ff9b714ced4a91dc425c /apps/plugins/lib/buflib.h | |
parent | e54c1cc9a2f9053245feddf70243aa357f18870d (diff) | |
download | rockbox-b727de604ddab15fe809303181ba18e53197708d.tar.gz rockbox-b727de604ddab15fe809303181ba18e53197708d.zip |
FS#9916 buflib plugin memory allocator
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20202 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/lib/buflib.h')
-rw-r--r-- | apps/plugins/lib/buflib.h | 58 |
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 | |||
29 | union buflib_data | ||
30 | { | ||
31 | intptr_t val; | ||
32 | union buflib_data *ptr; | ||
33 | }; | ||
34 | |||
35 | struct 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 | |||
45 | void buflib_init(struct buflib_context *context, void *buf, size_t size); | ||
46 | int buflib_alloc(struct buflib_context *context, size_t size); | ||
47 | void 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 | */ | ||
53 | extern inline __attribute__((always_inline)) | ||
54 | void* buflib_get_data(struct buflib_context *context, int handle) | ||
55 | { | ||
56 | return (void*)(context->handle_table[-handle].ptr); | ||
57 | } | ||
58 | #endif | ||