2 docCopyright("Steve Dekorte", 2006)
3 docLicense("BSD revised")
4 docDescription("""A tricolor collector using a Baker treadmill.""")
7 #ifndef Collector_DEFINED
8 #define Collector_DEFINED 1
10 #include "CollectorMarker.h"
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;);
23 COLLECTOR_INITIAL_WHITE
,
25 COLLECTOR_INITIAL_BLACK
,
29 typedef int (CollectorMarkFunc
)(void *);
30 typedef void (CollectorWillFreeFunc
)(void *);
31 typedef void (CollectorFreeFunc
)(void *);
36 void *markBeforeSweepValue
;
40 CollectorMarker
*blacks
;
41 CollectorMarker
*grays
;
42 CollectorMarker
*whites
;
43 CollectorMarker
*freed
;
49 size_t allocatedSweepLevel
;
52 CollectorMarkFunc
*markFunc
;
53 CollectorWillFreeFunc
*willFreeFunc
;
54 CollectorFreeFunc
*freeFunc
;
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
);
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
);
76 COLLECTOR_API
void Collector_setMarksPerAlloc_(Collector
*self
, float n
);
77 COLLECTOR_API
float Collector_marksPerAlloc(Collector
*self
);
81 COLLECTOR_API
void Collector_setAllocatedStep_(Collector
*self
, float n
);
82 COLLECTOR_API
float Collector_allocatedStep(Collector
*self
);
86 COLLECTOR_API
void Collector_setDebug_(Collector
*self
, int b
);
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
);
96 COLLECTOR_API CollectorMarker
*Collector_newMarker(Collector
*self
);
97 COLLECTOR_API
void Collector_addValue_(Collector
*self
, void *v
);
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
);
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"