Exemplo n.º 1
0
ELTE_VOID CEventMgr::MainLoop()
{
	while(m_bRun)
	{
		EVENT_DATA* pstEvent = PopEvent();
		if(NULL == pstEvent)
		{
			Sleep(100);
			continue;
		}
		else if(NULL != m_fnEventCallBack)
		{
			m_fnEventCallBack(pstEvent->iEventType, pstEvent->pEventData, pstEvent->uiBufSize, m_pUserData);
		}
		if(NULL != pstEvent && NULL != pstEvent->pEventData)
		{
			delete [] ((ELTE_CHAR*)(pstEvent->pEventData));
			pstEvent->pEventData = NULL;

			delete pstEvent;
			pstEvent = NULL;
		}
	}//lint !e438
	m_Thread = NULL;
}
	CGuiListView()
		: m_AlignTop(TRUE)
	{
		// 添加事件对象
		PopEvent(FALSE);
		InsEvent(_T("CGuiLVEvent")); /*先让基类绘图*/
	}
Exemplo n.º 3
0
C4InteractiveThread::~C4InteractiveThread()
{
	CStdLock PushLock(&EventPushCSec), PopLock(&EventPopCSec);
	// Remove all items. This may leak data, if pData was allocated on the heap.
	while (PopEvent(nullptr, nullptr)) {}
	// Delete head-item
	delete pFirstEvent;
	pFirstEvent = pLastEvent = nullptr;
	// Unregister notify
	Application.Remove(&NotifyProc);
}
Exemplo n.º 4
0
svEvent *svEventClient::PopWaitEvent(uint32_t wait_ms)
{
    int rc;
    svEvent *event = NULL;

    struct timespec ts;
    if (wait_ms > 0) {
        struct timespec delay;
        delay.tv_sec = wait_ms / 1000;
        delay.tv_nsec = (wait_ms - delay.tv_sec * 1000) * 1000 * 1000;
        struct timespec now;
#if defined(HAVE_CLOCK_GETTIME)
        clock_gettime(CLOCK_REALTIME, &now);
#elif defined(HAVE_GETTIMEOFDAY)
        struct timeval gtod_now;
        gettimeofday(&gtod_now, NULL);
        now.tv_sec = gtod_now.tv_sec;
        now.tv_nsec = gtod_now.tv_usec * 1000;
#else
#error "No system clock available!"
#endif
        ts.tv_sec = now.tv_sec + delay.tv_sec;
        ts.tv_nsec = now.tv_nsec + delay.tv_nsec;
        if (ts.tv_nsec >= 1000000000L) {
            ts.tv_sec++;
            ts.tv_nsec = ts.tv_nsec - 1000000000L;
        }
    }

    for ( ;; ) {
        event = PopEvent();
        if (event != NULL) break;

        pthread_mutex_lock(&evt_cond_lock);
        if (wait_ms == 0) {
            rc = pthread_cond_wait(&evt_cond, &evt_cond_lock);
            pthread_mutex_unlock(&evt_cond_lock);
        }
        else {
            rc = pthread_cond_timedwait(
                &evt_cond, &evt_cond_lock, &ts);
            pthread_mutex_unlock(&evt_cond_lock);
            if (rc == ETIMEDOUT) break;
        }
        if (rc != 0) throw svExEventCondWait(rc);
    }
    return event;
}
Exemplo n.º 5
0
void C4InteractiveThread::ProcessEvents() // by main thread
{
	C4InteractiveEventType eEventType; void *pEventData;
	while (PopEvent(&eEventType, &pEventData))
		switch (eEventType)
		{
			// Logging
		case Ev_Log: case Ev_LogSilent: case Ev_LogFatal: case Ev_LogDebug:
		{
			// Reconstruct the StdStrBuf which allocated the data.
			StdStrBuf pLog;
			pLog.Take(reinterpret_cast<char *>(pEventData));
			switch (eEventType)
			{
			case Ev_Log:
				Log(pLog.getData()); break;
			case Ev_LogSilent:
				LogSilent(pLog.getData()); break;
			case Ev_LogFatal:
				LogFatal(pLog.getData()); break;
			case Ev_LogDebug:
				DebugLog(pLog.getData()); break;
			default: assert(eEventType == Ev_Log || eEventType == Ev_LogSilent || eEventType == Ev_LogFatal || eEventType == Ev_LogDebug); // obviously will not happen, but someone tell gcc
			}

		}
		break;

	case Ev_Function:
		{
			std::unique_ptr<std::function<void ()> > func(static_cast<std::function<void()>*>(pEventData));
			(*func)();
		}

		// Other events: check for a registered handler
		default:
			if (eEventType >= Ev_None && eEventType <= Ev_Last)
				if (pCallbacks[eEventType])
					pCallbacks[eEventType]->OnThreadEvent(eEventType, pEventData);
			// Note that memory might leak if the event wasn't processed....
		}
}
Exemplo n.º 6
0
void svServer::Start(void)
{
	CreateSockets();
	CreateVpnClientThreads();
	SwitchUserGroup();
	Daemonize();
	SaveProcessId();
	StartSignalHandler();
	LoadKeyRing();
	CreateStorageThreads();

	svEvent *event;
	for ( ;; ) {
		while ((event = PopEvent())) {
			switch (event->GetId())
			{
			case svEVT_QUIT:
				return;
			case svEVT_KEYRING_REQUEST:
				KeyRingRequest((svEventKeyRingRequest *)event);
				break;
			case svEVT_HOSTKEY_REQUEST:
				HostKeyRequest((svEventHostKeyRequest *)event);
				break;
			case svEVT_HOSTKEY_RESULT:
				HostKeyResult((svEventHostKeyResult *)event);
				break;
			case svEVT_POOLCLIENT_SAVE:
				PoolClientSave((svEventPoolClientSave *)event);
				break;
			case svEVT_POOLCLIENT_LOAD:
				PoolClientLoad((svEventPoolClientLoad *)event);
				break;
			default:
				ProcessEvent(event);
			}
			delete event;
		}
		SelectSockets();
	}
}
Exemplo n.º 7
0
// Simulates behaviour of Allegro 4.x function readkey() for debugging purposes
void AllegroInput5::WaitAnyKey()
{
	Clear();
	while( true )
	{		
		Update(0);
		BeginRead();
		
		while( true )
		{
			InputEvent ev = GetEvent();
			InputEvent::EType type = ev.m_type;
			if ( type == InputEvent::EV_KEYBOARD && ev.m_keyboardEvent.m_type == KeyboardEvent::KBD_KEY_UP )
			{
				Clear();
				return;
			}
			else if ( type == InputEvent::EV_INVALID )
				break;

			PopEvent();
		}
	}
}
Exemplo n.º 8
0
void FD3DGPUProfiler::EndFrame()
{
	if (GEmitDrawEvents)
	{
		PopEvent();
	}

	FrameTiming.EndTiming();

	if (FrameTiming.IsSupported())
	{
		uint64 GPUTiming = FrameTiming.GetTiming();
		uint64 GPUFreq = FrameTiming.GetTimingFrequency();
		GGPUFrameTime = FMath::TruncToInt(double(GPUTiming) / double(GPUFreq) / FPlatformTime::GetSecondsPerCycle());
	}
	else
	{
		GGPUFrameTime = 0;
	}

	// if we have a frame open, close it now.
	if (CurrentEventNodeFrame)
	{
		CurrentEventNodeFrame->EndFrame();
	}

	check(!bTrackingEvents || bLatchedGProfilingGPU || bLatchedGProfilingGPUHitches);
	check(!bTrackingEvents || CurrentEventNodeFrame);
	if (bLatchedGProfilingGPU)
	{
		if (bTrackingEvents)
		{
			GEmitDrawEvents = bOriginalGEmitDrawEvents;
			UE_LOG(LogD3D12RHI, Warning, TEXT(""));
			UE_LOG(LogD3D12RHI, Warning, TEXT(""));
			CurrentEventNodeFrame->DumpEventTree();
			GTriggerGPUProfile = false;
			bLatchedGProfilingGPU = false;

			if (RHIConfig::ShouldSaveScreenshotAfterProfilingGPU()
				&& GEngine->GameViewport)
			{
				GEngine->GameViewport->Exec(NULL, TEXT("SCREENSHOT"), *GLog);
			}
		}
	}
	else if (bLatchedGProfilingGPUHitches)
	{
		//@todo this really detects any hitch, even one on the game thread.
		// it would be nice to restrict the test to stalls on D3D, but for now...
		// this needs to be out here because bTrackingEvents is false during the hitch debounce
		static double LastTime = -1.0;
		double Now = FPlatformTime::Seconds();
		if (bTrackingEvents)
		{
			/** How long, in seconds a frame much be to be considered a hitch **/
			const float HitchThreshold = RHIConfig::GetGPUHitchThreshold();
			float ThisTime = Now - LastTime;
			bool bHitched = (ThisTime > HitchThreshold) && LastTime > 0.0 && CurrentEventNodeFrame;
			if (bHitched)
			{
				UE_LOG(LogD3D12RHI, Warning, TEXT("*******************************************************************************"));
				UE_LOG(LogD3D12RHI, Warning, TEXT("********** Hitch detected on CPU, frametime = %6.1fms"), ThisTime * 1000.0f);
				UE_LOG(LogD3D12RHI, Warning, TEXT("*******************************************************************************"));

				for (int32 Frame = 0; Frame < GPUHitchEventNodeFrames.Num(); Frame++)
				{
					UE_LOG(LogD3D12RHI, Warning, TEXT(""));
					UE_LOG(LogD3D12RHI, Warning, TEXT(""));
					UE_LOG(LogD3D12RHI, Warning, TEXT("********** GPU Frame: Current - %d"), GPUHitchEventNodeFrames.Num() - Frame);
					GPUHitchEventNodeFrames[Frame].DumpEventTree();
				}
				UE_LOG(LogD3D12RHI, Warning, TEXT(""));
				UE_LOG(LogD3D12RHI, Warning, TEXT(""));
				UE_LOG(LogD3D12RHI, Warning, TEXT("********** GPU Frame: Current"));
				CurrentEventNodeFrame->DumpEventTree();

				UE_LOG(LogD3D12RHI, Warning, TEXT("*******************************************************************************"));
				UE_LOG(LogD3D12RHI, Warning, TEXT("********** End Hitch GPU Profile"));
				UE_LOG(LogD3D12RHI, Warning, TEXT("*******************************************************************************"));
				if (GEngine->GameViewport)
				{
					GEngine->GameViewport->Exec(NULL, TEXT("SCREENSHOT"), *GLog);
				}

				GPUHitchDebounce = 5; // don't trigger this again for a while
				GPUHitchEventNodeFrames.Empty(); // clear history
			}
			else if (CurrentEventNodeFrame) // this will be null for discarded frames while recovering from a recent hitch
			{
				/** How many old frames to buffer for hitch reports **/
				static const int32 HitchHistorySize = 4;

				if (GPUHitchEventNodeFrames.Num() >= HitchHistorySize)
				{
					GPUHitchEventNodeFrames.RemoveAt(0);
				}
				GPUHitchEventNodeFrames.Add((FD3D12EventNodeFrame*)CurrentEventNodeFrame);
				CurrentEventNodeFrame = NULL;  // prevent deletion of this below; ke kept it in the history
			}
		}
		LastTime = Now;
	}
	bTrackingEvents = false;
	delete CurrentEventNodeFrame;
	CurrentEventNodeFrame = NULL;
}