コード例 #1
0
void FMTest1Thread(TAny* a)
	{
	SFMTest1Info& info = *(SFMTest1Info*)a;
	NThread* pC = NKern::CurrentThread();
	TUint32 seed[2] = {(TUint32)pC, 0};
	TBool wait = (pC->iPriority > info.iPriorityThreshold);
	TBool thread0 = (pC==info.iThreads[0]);
	TInt n = 0;
	while (!info.iStop)
		{
		if (thread0)
			NKern::ThreadSetPriority(pC, 11);
		NKern::FMWait(&info.iMutex);
		TBool ok = verify_block((TUint32*)info.iBlock, info.iBlockSize);
		TEST_RESULT(ok, "Block corrupt");
		++info.iBlock[0];
		setup_block((TUint32*)info.iBlock, info.iBlockSize);
		++n;
		NKern::FMSignal(&info.iMutex);
		if (wait)
			{
			TUint32 x = random(seed) & 1;
			NKern::Sleep(x+1);
			}
		}
	TEST_PRINT2("Thread %T ran %d times", pC, n);
	}
コード例 #2
0
ファイル: fastsem.cpp プロジェクト: kuailexs/symbiandump-os1
void FSTest2(TAny* a)
	{
	SFSTest2Info& info = *(SFSTest2Info*)a;
	NFastSemaphore exitSem(0);
	NKern::FSSetOwner(&info.iSem, 0);
	info.iBlockCount = 0;
	info.iWaits = 0;
	info.iSignals = 0;
	info.iStart = FALSE;
	info.iStop = FALSE;
	TInt cpu;
	TInt threads = 0;
	TInt this_cpu = NKern::CurrentCpu();
	for_each_cpu(cpu)
		{
		if (cpu==this_cpu)
			CreateThreadSignalOnExit("FSTest2Sig0", &FSTest2Signaller0, 11, a, 0, KSmallTimeslice, &exitSem, cpu);
		else
			CreateThreadSignalOnExit("FSTest2Sig", &FSTest2Signaller, 12, a, 0, KSmallTimeslice, &exitSem, cpu);
		++threads;
		}

	info.iStart = TRUE;
	while(info.iWaits < 1048576)
		{
		NKern::FSWait(&info.iSem);
		++info.iWaits;
		}

	info.iStop = TRUE;
	while (threads--)
		NKern::FSWait(&exitSem);
	TEST_PRINT1("Leftover signals %d", info.iSignals-info.iWaits);
	TInt r;
	do	{
		r = WaitWithTimeout(&info.iSem, KMinTimeout);
		TEST_RESULT1(r==KErrNone || r==KErrTimedOut, "Invalid return code %d", r);
		if (r == KErrNone)
			++info.iWaits;
		} while(r == KErrNone);
	TEST_PRINT2("Signalled %d, Waited %d", info.iSignals, info.iWaits);
	TEST_RESULT(info.iWaits==info.iSignals, "MISMATCH!");
	}
コード例 #3
0
void FMTest1PInterfererThread(TAny* a)
	{
	SFMTest1Info& info = *(SFMTest1Info*)a;
	NThread* pC = NKern::CurrentThread();
	TEST_PRINT1("Thread %T start", pC);
	TUint32 seed[2] = {(TUint32)pC, 0};
	NThread* t0 = info.iThreads[0];
	TInt n = 0;
	while (!__e32_atomic_load_acq32(&info.iStop))
		{
		while (!__e32_atomic_load_acq32(&info.iStop) && t0->iPriority != 11)
			__chill();
		TUint32 x = random(seed) & 2047;
		while(x)
			{
			__e32_atomic_add_ord32(&x, TUint32(-1));
			}
		if (__e32_atomic_load_acq32(&info.iStop))
			break;
		NKern::ThreadSetPriority(t0, 9);
		++n;
		}
	TEST_PRINT2("Thread %T ran %d times", pC, n);
	}