SystemCall run(block) can now exit the run if it returns false
[io/quag.git] / libs / garbagecollector / source / Collector.h
blobef53d3e5f418a880c7e06df06c545c887c823cdc
1 /*#io
2 docCopyright("Steve Dekorte", 2006)
3 docLicense("BSD revised")
4 docDescription("""A tricolor collector using a Baker treadmill.""")
5 */
7 #ifndef Collector_DEFINED
8 #define Collector_DEFINED 1
10 #include "CollectorMarker.h"
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
16 #define COLLECTOR_FOREACH(self, v, code) \
17 COLLECTMARKER_FOREACH(self->whites, v, code;); \
18 COLLECTMARKER_FOREACH(self->grays, v, code;); \
19 COLLECTMARKER_FOREACH(self->blacks, v, code;);
21 typedef enum
23 COLLECTOR_INITIAL_WHITE,
24 COLLECTOR_GRAY,
25 COLLECTOR_INITIAL_BLACK,
26 COLLECTOR_FREE
27 } CollectorColor;
29 typedef int (CollectorMarkFunc)(void *);
30 typedef void (CollectorWillFreeFunc)(void *);
31 typedef void (CollectorFreeFunc)(void *);
33 typedef struct
35 List *retainedValues;
36 void *markBeforeSweepValue;
38 int pauseCount;
40 CollectorMarker *blacks;
41 CollectorMarker *grays;
42 CollectorMarker *whites;
43 CollectorMarker *freed;
45 float marksPerAlloc;
46 float queuedMarks;
48 size_t allocated;
49 size_t allocatedSweepLevel;
50 float allocatedStep;
52 CollectorMarkFunc *markFunc;
53 CollectorWillFreeFunc *willFreeFunc;
54 CollectorFreeFunc *freeFunc;
56 long clocksUsed;
57 size_t sweepCount;
58 int debugOn;
59 } Collector;
61 COLLECTOR_API Collector *Collector_new(void);
62 COLLECTOR_API void Collector_free(Collector *self);
64 COLLECTOR_API void Collector_check(Collector *self);
66 COLLECTOR_API void Collector_setMarkBeforeSweepValue_(Collector *self, void *v);
68 // callbacks
70 COLLECTOR_API void Collector_setMarkFunc_(Collector *self, CollectorMarkFunc *func);
71 COLLECTOR_API void Collector_setWillFreeFunc_(Collector *self, CollectorWillFreeFunc *func);
72 COLLECTOR_API void Collector_setFreeFunc_(Collector *self, CollectorFreeFunc *func);
74 // marks per alloc
76 COLLECTOR_API void Collector_setMarksPerAlloc_(Collector *self, float n);
77 COLLECTOR_API float Collector_marksPerAlloc(Collector *self);
79 // marks per sweep
81 COLLECTOR_API void Collector_setAllocatedStep_(Collector *self, float n);
82 COLLECTOR_API float Collector_allocatedStep(Collector *self);
84 // debug
86 COLLECTOR_API void Collector_setDebug_(Collector *self, int b);
88 // retaining
90 COLLECTOR_API void *Collector_retain_(Collector *self, void *v);
91 COLLECTOR_API void Collector_stopRetaining_(Collector *self, void *v);
92 COLLECTOR_API void Collector_removeAllRetainedValues(Collector *self);
94 // adding
96 COLLECTOR_API CollectorMarker *Collector_newMarker(Collector *self);
97 COLLECTOR_API void Collector_addValue_(Collector *self, void *v);
99 // collection
101 COLLECTOR_API void Collector_initPhase(Collector *self);
102 COLLECTOR_API size_t Collector_sweepPhase(Collector *self);
103 COLLECTOR_API void Collector_markPhase(Collector *self);
105 COLLECTOR_API size_t Collector_collect(Collector *self);
106 COLLECTOR_API size_t Collector_freeAllValues(Collector *self);
108 // changing colors
110 #define Collector_shouldMark_(self, v) Collector_makeGrayIfWhite_(self, v)
111 void Collector_makeGrayIfWhite_(Collector *self, void *v);
113 void Collector_makeWhite_(Collector *self, CollectorMarker *v);
114 void Collector_makeGray_(Collector *self, CollectorMarker *v);
115 void Collector_makeBlack_(Collector *self, CollectorMarker *v);
117 int Collector_markerIsWhite_(Collector *self, CollectorMarker *m);
118 int Collector_markerIsGray_(Collector *self, CollectorMarker *m);
119 int Collector_markerIsBlack_(Collector *self, CollectorMarker *m);
121 COLLECTOR_API char *Collector_colorNameFor_(Collector *self, void *v);
123 void *Collector_value_addingRefTo_(Collector *self, void *v, void *ref);
125 // pause/resume stack
127 COLLECTOR_API void Collector_pushPause(Collector *self);
128 COLLECTOR_API void Collector_popPause(Collector *self);
129 COLLECTOR_API int Collector_isPaused(Collector *self);
130 COLLECTOR_API double Collector_timeUsed(Collector *self);
132 #include "Collector_inline.h"
134 #ifdef __cplusplus
136 #endif
137 #endif