Exemple #1
0
FAKE_MESSAGE *get_next_msg(void *key)
{
   AutoPtr<FAKE_MESSAGE> msg;

   AutoMutex autoMut(msg_mutex);
   if(requests.value() < NUMBER_MSGS)
   {
      msg.reset(PEGASUS_NEW(FAKE_MESSAGE, dq_handle) FAKE_MESSAGE(key, 0));

/*****
      check for corrupted memory 
      char *p = (char *)msg;
      p += sizeof(FAKE_MESSAGE);

      *p = 0x00;
      
      if(peg_suballocator::CheckMemory(msg))
	 abort();
******/      
      
      
      
      requests++;
   }
    
   return msg.release();  
}
Exemple #2
0
// Test Thread and AtomicInt
void test02()
{
    const Uint32 numThreads = 64;
    AtomicInt * atom = new AtomicInt(0);
    Thread* threads[numThreads];

    (*atom)++;
    Boolean zero = atom->DecAndTestIfZero();
    assert(zero);

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i] = new Thread(atomicIncrement, atom, false);
    }

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i]->run();
    }

    for (Uint32 i=0; i<numThreads; i++)
    {
        threads[i]->join();
        delete threads[i];
    }

    assert(atom->value() == numThreads);
    delete atom;
}
Exemple #3
0
PEGASUS_NAMESPACE_END

int main(int argc, char **argv)
{
    PEGASUS_START_LEAK_CHECK();
   
    const char* tmpDir = getenv ("PEGASUS_TMP");
    if (tmpDir == NULL)
    {
        tmpDir = ".";
    }
    String traceFile (tmpDir);
    traceFile.append("/dq_memory_trace");

   Tracer::setTraceFile (traceFile.getCString()); 
   Tracer::setTraceComponents("Memory");  
   Tracer::setTraceLevel(Tracer::LEVEL4); 
   AutoPtr<dq_handle>(new peg_suballocator::SUBALLOC_HANDLE());

   read_write rw =
      { 
	 new AsyncDQueue<FAKE_MESSAGE>(true, 100), 
	 new AsyncDQueue<FAKE_MESSAGE>(true, 100)
      };

   Thread *client_sender[20];
   Thread *server[10];
   int i;
   FAKE_MESSAGE *test = PEGASUS_ARRAY_NEW(FAKE_MESSAGE, 10, dq_handle.get());
   PEGASUS_ARRAY_DELETE(test);
   
   
   for( i = 0; i < NUMBER_CLIENTS; i++)
   {
      client_sender[i] = new Thread(client_sending_thread, &rw, false );
      client_sender[i]->run();
   }

   for( i = 0; i < NUMBER_SERVERS; i++)
   {
      server[i] = new Thread(server_thread, &rw, false);
      server[i]->run();
   }

   while( requests.value() < NUMBER_MSGS || replies.value() < NUMBER_MSGS )
   {
      pegasus_sleep(1000);
   }

   rw.incoming->shutdown_queue();
   rw.outgoing->shutdown_queue();

   PEGASUS_STOP_LEAK_CHECK();
   PEGASUS_CHECK_FOR_LEAKS(dq_handle.get());

   for( i = 0; i < NUMBER_CLIENTS; i++)
   {
      client_sender[i]->join();
      delete client_sender[i];
   }

   for( i = 0; i < NUMBER_SERVERS; i++)
   {
      server[i]->join();
      delete server[i];
   }

   cout << NUMBER_MSGS << " messages using " << NUMBER_CLIENTS << " clients and " << NUMBER_SERVERS << " servers" << endl;
   cout << endl << "total requests: " << requests.value() << "; total replies: " << replies.value() << endl;
   cout << "unclaimed requests: " <<  rw.outgoing->count() << endl;
   delete rw.incoming;
   delete rw.outgoing;


   
   return 0;
}