buflib_get_data(): static inline ensures it will be inlined
[maemo-rb.git] / apps / plugins / lib / buflib.h
blob47ad57f526710c3374075f83eb506d2e28ae806d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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.
14 * Copyright (C) 2009 Andrew Mahone
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.
21 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
22 * KIND, either express or implied.
24 ****************************************************************************/
26 #ifndef _BUFLIB_H_
27 #include <plugin.h>
29 union buflib_data
31 intptr_t val;
32 union buflib_data *ptr;
35 struct buflib_context
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 *buf_start;
42 union buflib_data *alloc_end;
43 bool compact;
46 void buflib_init(struct buflib_context *context, void *buf, size_t size);
47 int buflib_alloc(struct buflib_context *context, size_t size);
48 void buflib_free(struct buflib_context *context, int handle);
49 void* buflib_buffer_out(struct buflib_context *ctx, size_t *size);
50 void buflib_buffer_in(struct buflib_context *ctx, int size);
54 static inline void* buflib_get_data(struct buflib_context *context, int handle)
56 return (void*)(context->handle_table[-handle].ptr);
58 #endif