Exemplo n.º 1
0
void SDL_SYS_WaitThread(SDL_Thread *thread)
{
    RUndertaker taker;
    taker.Create();
    TRequestStatus status;
    taker.Logon(status, thread->handle);
    User::WaitForRequest(status);
    taker.Close();
}
static TInt CatalogsUndertaker()
    {
    DLTRACEIN((""));

    TFullName catalogsThreadName;
    TInt err = User::GetDesParameter( 15, catalogsThreadName );
    
    if( err != KErrNone )
        {
        DLERROR(( "Failed to read parameter slot 15, error %d", err ));
        catalogsThreadName = KNullDesC();
        }
    else
        {
        DLINFO(( _L("Read catalogs thread name: %S"), &catalogsThreadName ));
        }

    RUndertaker undertaker;
    TRequestStatus status;
    TInt deadThreadHandleNumber;

    undertaker.Create();

    for( ;; )
        {
        undertaker.Logon( status, deadThreadHandleNumber );
        User::WaitForRequest( status );

        RThread deadThread;
        deadThread.SetHandle( deadThreadHandleNumber );

        const TDesC* type;

        switch( deadThread.ExitType() )
            {
            case EExitKill:
                type = &KExitTypeKill;
                break;

            case EExitTerminate:
                type = &KExitTypeTerminate;
                break;

            case EExitPanic:
                type = &KExitTypePanic;
                break;

            default:
                type = &KExitTypeUnknown;
                DLERROR(( "Exit type: %d", (TInt)deadThread.ExitType() ));
                break;
            }


        DLWARNING(( _L("THREAD %S DEATH observed! %S %S %d"), 
            &deadThread.FullName(),
            type,
            &deadThread.ExitCategory(),
            deadThread.ExitReason() ));
        
        type = type; // to suppress compiler warning

        if( catalogsThreadName == deadThread.FullName() )
            {
            DLERROR(( "Catalogs server thread killed, undertaker exits" ));
            deadThread.Close();
            break;
            }

        deadThread.Close();

        }

    undertaker.Close();
    DLTRACEOUT(("KErrNone"));

    return KErrNone;
    }
Exemplo n.º 3
0
//! @SYMTestCaseID t_cputime_1
//! @SYMTestType CT
//! @SYMTestCaseDesc Thread CPU time tests
//! @SYMREQ CR RFID-66JJKX
//! @SYMTestActions Tests cpu time when a thread is put through the various states
//! @SYMTestExpectedResults Reported cpu time increses only when the thread is running
//! @SYMTestPriority High
//! @SYMTestStatus Defined
void TestThreadCpuTime()
	{
	test.Start(_L("CPU thread time unit tests"));

	TThreadParam threadParam;
	FailIfError((threadParam.iSem).CreateLocal(0));
	threadParam.iCpu = 0;				// Later tests will exercise other CPUs

	RThread thread;
	RUndertaker u;
	TInt h;
	TRequestStatus s;
	FailIfError(thread.Create(_L("Thread"), ThreadFunction, 1024, NULL, &threadParam));
	thread.SetPriority(EPriorityLess);
	FailIfError(u.Create());
	FailIfError(u.Logon(s,h));
	test(s==KRequestPending);

	TTimeIntervalMicroSeconds time, time2;
	TInt64 us;

	// Test cpu time is initially zero
	FailIfError(thread.GetCpuTime(time));
	test(time == 0);

	// Test cpu time is not increased while thread is waiting on semaphore
	thread.Resume();
	User::After(KShortWait);
	FailIfError(thread.GetCpuTime(time2));
	us = time2.Int64();
	test.Printf(_L("Time %dus\n"), us);
	test(us < KTolerance); // wait should happen in less than 1ms

	// Test cpu time increases when thread allowed to run
	// We want to allow 2% tolerance for the thread's CPU time, as there could be
	// something else running on the system during that time which would result lower CPU time than the
	// actual KShortPeriod or KLongPeriod wait time.
	// Also User::After(t) might return within the range of <t, t + 1000000/64 + 2*NanoKarnelTickPeriod>.
	// Given all that - we expect that the the cpu time should be within the range of:
	// <t - 0.02*t, t + 15625 + 2*NanoKernelTickPeriod>
	// or <0.98*t, t + 15625 + 2*NanoKernelTickPeriod>
	TInt user_after_tolerance = 0;
	HAL::Get(HAL::ENanoTickPeriod, user_after_tolerance);
	user_after_tolerance += user_after_tolerance + 15625;

	(threadParam.iSem).Signal();
	User::After(KShortWait);
	FailIfError(thread.GetCpuTime(time));
	us = time.Int64() - time2.Int64();
	test.Printf(_L("Time %dus\n"), us);
	test(100*us >= 98*KShortWait); // left limit
	test(us - KShortWait <= user_after_tolerance); // right limit

	FailIfError(thread.GetCpuTime(time));
	User::After(KLongWait);
	FailIfError(thread.GetCpuTime(time2));
	us = time2.Int64() - time.Int64();
	test.Printf(_L("Time %dus\n"), us);
	test(100*us >= 98*KLongWait); // left limit
	test(us - KLongWait <= user_after_tolerance); // right limit

	// Test not increased while suspended
	thread.Suspend();
	FailIfError(thread.GetCpuTime(time));
	User::After(KShortWait);
	FailIfError(thread.GetCpuTime(time2));
	test(time == time2);
	thread.Resume();

	// Test not increased while dead
	thread.Kill(KErrNone);
	User::WaitForRequest(s);	// wait on undertaker since that completes in supervisor thread
	FailIfError(thread.GetCpuTime(time));
	User::After(KShortWait);
	FailIfError(thread.GetCpuTime(time2));
	test(time == time2);

	RThread t;
	t.SetHandle(h);
	test(t.Id()==thread.Id());
	t.Close();
	u.Close();
	thread.Close();
	(threadParam.iSem).Close();
	test.End();
	}