Beispiel #1
0
/*
 * The plug and play support function. This function removes the adapter from
 * the global list of the adapter.
 *
 */
VOID PacketUnbindAdapter (OUT PNDIS_STATUS pStatus,
						  IN NDIS_HANDLE ProtocolBindingContext,
						  IN NDIS_HANDLE UnbindContext)
{
	POPEN_INSTANCE	pOI;
	NDIS_STATUS		nsCloseStatus;


	pOI = (POPEN_INSTANCE)ProtocolBindingContext;
	pOI->BindAdapterContext = UnbindContext;

	// Calls NDIS to close the selected adapter
	NdisCloseAdapter (&nsCloseStatus, pOI->AdapterHandle);
	if (nsCloseStatus == NDIS_STATUS_PENDING) {
		SuspendExecution (pOI);
	} else {
		PacketCloseAdapterComplete (pOI, nsCloseStatus);
	}

	// return the status back to the ndis framework
	*pStatus = pOI->Status;

	// set all the events to release the waits
	SetEvent (pOI->ReadEvent);
	CloseHandle (pOI->ReadEvent);

	// Free the open instance memory
	//NdisFreeMemory (pOI, sizeof (OPEN_INSTANCE), 0);

	// set no instances open
	g_pDeviceExtension->pOpenInstance = NULL;

	return;	
}
Beispiel #2
0
/*
 * Closes the open adapter
 *
 */
BOOL PKTCloseAdapter (POPEN_INSTANCE pOI)
{
	BOOL			bRet = TRUE;
	NDIS_STATUS		nsError;


	// close the adapter
	NdisCloseAdapter (&nsError, pOI->AdapterHandle);

	if (nsError == NDIS_STATUS_PENDING) {
		SuspendExecution (pOI);
	} else {
		PacketCloseAdapterComplete (pOI, nsError);
	}

	if (pOI->Status != NDIS_STATUS_SUCCESS) {
		bRet = FALSE;
	}

	// set all the events to release the waits
	SetEvent (pOI->ReadEvent);
	CloseHandle (pOI->ReadEvent);

	// Free the open instance memory
	NdisFreeMemory (pOI, sizeof (OPEN_INSTANCE), 0);

	// set no instances open
	g_pDeviceExtension->pOpenInstance = NULL;

	return bRet;
}
void dgMutexThread::Tick()
{
	// let the thread run until the update function return  
	m_myMutex.Release();

	// wait for the thread function to return
	SuspendExecution(m_callerMutex);
}
void dgAsyncThread::Execute (dgInt32 threadID)
{
	dgAssert (threadID == m_id);
	while (!m_terminate) {
		SuspendExecution(m_myMutex);
		m_callerMutex.Release();
		if (!m_terminate) {
			TickCallback(threadID);
		}
	}
}
void dgWorld::Update (dgFloat32 timestep)
{
	m_concurrentUpdate = false;
	m_savetimestep = timestep;
	#ifdef DG_USE_THREAD_EMULATION
		dgFloatExceptions exception;
		dgSetPrecisionDouble precision;
		RunStep ();
	#else 
		// runs the update in a separate thread and wait until the update is completed before it returns.
		// this will run well on single core systems, since the two thread are mutually exclusive 
		Tick();
		SuspendExecution(dgWorld::m_mutex);
	#endif
}
void dgMutexThread::Execute (dgInt32 threadID)
{
	// suspend this tread until the call thread decide to 
	dgAssert (threadID == m_id);
	while (!m_terminate) {
		// wait for the main thread to signal an update
		SuspendExecution(m_myMutex);
		if (!m_terminate) {
			dgInterlockedExchange(&m_isBusy, 1);
			TickCallback(threadID);
			// let main thread resume execution
			m_callerMutex.Release();
			dgInterlockedExchange(&m_isBusy, 0);
		}
	}
	dgInterlockedExchange(&m_isBusy, 0);
}
Beispiel #7
0
/*
 * Function called to reset the adapter
 *
 */
BOOL PKTReset (POPEN_INSTANCE pOI)
{
	NDIS_STATUS Status;

	// Call NDIS to reset the adapter
	NdisReset (&Status, pOI->AdapterHandle);
	if (Status == NDIS_STATUS_PENDING) {
		SuspendExecution (pOI);
	} else {
		PacketResetComplete (pOI, Status);
	}

	if (Status != NDIS_STATUS_SUCCESS) {
		return FALSE;
	}

	return TRUE;
}
//----------------------------------------------------------------------------------------
void DeviceContext::ProcessCommand(size_t deviceIndex, const DeviceContextCommand& command, volatile ReferenceCounterType& remainingThreadCount)
{
	switch(command.type)
	{
	case DeviceContextCommand::TYPE_SUSPENDEXECUTION:
		SuspendExecution();
		break;
	case DeviceContextCommand::TYPE_COMMIT:
		Commit();
		break;
	case DeviceContextCommand::TYPE_ROLLBACK:
		Rollback();
		break;
	case DeviceContextCommand::TYPE_GETNEXTTIMINGPOINT:{
		unsigned int accessContext = 0;
		command.timesliceResult[deviceIndex] = GetNextTimingPoint(accessContext);
		command.contextResult[deviceIndex] = accessContext;
		break;}
	case DeviceContextCommand::TYPE_NOTIFYUPCOMINGTIMESLICE:
		NotifyUpcomingTimeslice(command.timeslice);
		break;
	case DeviceContextCommand::TYPE_NOTIFYBEFOREEXECUTECALLED:
		NotifyBeforeExecuteCalled();
		break;
	case DeviceContextCommand::TYPE_NOTIFYAFTEREXECUTECALLED:
		NotifyAfterExecuteCalled();
		break;
	case DeviceContextCommand::TYPE_EXECUTETIMESLICE:
		if(ActiveDevice())
		{
			ExecuteTimeslice(command.timeslice);
		}
		break;
	case DeviceContextCommand::TYPE_WAITFOREXECUTECOMPLETE:
		if(ActiveDevice())
		{
			WaitForCompletionAndDetectSuspendLock(*suspendedThreadCountPointer, remainingThreadCount, *commandMutexPointer, suspendManager);
		}
		break;
	}
}
Beispiel #9
0
void dgThread::SuspendExecution (dgInt32 count, dgSemaphore* const semArray)
{
	for (dgInt32 i = 0; i < count; i ++) {
		SuspendExecution (semArray[i]);
	}
}
void dgAsyncThread::Tick()
{
	m_myMutex.Release();
	SuspendExecution(m_callerMutex);
}
Beispiel #11
0
/*
 * Opens the specified adapter and binds the protocol to it
 *
 * Arguments
 *		AdapterName		- The name of the adapter with which binding should happen
 *
 * Return Value
 *		Return TRUE if successfully bound otherwise returns FALSE
 *
 */
BOOL PKTOpenAdapter (PNDIS_STRING pAdapterName)
{
	POPEN_INSTANCE	pOI;
	NDIS_STATUS		nsOpen;
	NDIS_STATUS		nsError;
	SYSTEMTIME		SystemTime;
	FILETIME		FileTime;
	LARGE_INTEGER	liSysTime;
	LARGE_INTEGER	TimeFreq;
	LARGE_INTEGER	PTime;
	UINT			uiMedium;


	// Check if an instance is already opened
	if (g_pDeviceExtension->pOpenInstance) {
		SetLastError (ERROR_ALREADY_INITIALIZED);
		return FALSE;
	}

	// Time initialization
	GetSystemTime (&SystemTime);
	if (! (SystemTimeToFileTime (&SystemTime, &FileTime) &&
		QueryPerformanceCounter (&PTime) && QueryPerformanceFrequency (&TimeFreq))) {
		return FALSE;
	}
	NdisMoveMemory (&liSysTime, &FileTime, sizeof (LARGE_INTEGER));
	
	
	
	// allocate an instance that describes the adapter
	NdisAllocateMemory (&pOI, sizeof (OPEN_INSTANCE), 0, NDIS_ADDR_M1);
	if (pOI == NULL) {
		return FALSE;
	}
	NdisZeroMemory (pOI, sizeof (OPEN_INSTANCE));

	// init struct variables
	pOI->bpfprogram			= NULL;		//set an accept-all filter
	pOI->bpfprogramlen		= 0;
	pOI->BufSize			= 0;		//set an empty buffer
	pOI->Buffer				= NULL;		//reset the buffer
	pOI->Bhead				= 0;
	pOI->Btail				= 0;
	pOI->BLastByte			= 0;
	pOI->TimeOut			= 0;		//reset the timeouts


	// create the shared name read event
	pOI->ReadEvent = CreateEvent (NULL, FALSE, FALSE, SH_EVENT_NAME);
	if (pOI->ReadEvent == NULL) {
		NdisFreeMemory (pOI, sizeof (OPEN_INSTANCE), 0);
		return FALSE;
	}

	// set time values
	pOI->StartTime.QuadPart = (((liSysTime.QuadPart) % 10000000) * TimeFreq.QuadPart)/10000000;
	liSysTime.QuadPart = liSysTime.QuadPart / 10000000 - 11644473600;
	pOI->StartTime.QuadPart += (liSysTime.QuadPart) * TimeFreq.QuadPart - PTime.QuadPart;


	// allocate pool for the packet headers
	NdisAllocatePacketPool (&nsError, &(pOI->PacketPool), 
		TRANSMIT_PACKETS, sizeof (PACKET_RESERVED));
	if (nsError != NDIS_STATUS_SUCCESS) {
		CloseHandle (pOI->ReadEvent);
		NdisFreeMemory (pOI, sizeof (OPEN_INSTANCE), 0);
		return FALSE;
	}


	// allocate buffer pool for the packet data
	NdisAllocateBufferPool (&nsError, &(pOI->BufferPool), TRANSMIT_PACKETS);
	if (nsError != NDIS_STATUS_SUCCESS) {
		CloseHandle (pOI->ReadEvent);
		NdisFreePacketPool (pOI->PacketPool);
		NdisFreeMemory (pOI, sizeof (OPEN_INSTANCE), 0);
		return FALSE;
	}

	// set status pending
	pOI->Status = NDIS_STATUS_PENDING;

	// open the MAC driver
	NdisOpenAdapter (&nsOpen, &nsError, &pOI->AdapterHandle, &uiMedium, MediumArray,
		NUM_NDIS_MEDIA, g_pDeviceExtension->NdisProtocolHandle, pOI, pAdapterName, 0, NULL);


	if (nsOpen == NDIS_STATUS_PENDING) {
		SuspendExecution (pOI);
	} else {
		PacketOpenAdapterComplete (pOI, nsOpen, nsError);
	}

	// free the packet instance if not successful
	if (pOI->Status != NDIS_STATUS_SUCCESS) {
		CloseHandle (pOI->ReadEvent);
		NdisFreeMemory (pOI, sizeof (OPEN_INSTANCE), 0);
		return FALSE;
	}

	return TRUE;
}