cwist
Modern C web framework with libttak runtime
Loading...
Searching...
No Matches
gc.h
Go to the documentation of this file.
1
6#ifndef __CWIST_CORE_MEM_GC_H__
7#define __CWIST_CORE_MEM_GC_H__
8
9#include <stdbool.h>
10#include <stddef.h>
11#include <ttak/compat/stdatomic.h>
12#include <ttak/mem/epoch_gc.h>
13
20typedef struct cwist_gc {
21 ttak_epoch_gc_t impl;
25 _Atomic bool auto_rotated;
27
34void cwist_gc(cwist_gc_t *gc, bool manual_rotation);
35
44
49
56void cwist_gc_auto_rotate(cwist_gc_t *gc, bool enabled);
57
62
71void cwist_reg_ptr(cwist_gc_t *gc, void *ptr);
72
91void cwist_reg_ptr_sized(cwist_gc_t *gc, void *ptr, size_t size);
92
101ttak_epoch_gc_t *cwist_gc_raw(cwist_gc_t *gc);
102
114void *cwist_ebr_alloc(size_t size);
115
133void cwist_ebr_free(void *ptr);
134
143void cwist_gc_pipeline_tick(void);
144
161void cwist_full_gc(bool enable);
162
166bool cwist_full_gc_enabled(void);
167
173bool cwist_full_gc_locked(void);
174
181void *cwist_full_gc_guard_page(void);
182
189void cwist_gc_scope_track(void *ptr);
190
202bool cwist_gc_scope_untrack(void *ptr);
203
225bool cwist_gc_scope_disown(void *ptr);
226
258void cwist_gc_scope_flush(void);
259
265
276typedef atomic_bool cwist_release_guard_t;
277
282
289
301typedef void (*cwist_conn_close_fn)(void *handle);
302
320void cwist_conn_registry_track(void *handle, cwist_conn_close_fn close_fn);
321
333bool cwist_conn_registry_adopt(void *handle);
334
351bool cwist_conn_registry_untrack(void *handle);
352
365
373
383
384#endif
void cwist_full_gc(bool enable)
Enable or disable full-GC mode process-wide.
Definition gc.c:483
ttak_epoch_gc_t * cwist_gc_raw(cwist_gc_t *gc)
Obtain the raw libttak epoch GC pointer (advanced usage).
Definition gc.c:321
void cwist_gc_auto_rotate(cwist_gc_t *gc, bool enabled)
Toggle whether the GC context reclaims automatically.
Definition gc.c:212
void cwist_conn_registry_sweep_all(void)
Sweep every thread's pending-sweep list right now. This is what the process-exit (atexit) hook calls;...
Definition gc.c:1052
bool cwist_conn_registry_untrack(void *handle)
Remove a handle from the registry before closing it yourself through the normal explicit path.
Definition gc.c:1010
void cwist_ebr_free(void *ptr)
Defer release of a block shared across threads via epoch reclamation.
Definition gc.c:350
bool cwist_gc_scope_disown(void *ptr)
Remove ptr from the current thread's pending-sweep list without freeing it, because ownership is bein...
Definition gc.c:766
void cwist_reg_ptr(cwist_gc_t *gc, void *ptr)
Register a pointer without specifying a size (defaults to 0).
Definition gc.c:236
bool cwist_full_gc_enabled(void)
Check whether full-GC mode is currently enabled.
Definition gc.c:515
void cwist_release_guard_init(cwist_release_guard_t *guard)
Initialize a release guard to its unclaimed state.
Definition gc.c:366
bool cwist_conn_registry_adopt(void *handle)
Make the calling thread the owner of a tracked handle.
Definition gc.c:1025
bool cwist_gc_auto_rotated(cwist_gc_t *gc)
Check whether the GC context is currently set to auto-rotate.
Definition gc.c:222
void(* cwist_conn_close_fn)(void *handle)
Full-GC's connection registry: thread/process-exit sweep for resources that aren't plain cwist_alloc(...
Definition gc.h:301
void cwist_gc_shutdown(cwist_gc_t *gc)
Shut down and free internal GC state.
Definition gc.c:192
struct cwist_gc cwist_gc_t
High-level wrapper over libttak's epoch GC.
bool cwist_release_guard_acquire(cwist_release_guard_t *guard)
Attempt to claim the guard.
Definition gc.c:376
void cwist_gc_rotate(cwist_gc_t *gc)
Rotate the GC epoch and reclaim retired nodes.
Definition gc.c:203
void cwist_gc_scope_flush(void)
Retire every block still on the current thread's pending-sweep list right now, instead of waiting for...
Definition gc.c:776
size_t cwist_conn_registry_pending_count(void)
Number of tracked connections the calling thread owns. Introspection/testing helper.
Definition gc.c:1060
void cwist_gc_pipeline_tick(void)
Drive the EBR pipeline: attempt to advance the epoch and run any cwist_ebr_free() callbacks that are ...
Definition gc.c:358
void cwist_conn_registry_flush(void)
Close every handle the calling thread owns right now, without waiting for thread exit....
Definition gc.c:1041
bool cwist_gc_scope_untrack(void *ptr)
Remove a block from the current thread's pending-sweep list.
Definition gc.c:734
bool cwist_full_gc_locked(void)
Check whether the full-GC toggle has been latched (i.e. cwist_full_gc() has been called once already ...
Definition gc.c:524
void cwist_reg_ptr_sized(cwist_gc_t *gc, void *ptr, size_t size)
Register a pointer and its size for better accounting.
Definition gc.c:261
void cwist_conn_registry_track(void *handle, cwist_conn_close_fn close_fn)
Register a connection handle for the full-GC exit sweep, owned by the calling thread (full-GC mode on...
Definition gc.c:984
atomic_bool cwist_release_guard_t
One-shot guard ensuring a shared teardown path runs exactly once.
Definition gc.h:276
void * cwist_ebr_alloc(size_t size)
Allocate a block meant to be released through cwist_ebr_free().
Definition gc.c:331
size_t cwist_gc_scope_pending_count(void)
Number of blocks currently on the calling thread's pending-sweep list. Introspection/testing helper.
Definition gc.c:784
void cwist_gc_scope_track(void *ptr)
Register a cwist_alloc() block with the current thread's pending-sweep list (full-GC mode only).
Definition gc.c:707
void * cwist_full_gc_guard_page(void)
Raw pointer to the full-GC toggle's guard page, or NULL if the mmap() backing it failed at process st...
Definition gc.c:533
High-level wrapper over libttak's epoch GC.
Definition gc.h:20
_Atomic bool auto_rotated
Check if GC should scan and reclaim objects.
Definition gc.h:25
bool initialized
Check if CWIST GC has initialized.
Definition gc.h:23
ttak_epoch_gc_t impl
Definition gc.h:21