19 #undef afw_pool_create
20 #undef afw_pool_internal_create_thread
23 #define AFW_IMPLEMENTATION_ID "afw_pool_singlethreaded"
27 #define IMPL_DEBUG_LEVEL_detail flag_index_debug_pool_detail
28 #define IMPL_DEBUG_LEVEL_minimal flag_index_debug_pool
30 #define IMPL_PRINT_DEBUG_INFO_Z(level,info_z) \
32 const afw_utf8_t *trace; \
33 if (afw_flag_is_active(xctx->env->IMPL_DEBUG_LEVEL_##level, xctx)) \
35 trace = afw_os_backtrace(0, -1, xctx); \
36 afw_debug_write_fz(NULL, source_z, xctx, \
37 "pool %" AFW_INTEGER_FMT " " \
39 ": before %" AFW_SIZE_T_FMT \
40 " refs %" AFW_INTEGER_FMT \
41 " parent %" AFW_INTEGER_FMT \
46 (self->bytes_allocated), \
47 (self->reference_count), \
48 (afw_integer_t)((self->parent) ? self->parent->pool_number : 0), \
49 (char *)((trace) ? "\n" : ""), \
50 (int)((trace) ? (int)trace->len : 0), \
51 (const char *)((trace) ? (const char *)trace->s : "") \
57 #define IMPL_PRINT_DEBUG_INFO_FZ(level,format_z,...) \
59 const afw_utf8_t *trace; \
60 if (afw_flag_is_active(xctx->env->IMPL_DEBUG_LEVEL_##level, xctx)) \
62 trace = afw_os_backtrace(0, -1, xctx); \
63 afw_debug_write_fz(NULL, source_z, xctx, \
64 "pool %" AFW_INTEGER_FMT " " \
66 ": before %" AFW_SIZE_T_FMT \
67 " refs %" AFW_INTEGER_FMT \
68 " parent %" AFW_INTEGER_FMT \
74 (self->bytes_allocated), \
75 (self->reference_count), \
76 (afw_integer_t)((self->parent) ? self->parent->pool_number : 0), \
77 (char *)((trace) ? "\n" : ""), \
78 (int)((trace) ? (int)trace->len : 0), \
79 (const char *)((trace) ? (const char *)trace->s : "") \
91 child->next_sibling = parent->first_child;
92 parent->first_child = child;
103 for (prev = NULL, sibling = parent->first_child;
105 prev = sibling, sibling = sibling->next_sibling)
107 if (sibling == child) {
109 parent->first_child = sibling->next_sibling;
112 prev->next_sibling = sibling->next_sibling;
133 apr_pool_create(&apr_p, (parent) ? parent->
apr_p : NULL);
141 self->pub.inf = &impl_afw_pool_inf;
143 self->reference_count = 1;
144 self->parent = parent;
150 impl_add_child(parent,
self, xctx);
174 self->thread = xctx->thread;
190 IMPL_PRINT_DEBUG_INFO_FZ(minimal,
201 afw_pool_internal_create_thread(
211 self = impl_pool_create(NULL, xctx);
212 thread = apr_pcalloc(self->apr_p, size);
213 self->thread = thread;
223 afw_pool_internal_create_thread_debug(
228 afw_pool_internal_create_thread(size, xctx);
232 IMPL_PRINT_DEBUG_INFO_FZ(minimal,
254 if (!instance)
return;
257 if (--(self->reference_count) == 0) {
266 impl_afw_pool_add_reference(
273 if (!instance)
return;
284 impl_afw_pool_destroy(
294 if (!instance)
return;
301 e->cleanup(e->data, e->data2, instance, xctx);
309 for (child = self->first_child;
311 child = self->first_child)
318 impl_remove_child(self->parent,
self, xctx);
322 apr_pool_destroy(self->apr_p);
337 rv = apr_pool_create(&self->apr_p,
338 (self->parent) ? self->parent->apr_p : NULL);
339 if (rv != APR_SUCCESS) {
352 impl_afw_pool_calloc(
364 "Attempt to allocate memory for a size of 0",
368 result = apr_pcalloc(self->apr_p, size);
369 self->bytes_allocated += size;
382 impl_afw_pool_malloc(
394 "Attempt to allocate memory for a size of 0",
398 result = apr_palloc(self->apr_p, size);
399 self->bytes_allocated += size;
427 impl_afw_pool_register_cleanup_before(
444 e->cleanup = cleanup;
446 self->first_cleanup = e;
453 impl_afw_pool_deregister_cleanup(
466 e =
self->first_cleanup;
469 if (e->data == data && e->data2 == data2 && e->cleanup == cleanup) {
480 impl_afw_pool_release_debug(
488 IMPL_PRINT_DEBUG_INFO_Z(minimal,
"afw_pool_release");
497 impl_afw_pool_add_reference_debug(
505 IMPL_PRINT_DEBUG_INFO_Z(minimal,
"afw_pool_add_reference");
507 impl_afw_pool_add_reference(instance, xctx);
514 impl_afw_pool_destroy_debug(
522 IMPL_PRINT_DEBUG_INFO_Z(minimal,
"afw_pool_destroy");
524 impl_afw_pool_destroy(instance, xctx);
532 impl_afw_pool_calloc_debug(
541 IMPL_PRINT_DEBUG_INFO_FZ(detail,
545 return impl_afw_pool_calloc(instance, size, xctx);
552 impl_afw_pool_malloc_debug(
561 IMPL_PRINT_DEBUG_INFO_FZ(detail,
565 return impl_afw_pool_malloc(instance, size, xctx);
572 impl_afw_pool_free_debug(
582 IMPL_PRINT_DEBUG_INFO_FZ(detail,
594 impl_afw_pool_register_cleanup_before_debug(
605 IMPL_PRINT_DEBUG_INFO_FZ(minimal,
606 "afw_pool_register_cleanup_before %p %p",
609 impl_afw_pool_register_cleanup_before(instance, data, data2, cleanup, xctx);
616 impl_afw_pool_deregister_cleanup_debug(
627 IMPL_PRINT_DEBUG_INFO_FZ(minimal,
628 "afw_pool_deregister_cleanup_debug %p %p",
631 impl_afw_pool_deregister_cleanup(instance, data, data2, cleanup, xctx);
AFW_DEFINE(const afw_object_t *)
Adaptive Framework Core Internal.
Interface afw_interface implementation declares.
afw_integer_t afw_atomic_integer_increment(AFW_ATOMIC afw_integer_t *mem)
Integer atomic increment.
#define AFW_INTEGER_FMT
Format string specifier used for afw_integer_t.
afw_utf8_octet_t afw_utf8_z_t
NFC normalized UTF-8 null terminated string.
apr_size_t afw_size_t
size_t.
void(* afw_pool_cleanup_function_p_t)(void *data, void *data2, const afw_pool_t *p, afw_xctx_t *xctx)
Typedef for pool cleanup functions.
#define AFW_SIZE_T_FMT
Format string specifier used for afw_size_t.
apr_int64_t afw_integer_t
typedef for big signed int.
struct afw_thread_s afw_thread_t
#define AFW_THROW_ERROR_Z(code, message_z, xctx)
Macro used to set error and 0 rv in xctx and throw it.
void impl_afw_pool_release(const afw_pool_t *instance, afw_xctx_t *xctx)
void impl_afw_pool_free(const afw_pool_t *instance, void *address, afw_size_t size, afw_xctx_t *xctx)
apr_pool_t * impl_afw_pool_get_apr_pool(const afw_pool_t *instance)
#define afw_pool_destroy(instance, xctx)
Call method destroy of interface afw_pool.
#define afw_pool_add_reference(instance, xctx)
Call method add_reference of interface afw_pool.
#define afw_pool_release(instance, xctx)
Call method release of interface afw_pool.
#define afw_pool_calloc_type(instance, type, xctx)
Macro to allocate cleared memory to hold type in pool.
afw_pool_create(const afw_pool_t *parent, afw_xctx_t *xctx)
Create a new pool.
afw_pool_create_debug(const afw_pool_t *parent, afw_xctx_t *xctx, const afw_utf8_z_t *source_z)
Debug version of create a new pool.
Struct for typedef afw_environment_t defined in afw_common.h.
Struct for registered cleanup functions.
afw_pool_cleanup_t * next_cleanup
Next cleanup function.
apr_pool_t * apr_p
Associated apr pool or NULL if it has not been created.
afw_integer_t pool_number
Unique number for pool.
afw_integer_t reference_count
Pools reference count.
Interface afw_pool public struct.
Struct for public part of afw_pool_t.
const afw_pool_t * p
The thread specific pool for the thread.
Interface afw_xctx public struct.