Reduct  v4.0.5-1-g4851deb
A functional and immutable language.
Loading...
Searching...
No Matches
gc.h
Go to the documentation of this file.
1#include "reduct/sync.h"
2#ifndef REDUCT_GC_H
3#define REDUCT_GC_H 1
4
5#include <reduct/defs.h>
6
7#include <reduct/handle.h>
8#include <reduct/item.h>
9
10/**
11 * @file gc.h
12 * @brief Garbage collection
13 * @defgroup gc Garbage Collection
14 *
15 * @todo Reimplement Garbage Collector.
16 *
17 * @{
18 */
19
20/**
21 * @brief Global garbage collection-related state structure.
22 * @struct reduct_gc_global_t
23 */
24typedef struct
25{
26 _Atomic(bool) requested;
28
29/**
30 * @brief Initialize a global gc state.
31 *
32 * @param global Pointer to the global gc state to initialize.
33 */
35
36/**
37 * @brief Deinitialize a global gc state.
38 *
39 * @param global Pointer to the global gc state to deinitialize.
40 */
42
43/**
44 * @brief Run the garbage collector.
45 *
46 * @note Usually the garbage collector will only be ran in between the evaluation of two instructions. As such, when
47 * evaluation is not taking place, or when evaluating an instruction, there is no need to retain specific items.
48 *
49 * @param reduct Pointer to the Reduct structure.
50 */
51REDUCT_API void reduct_gc(struct reduct* reduct);
52
53/**
54 * @brief Check if the garbage collector should be ran and run it if so.
55 *
56 * State and env pointer must be specified sep
57 *
58 * @param _reduct Pointer to the Reduct structure.
59 */
60#define REDUCT_GC_CHECK(_reduct) \
61 do \
62 { \
63 if (REDUCT_UNLIKELY(atomic_load_explicit(&_reduct->global->gc.requested, memory_order_relaxed))) \
64 { \
65 reduct_gc(_reduct); \
66 } \
67 } while (0)
68
69/**
70 * @brief Request that the garbage collector be ran without immediately running it.
71 *
72 * @param gc Pointer to the GC environment.
73 */
75{
76 atomic_store_explicit(&gc->requested, true, memory_order_relaxed);
77}
78
79/** @} */
80
81#endif
#define REDUCT_ALWAYS_INLINE
Definition defs.h:61
#define REDUCT_API
Definition defs.h:24
REDUCT_API void reduct_gc_global_deinit(reduct_gc_global_t *global)
Deinitialize a global gc state.
REDUCT_API void reduct_gc_global_init(reduct_gc_global_t *global)
Initialize a global gc state.
static REDUCT_ALWAYS_INLINE void reduct_gc_request(reduct_gc_global_t *gc)
Request that the garbage collector be ran without immediately running it.
Definition gc.h:74
REDUCT_API void reduct_gc(struct reduct *reduct)
Run the garbage collector.
Handle management.
Item management.
Global garbage collection-related state structure.
Definition gc.h:25
_Atomic(bool) requested
Syncronization primitives.