Пример #1
0
TInt DZeroCopyLoopbackDevice::RequestDataReceipt()
	{
	iPendingRead = ETrue;
	if(!(iReceiveQueue.IsEmpty() && iSendQueue.IsEmpty()))
		{
		NKern::Lock(); 
		ReceiveDataCallback();
		NKern::Unlock(); 
		}
	return KErrNone;
	}
Пример #2
0
void DZeroCopyLoopbackDevice::ReceiveDataCallback()
	{
	// Copy buffer from send queue (it's like our receive hardware) to receive queue
	DCommsBuf* srcBuf = iSendQueue.HeadBuffer();
	if(!iReceiveQueue.IsFull() && !iSendQueue.IsEmpty())
		{
		// Alloc a new buffer in to which we will copy the received (sent) buffer (mimicking DMA in the non zerocopy case)
		DCommsBuf newBuf;
		TInt result = iLdd->Pond().Alloc(newBuf);
		if(result == KErrNone)
			{
			// Copy our buffer and set the new buffer's properties
			TInt srcPayloadLength = srcBuf->Length();
			newBuf.SetOffset(0);
			newBuf.SetLength(srcPayloadLength);

			// Do the copy
			TUint8* srcPayloadPtr = srcBuf->Ptr();
			TUint8* destPayloadPtr = newBuf.Ptr();
			memcpy(destPayloadPtr, srcPayloadPtr, srcPayloadLength);

			// Put the new buffer in the receive queue
			DCommsBuf* destBuf = iReceiveQueue.TailBuffer();
			*destBuf = newBuf;
			iReceiveQueue.Push();

			// Drop the incoming buffer
			srcBuf->Free();

			// Step the queue
			iSendQueue.Pop();
			}

		// We can now complete any outstanding request for received data - if indeed we managed to alloc a receive buffer
		if(iPendingRead && !iReceiveQueue.IsEmpty())
			{
			iPendingRead = FALSE;
			
			// Tell LDD we're done
			iLdd->ReceiveDataComplete(KErrNone);
			}
		}
	}
Пример #3
0
bool FAppEventManager::WaitForEventInQueue(EAppEventState InState, double TimeoutSeconds)
{
	bool FoundEvent = false;
	double StopTime = FPlatformTime::Seconds() + TimeoutSeconds;

	TQueue<FAppEventData, EQueueMode::Spsc> HoldingQueue;
	while (!FoundEvent)
	{
		int rc = pthread_mutex_lock(&QueueMutex);
		check(rc == 0);

		// Copy the existing queue (and check for our event)
		while (!Queue.IsEmpty())
		{
			FAppEventData OutData;
			Queue.Dequeue(OutData);

			if (OutData.State == InState)
				FoundEvent = true;

			HoldingQueue.Enqueue(OutData);
		}

		if (FoundEvent)
			break;

		// Time expired?
		if (FPlatformTime::Seconds() > StopTime)
			break;

		// Unlock for new events and wait a bit before trying again
		rc = pthread_mutex_unlock(&QueueMutex);
		check(rc == 0);
		FPlatformProcess::Sleep(0.01f);
	}

	// Add events back to queue from holding
	while (!HoldingQueue.IsEmpty())
	{
		FAppEventData OutData;
		HoldingQueue.Dequeue(OutData);
		Queue.Enqueue(OutData);
	}

	int rc = pthread_mutex_unlock(&QueueMutex);
	check(rc == 0);

	return FoundEvent;
}
Пример #4
0
void sim()
{
	int j = 0;
	int tickskip = 0, proctime = 0, taskskip = 0;
	int tick;
	int critT, critP;
	TQueue queue;

	printf("??????? ??????????? ???????? ?????\n");
	critT = input(DIAP);
	printf("??????? ??????????? ???????? ??????????\n");
	critP = input(DIAP);

	printf("??????? ?????????? ??????\n");
	tick = input(9000);
	if (tick < 20)
	{
		for (int i = 0; i < tick; i++)
		{
			if (TaskRand(critT))
			{
				if (!queue.IsFull())
				{
					queue.Put(1);
					printf("????????? ??????\n");
				}
				else
				{
					taskskip++;
					printf("?????? ?????????\n");
				}
			}
			if (proctime != 0)
			{
				printf("????????? ???????????? ??????\n");
				if (ProcRand(critP))
				{
					proctime = 0;
					printf("?????? ??????????\n");
				}
				else
				{
					proctime++;
					printf("?????? ??????????????\n");
				}
			}
			else if (!queue.IsEmpty())
			{
				printf("????????? ?????? ??????\n");
				queue.Push();
				if (ProcRand(critP))
				{
					printf("?????? ??????????\n");
				}
				else
				{
					proctime++;
					printf("?????? ??????????????\n");
				}
			}
			else
			{
				tickskip++;
				printf("????????? ???????????\n");
			}
		}
		while (!queue.IsEmpty())
		{
			queue.Push();
			j++;
		}
	}
	else
	{
		for (int i = 0; i < tick; i++)
		{
			if (TaskRand(critT))
			{
				if (!queue.IsFull())
				{
					queue.Put(1);
				}
				else
				{
					taskskip++;
				}
			}
			if (proctime != 0)
			{
				if (ProcRand(critP))
				{
					proctime = 0;
				}
				else
				{
					proctime++;
				}
			}
			else if (!queue.IsEmpty())
			{
				queue.Push();
				if (ProcRand(critP))
				{
				}
				else
				{
					proctime++;
				}
			}
			else
			{
				tickskip++;
			}
		}
		while (!queue.IsEmpty())
		{
			queue.Push();
			j++;
		}
	}
	printf("????????? ? ???????: %d\n", j);
	printf("????? ?????????: %d\n ????? ???????: %d\n", taskskip, tickskip);
}