fix freezing and thawing of read sites where the same value is read multiple times in compile()

This commit is contained in:
Joel Dice 2008-05-15 08:29:19 -06:00
parent 505d6df7ae
commit 2ed6247cec

View File

@ -305,7 +305,7 @@ expect(Context* c, bool v)
class Event { class Event {
public: public:
Event(Context* c): Event(Context* c):
next(0), stack(c->state->stack), promises(0), reads(0), next(0), stack(c->state->stack), promises(0), reads(0), readCount(0),
sequence(c->nextSequence++), stackReset(c->stackReset) sequence(c->nextSequence++), stackReset(c->stackReset)
{ {
assert(c, c->logicalIp >= 0); assert(c, c->logicalIp >= 0);
@ -325,7 +325,7 @@ class Event {
} }
Event(Context*, unsigned sequence, Stack* stack): Event(Context*, unsigned sequence, Stack* stack):
next(0), stack(stack), promises(0), reads(0), next(0), stack(stack), promises(0), reads(0), readCount(0),
sequence(sequence), stackReset(false) sequence(sequence), stackReset(false)
{ } { }
@ -339,6 +339,7 @@ class Event {
Stack* stack; Stack* stack;
CodePromise* promises; CodePromise* promises;
Read* reads; Read* reads;
unsigned readCount;
unsigned sequence; unsigned sequence;
bool stackReset; bool stackReset;
}; };
@ -1106,12 +1107,13 @@ apply(Context* c, BinaryOperation op, unsigned size, Site* a, Site* b)
} }
void void
insertRead(Context* c, Event* thisEvent, int sequence, Value* v, insertRead(Context* c, Event* event, int sequence, Value* v,
unsigned size, Site* target) unsigned size, Site* target)
{ {
Read* r = new (c->zone->allocate(sizeof(Read))) Read* r = new (c->zone->allocate(sizeof(Read)))
Read(size, v, target, 0, thisEvent, thisEvent->reads); Read(size, v, target, 0, event, event->reads);
thisEvent->reads = r; event->reads = r;
++ event->readCount;
// fprintf(stderr, "add read %p to %p\n", r, v); // fprintf(stderr, "add read %p to %p\n", r, v);
@ -1939,13 +1941,20 @@ compile(Context* c)
} }
} }
Site* sites[e->readCount];
unsigned si = 0;
for (Read* r = e->reads; r; r = r->eventNext) { for (Read* r = e->reads; r; r = r->eventNext) {
r->value->source = readSource(c, e->stack, r); r->value->source = readSource(c, e->stack, r);
if (r->value->source) r->value->source->freeze(c);
if (r->value->source) {
assert(c, si < e->readCount);
sites[si++] = r->value->source;
r->value->source->freeze(c);
}
} }
for (Read* r = e->reads; r; r = r->eventNext) { while (si) {
if (r->value->source) r->value->source->thaw(c); sites[--si]->thaw(c);
} }
e->compile(c); e->compile(c);