void StressTest(OSCQueue q) { int i,j; myObj *item; printf("\n\nStress Test...\n\n"); for (i = 1; i < NUM_OBJS; ++i) { objects[i].timetag = rand(); objects[i].data = "stress test"; if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[i])) == FALSE) { printf("OSCQueueInsert() returned FALSE!\n"); return; } if (i % 13 == 0) { item = (myObj *) OSCQueueRemoveEarliest(q); printf("First earliest: %llu\n", item->timetag); item = (myObj *) OSCQueueRemoveEarliest(q); printf("Second earliest: %llu\n", item->timetag); item = (myObj *) OSCQueueRemoveEarliest(q); printf("Third earliest: %llu\n\n", item->timetag); } } while (OSCQueueEarliestTimeTag(q) != OSCTT_BiggestPossibleTimeTag()) { item = (myObj *) OSCQueueRemoveEarliest(q); printf("next from queue: %llu\n", item->timetag); } }
Boolean OSCInvokeMessagesThatAreReady(OSCTimeTag now) { queuedData *x; OSCTimeTag thisTimeTag; globals.lastTimeTag = now; globals.timePassed = TRUE; thisTimeTag = OSCQueueEarliestTimeTag(globals.TheQueue); if (OSCTT_Compare(thisTimeTag, now) > 0) { /* No messages ready yet. */ return FALSE; } #ifdef DEBUG printf("OSCInvokeMessagesThatAreReady(%llx) - yes, some are ready; earliest %llx\n", now, thisTimeTag); #endif while (OSCTT_Compare(thisTimeTag, OSCQueueEarliestTimeTag(globals.TheQueue)) == 0) { x = (queuedData *) OSCQueueRemoveEarliest(globals.TheQueue); #ifdef DEBUG printf("...Just removed earliest entry from queue: %p, TT %llx, %s\n", x, x->timetag, x->type == MESSAGE ? "message" : "bundle"); if (x->type == MESSAGE) { printf("...message %s, len %d, args %p, arglen %d, callbacks %p\n", x->data.message.messageName, x->data.message.length, x->data.message.args, x->data.message.argLength, x->data.message.callbacks); } else { if (x->data.bundle.length == 0) { printf("...bundle is empty.\n"); } else { printf("...bundle len %d, first count %d, first msg %s\n", x->data.bundle.length, *((int *) x->data.bundle.bytes), x->data.bundle.bytes+4); } } PrintPacket(x->myPacket); #endif if (x->type == BUNDLE) { ParseBundle(x); } else { if (x->data.message.callbacks == NOT_DISPATCHED_YET) { if (ParseMessage(x) == FALSE) { /* Problem with this message - flush it. */ PacketRemoveRef(x->myPacket); FreeQD(x); continue; } } CallWholeCallbackList(x->data.message.callbacks, x->data.message.argLength, x->data.message.args, thisTimeTag, x->myPacket->returnAddrOK ? x->myPacket->returnAddr : 0); PacketRemoveRef(x->myPacket); FreeQD(x); } } #ifdef PARANOID if (OSCTT_Compare(thisTimeTag, OSCQueueEarliestTimeTag(globals.TheQueue)) > 0) { fatal_error("OSCInvokeMessagesThatAreReady: corrupt queue!\n" " just did %llx; earliest in queue is now %llx", thisTimeTag, OSCQueueEarliestTimeTag(globals.TheQueue)); } #endif return OSCTT_Compare(OSCQueueEarliestTimeTag(globals.TheQueue), now) <= 0; }
void main (void) { OSCQueue q; myObj *item; q = OSCNewQueue(100, Allocator); if (q == 0) { printf("OSCNewQueue() returned 0!\n"); return; } printf("Made an empty queue: "); OSCQueuePrint(q); printf("Inserting three objects.\n"); objects[0].timetag = 5; objects[0].data = "five"; objects[1].timetag = 2; objects[1].data = "two"; objects[2].timetag = 7; objects[2].data = "seven"; if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[0])) == FALSE) { printf("OSCQueueInsert() returned FALSE!\n"); return; } if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[1])) == FALSE) { printf("OSCQueueInsert() returned FALSE!\n"); return; } if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[2])) == FALSE) { printf("OSCQueueInsert() returned FALSE!\n"); return; } printf("Queue with three objects: "); OSCQueuePrint(q); printf("Earliest time tag is %llu.\n", OSCQueueEarliestTimeTag(q)); printf("Remove front item:\n"); item = (myObj *) OSCQueueRemoveEarliest(q); printf("Time tag %llu, data %s\n", item->timetag, item->data); printf("Queue with two objects: "); OSCQueuePrint(q); printf("Inserting three more objects.\n"); objects[3].timetag = 11; objects[3].data = "eleven"; objects[4].timetag = 6; objects[4].data = "six"; objects[5].timetag = 3; objects[5].data = "three"; if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[3])) == FALSE) { printf("OSCQueueInsert() returned FALSE!\n"); return; } if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[4])) == FALSE) { printf("OSCQueueInsert() returned FALSE!\n"); return; } if (OSCQueueInsert(q, (OSCSchedulableObject) &(objects[5])) == FALSE) { printf("OSCQueueInsert() returned FALSE!\n"); return; } printf("Queue with five objects: "); OSCQueuePrint(q); ScanTest(q); StressTest(q); printf("Done!\n"); }