1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * Non-sleeping memory allocation
6 * Copyright (C) 2006,2007 Nedko Arnaudov <nedko@arnaudov.name>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *****************************************************************************/
23 #ifndef MEMORY_ATOMIC_H__7B572547_304D_4597_8808_990BE4476CC3__INCLUDED
24 #define MEMORY_ATOMIC_H__7B572547_304D_4597_8808_990BE4476CC3__INCLUDED
26 typedef void * rtsafe_memory_pool_handle
;
30 rtsafe_memory_pool_create(
31 size_t data_size
, /* chunk size */
32 size_t min_preallocated
, /* min chunks preallocated */
33 size_t max_preallocated
, /* max chunks preallocated */
34 bool enforce_thread_safety
, /* true - enforce thread safety (internal mutex),
35 false - assume caller code is already thread-safe */
36 rtsafe_memory_pool_handle
* pool_ptr
);
40 rtsafe_memory_pool_destroy(
41 rtsafe_memory_pool_handle pool
);
45 rtsafe_memory_pool_sleepy(
46 rtsafe_memory_pool_handle pool
);
48 /* will not sleep, returns NULL if no memory is available */
50 rtsafe_memory_pool_allocate(
51 rtsafe_memory_pool_handle pool
);
53 /* may sleep, will not fail */
55 rtsafe_memory_pool_allocate_sleepy(
56 rtsafe_memory_pool_handle pool
);
60 rtsafe_memory_pool_deallocate(
61 rtsafe_memory_pool_handle pool
,
64 typedef void * rtsafe_memory_handle
;
72 bool enforce_thread_safety
, /* true - enforce thread safety (internal mutex),
73 false - assume caller code is already thread-safe */
74 rtsafe_memory_handle
* handle_ptr
);
76 /* will not sleep, returns NULL if no memory is available */
78 rtsafe_memory_allocate(
79 rtsafe_memory_handle handle_ptr
,
85 rtsafe_memory_handle handle_ptr
);
89 rtsafe_memory_deallocate(
94 rtsafe_memory_handle handle_ptr
);
96 #endif /* #ifndef MEMORY_ATOMIC_H__7B572547_304D_4597_8808_990BE4476CC3__INCLUDED */