Reduct  v1.0.4-3-gdaf0d70
A functional and immutable language.
Loading...
Searching...
No Matches
gc.h
Go to the documentation of this file.
1#ifndef REDUCT_GC_H
2#define REDUCT_GC_H 1
3
4#include "core.h"
5#include "handle.h"
6#include "item.h"
7
8/**
9 * @file gc.h
10 * @brief Garbage collection
11 * @defgroup gc Garbage Collection
12 *
13 * @todo The Garbage collector really needs to be optimized.
14 *
15 * @{
16 */
17
18/**
19 * @brief Run the garbage collector.
20 *
21 * @param reduct The Reduct structure.
22 */
23REDUCT_API void reduct_gc(reduct_t* reduct);
24
25/**
26 * @brief Optionally run the garbage collector if the number of allocated blocks exceeds the threshold.
27
28 * @param reduct The Reduct structure.
29 */
31
32/**
33 * @brief Retain an item, preventing it from being collected by the GC.
34 *
35 * @param reduct The Reduct structure.
36 * @param item The item to retain, must be a item.
37 */
38#define REDUCT_GC_RETAIN(_reduct, _handle) \
39 do \
40 { \
41 (void)(_reduct); \
42 reduct_handle_t __handle = (_handle); \
43 if (REDUCT_HANDLE_IS_ITEM(&__handle)) \
44 { \
45 reduct_item_t* __item = REDUCT_HANDLE_TO_ITEM(&__handle); \
46 __item->retainCount++; \
47 } \
48 } while (0)
49
50/**
51 * @brief Retain a item, preventing it from being collected by the GC.
52 *
53 * @param reduct The Reduct structure.
54 * @param item The item to retain.
55 */
56#define REDUCT_GC_RETAIN_ITEM(_reduct, _item) \
57 do \
58 { \
59 (void)(_reduct); \
60 reduct_item_t* __item = (_item); \
61 __item->retainCount++; \
62 } while (0)
63
64/**
65 * @brief Release a previously retained item, allowing it to be collected by the GC.
66 *
67 * @param reduct The Reduct structure.
68 * @param item The item to release.
69 */
70#define REDUCT_GC_RELEASE(_reduct, _handle) \
71 do \
72 { \
73 (void)(_reduct); \
74 reduct_handle_t __handle = (_handle); \
75 if (REDUCT_HANDLE_IS_ITEM(&__handle)) \
76 { \
77 reduct_item_t* __item = REDUCT_HANDLE_TO_ITEM(&__handle); \
78 __item->retainCount--; \
79 } \
80 } while (0)
81
82/** @} */
83
84#endif
Core definitions and structures.
#define REDUCT_API
Definition defs.h:7
REDUCT_API void reduct_gc_if_needed(reduct_t *reduct)
Optionally run the garbage collector if the number of allocated blocks exceeds the threshold.
Definition gc_impl.h:96
REDUCT_API void reduct_gc(reduct_t *reduct)
Run the garbage collector.
Definition gc_impl.h:108
Handle management.
Item management.
State structure.
Definition core.h:61