/*
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
*/
static TInt StartLockServer()
    {
    TInt result;

    TFindServer findTimeServer(KCrashServerName);
    TFullName name;

	result = findTimeServer.Next(name);
	if (result == KErrNone)
        {
		// Server already running
		return KErrNone;
	    }

	RSemaphore semaphore;		
	result = semaphore.CreateGlobal(KCrashServerSemaphoreName, 0);
    if (result != KErrNone)
        {
        return  result;
        }

    result = CreateLockServerProcess();
    if (result != KErrNone)
        {
        return  result;
        }

	semaphore.Wait();
	semaphore.Close();       

    return  KErrNone;
    }
TInt C32PerformanceThread::RunL(TAny* aNetPerformanceThread)
/**
 * @return - TInt
 * Implementation of RunL function
 * The RunL function is invoked each time when you create a client thread.
 * A global semaphore is implemented to block the client threads until all the CSYs are loaded.
 * iCountSemaphores variable is used to count the no of semaphores used.
 * InitTestDataL() is used to load the CSY from the corresponding test class.
 * RunAllTests() is used to perform read/write operation in each client thread once all the semaphore
 * are signalled.  
 */	
	
	{
	
	C32PerformanceThread *perThread = static_cast<C32PerformanceThread*>(aNetPerformanceThread);
   
    TInt  totalNoofSemaphores = perThread->iTThreadData.iSemaphoreCount;
    TBool semStatus           = perThread->iTThreadData.iSemaphoreStatus; 
    
    //search for the global semaphore        
    RSemaphore clientSemaphore;
		 	
	TFindSemaphore findTimeServer(KSemaphoreName);
	 
	TFullName name;
	TInt result1 = findTimeServer.Next(name);

	clientSemaphore.OpenGlobal(name);
	
	/*
	active scheduler is installed in each thread so that the test code doesn't
	need to install it if required. 
	*/   	
	CTrapCleanup* pCleanup = CTrapCleanup::New(); 
	CActiveScheduler* pScheduler = new CActiveScheduler;
	TInt ret = KErrNone;
	if ( pCleanup && pScheduler )
		{
      	 //install active scheduler for each thread     		
      	 CActiveScheduler::Install(pScheduler );
      	    	
		 TRAPD(err,perThread->InitTestDataL());
		 if(err)
		    {
		    User::Leave(KErrAbort);
		    }
      	  
      	 //signal all the semaphores if all the CSYs are loaded.
      	 if(totalNoofSemaphores == (iCountSemaphores+1))
        	{
        	 RDebug::Printf("signal all the semaphores if all the CSYs are loaded = %d",totalNoofSemaphores); 
        	 clientSemaphore.Signal(iCountSemaphores);
        	}
         //check whether the Semaphore status is True.
         else if(semStatus)
        	{
        	 //count no of semaphores required. 
	  		 iCountSemaphores++;
	  		 //block the client thread
	  		 clientSemaphore.Wait();
        	}
        //invoke RunAllTests() once all the semaphores are signalled.
        RDebug::Printf("run all MT tests"); 
        perThread->RunAllTests();
  
        }
	delete pScheduler;
    delete pCleanup;	
   
	return ret;
	}