/* EventAdd -- add an event to the buffer */ void EventAdd(Event ev, size_t length) { AVER(eventInited); if (!mps_lib_event_filter(ev, length)) return ; if(length > (size_t)(EventLimit - EventNext)) EventFlush(); /* @@@@ should pass length */ /** \todo ajcd 2012-08-02: This is not thread-safe. Does it need to be, or are the callers all locked? */ AVER(length <= (size_t)(EventLimit - EventNext)); (void)mps_lib_memcpy(EventNext, ev, length); EventNext += length ; }
static void shieldQueue(Arena arena, Seg seg) { Shield shield; /* <design/trace/#fix.noaver> */ AVERT_CRITICAL(Arena, arena); shield = ArenaShield(arena); SHIELD_AVERT_CRITICAL(Seg, seg); if (SegIsSynced(seg) || seg->queued) return; if (SegIsExposed(seg)) { /* This can occur if the mutator isn't suspended, we expose a segment, then raise the shield on it. In this case, the mutator isn't allowed to see the segment, but we don't need to queue it until its covered. */ shieldSuspend(arena); return; } /* Allocate or extend the shield queue if necessary. */ if (shield->next >= shield->length) { void *p; Res res; Count length; AVER(shield->next == shield->length); if (shield->length == 0) length = ShieldQueueLENGTH; else length = shield->length * 2; res = ControlAlloc(&p, arena, length * sizeof shield->queue[0]); if (res != ResOK) { AVER(ResIsAllocFailure(res)); /* Carry on with the existing queue. */ } else { if (shield->length > 0) { Size oldSize = shield->length * sizeof shield->queue[0]; AVER(shield->queue != NULL); mps_lib_memcpy(p, shield->queue, oldSize); ControlFree(arena, shield->queue, oldSize); } shield->queue = p; shield->length = length; } } /* Queue unavailable, so synchronize now. Or if the mutator is not yet suspended and the code raises the shield on a covered segment, protect it now, because that's probably better than suspending the mutator. */ if (shield->length == 0 || !shield->suspended) { shieldSync(shield, seg); return; } AVER_CRITICAL(shield->limit <= shield->length); AVER_CRITICAL(shield->next <= shield->limit); /* If we failed to extend the shield queue array, degrade to an LRU circular buffer. */ if (shield->next >= shield->length) shield->next = 0; AVER_CRITICAL(shield->next < shield->length); AVER_CRITICAL(shield->length > 0); /* If the limit is less than the length, then the queue array has yet to be filled, and next is an uninitialized entry. Otherwise it's the tail end from last time around, and needs to be flushed. */ if (shield->limit >= shield->length) { AVER_CRITICAL(shield->limit == shield->length); shieldFlushEntry(shield, shield->next); } shield->queue[shield->next] = seg; ++shield->next; seg->queued = TRUE; if (shield->next >= shield->limit) shield->limit = shield->next; }