PEGASUS_THREAD_RETURN PEGASUS_THREAD_CDECL deq(void * parm) { Thread* my_thread = (Thread *)parm; parmdef * Parm = (parmdef *)my_thread->get_parm(); Uint32 type, key; int first = Parm->first; int second = Parm->second; int count = Parm->count; Condition * condstart = Parm->cond_start; MessageQueue * mq = Parm->mq; condstart->signal(my_thread->self()); Message * message; type = 0; key = 0; while (type != MY_CANCEL_TYPE) { message = mq->dequeue(); while (!message) { #if defined PEGASUS_OS_SOLARIS && defined SUNOS_5_6 pegasus_sleep(1); #endif message = mq->dequeue(); } key = message->getKey(); type = message->getType(); delete message; if (type == 19) assert(key == 10946); } if (verbose) #if defined (PEGASUS_OS_VMS) // // pegasus_thread_self returns long-long-unsigned. // printf("Received Cancel Message, %llu about to end\n", pegasus_thread_self()); #else cout << "Received Cancel Message, " << pegasus_thread_self() << " about to end\n"; #endif my_thread->exit_self(0); return NULL; }
ThreadReturnType PEGASUS_THREAD_CDECL deq(void * parm) { Thread* my_thread = (Thread *)parm; parmdef * Parm = (parmdef *)my_thread->get_parm(); MessageType type; int first = Parm->first; int second = Parm->second; int count = Parm->count; Condition * condstart = Parm->cond_start; MessageQueue * mq = Parm->mq; condstart->signal(); Message * message; type = 0; while (type != CLOSE_CONNECTION_MESSAGE) { message = mq->dequeue(); while (!message) { message = mq->dequeue(); } type = message->getType(); delete message; } if (verbose) { #if defined (PEGASUS_OS_VMS) // // Threads::self returns long-long-unsigned. // printf("Received Cancel Message, %llu about to end\n", Threads::self()); #else cout << "Received Cancel Message, " << Threads::self() << " about to end\n"; #endif } return ThreadReturnType(0); }
void TestMessageQueue1() { MessageQueue q; Uint32 sum = 0; for (Uint32 i = 1; i <= 5; i++) { q.enqueue(new Alarm(i)); sum += i; } assert(Sum(q) == sum); // Test removing from the middle: Message* m = q.findByKey(3); assert(m != 0); q.remove(m); assert(Sum(q) == sum - 3); assert(q.getCount() == 4); // Test removing from the front: q.remove(q.front()); assert(Sum(q) == sum - 3 - 1); assert(q.getCount() == 3); // Test removing from the front: q.remove(q.back()); assert(Sum(q) == sum - 3 - 1 - 5); assert(q.getCount() == 2); // Test dequeue: m = q.dequeue(); assert(m->getKey() == 2); assert(Sum(q) == sum - 3 - 1 - 5 - 2); assert(q.getCount() == 1); // Test dequeue: m = q.dequeue(); assert(m->getKey() == 4); assert(Sum(q) == sum - 3 - 1 - 5 - 2 - 4); assert(q.getCount() == 0); }