2012-05-03 00:24:15 -07:00
|
|
|
#include "rr.h"
|
|
|
|
|
|
|
|
namespace rr {
|
2012-05-03 02:00:04 -07:00
|
|
|
GC::Queue* queue;
|
2012-05-03 00:24:15 -07:00
|
|
|
|
2012-05-03 02:00:04 -07:00
|
|
|
GC::Queue::Queue() : first(0), divider(0), last(0){
|
|
|
|
first = new GC::Queue::Node(NULL);
|
|
|
|
divider = first;
|
|
|
|
last = first;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GC::Queue::Enqueue(void* reference) {
|
|
|
|
last->next = new Node(reference);
|
|
|
|
last = last->next;
|
|
|
|
while (first != divider) {
|
|
|
|
Node* tmp = first;
|
|
|
|
first = first->next;
|
|
|
|
delete tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void* GC::Queue::Dequeue() {
|
|
|
|
void* result = NULL;
|
|
|
|
if (divider != last) {
|
|
|
|
result = divider->next->value;
|
|
|
|
divider = divider->next;
|
2012-05-03 00:24:15 -07:00
|
|
|
}
|
2012-05-03 02:00:04 -07:00
|
|
|
return result;
|
2012-05-03 00:24:15 -07:00
|
|
|
}
|
2012-05-03 02:00:04 -07:00
|
|
|
|
|
|
|
void GC::Finalize(void* phantom) {
|
|
|
|
queue->Enqueue(phantom);
|
2012-05-03 00:24:15 -07:00
|
|
|
}
|
2012-05-03 02:00:04 -07:00
|
|
|
void GC::Drain(v8::GCType type, v8::GCCallbackFlags flags) {
|
|
|
|
for(Phantom phantom = queue->Dequeue(); phantom.NotNull(); phantom = queue->Dequeue()) {
|
|
|
|
phantom.destroy();
|
2012-05-03 00:24:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void GC::Init() {
|
2012-05-03 02:00:04 -07:00
|
|
|
queue = new GC::Queue();
|
2012-05-03 10:56:41 -07:00
|
|
|
v8::V8::AddGCPrologueCallback(GC::Drain);
|
2012-05-03 00:24:15 -07:00
|
|
|
}
|
|
|
|
}
|