xref: /haiku/headers/os/media/RealtimeAlloc.h (revision cb3f273dd2ec921b8134f9378a91adb0b2af165b)
1*cb3f273dSStephan Aßmus /*
2*cb3f273dSStephan Aßmus  * Copyright 2009, Haiku, Inc. All rights reserved.
3*cb3f273dSStephan Aßmus  * Distributed under the terms of the MIT License.
4*cb3f273dSStephan Aßmus  */
5*cb3f273dSStephan Aßmus #ifndef _REALTIME_ALLOC_H
652a38012Sejakowatz #define _REALTIME_ALLOC_H
752a38012Sejakowatz 
8*cb3f273dSStephan Aßmus 
952a38012Sejakowatz #include <SupportDefs.h>
1052a38012Sejakowatz 
11*cb3f273dSStephan Aßmus 
12*cb3f273dSStephan Aßmus /*!	Allocation from separate "pools" of memory. Those pools will be locked
13*cb3f273dSStephan Aßmus 	in RAM if realtime allocators are turned on in the BMediaRoster, so don't
14*cb3f273dSStephan Aßmus 	waste this memory unless it's needed. Also, the shared pool is a scarce
15*cb3f273dSStephan Aßmus 	resource, so it's better if you create your own pool for your own needs
16*cb3f273dSStephan Aßmus 	and leave the shared pool for BMediaNode instances and the needs of the
17*cb3f273dSStephan Aßmus 	Media Kit.
18*cb3f273dSStephan Aßmus */
19*cb3f273dSStephan Aßmus 
2052a38012Sejakowatz #if defined(__cplusplus)
2152a38012Sejakowatz extern "C" {
2252a38012Sejakowatz #endif
2352a38012Sejakowatz 
2452a38012Sejakowatz typedef struct rtm_pool rtm_pool;
2552a38012Sejakowatz 
26*cb3f273dSStephan Aßmus /* If out_pool is NULL, the default pool will be created if it isn't */
27*cb3f273dSStephan Aßmus /* already. */
2852a38012Sejakowatz /* If the default pool is already created, it will return EALREADY. */
2952a38012Sejakowatz #if defined(__cplusplus)
30*cb3f273dSStephan Aßmus 
31*cb3f273dSStephan Aßmus status_t rtm_create_pool(rtm_pool** out_pool, size_t total_size,
32*cb3f273dSStephan Aßmus 	const char* name = NULL);
33*cb3f273dSStephan Aßmus 
3452a38012Sejakowatz #else
35*cb3f273dSStephan Aßmus 
36*cb3f273dSStephan Aßmus status_t rtm_create_pool(rtm_pool** out_pool, size_t total_size,
37*cb3f273dSStephan Aßmus 	const char* name);
38*cb3f273dSStephan Aßmus 
3952a38012Sejakowatz #endif
40*cb3f273dSStephan Aßmus 
41f6e4cbb9SAxel Dörfler status_t rtm_delete_pool(rtm_pool* pool);
42*cb3f273dSStephan Aßmus 
43*cb3f273dSStephan Aßmus /* If NULL is passed for 'pool', the default pool is used if it has been */
44*cb3f273dSStephan Aßmus /* created already. */
45f6e4cbb9SAxel Dörfler void* rtm_alloc(rtm_pool* pool, size_t size);
46f6e4cbb9SAxel Dörfler status_t rtm_free(void* data);
47f6e4cbb9SAxel Dörfler status_t rtm_realloc(void** data, size_t new_size);
48f6e4cbb9SAxel Dörfler status_t rtm_size_for(void* data);
49f6e4cbb9SAxel Dörfler status_t rtm_phys_size_for(void* data);
5052a38012Sejakowatz 
51*cb3f273dSStephan Aßmus /* Return the default pool, or NULL if it has not yet been initialized. */
52f6e4cbb9SAxel Dörfler rtm_pool* rtm_default_pool();
5352a38012Sejakowatz 
5452a38012Sejakowatz #if defined(__cplusplus)
5552a38012Sejakowatz }
5652a38012Sejakowatz #endif
5752a38012Sejakowatz 
5852a38012Sejakowatz #endif // _REALTIME_ALLOC_H
5952a38012Sejakowatz 
60