예제 #1
0
int CWorkerThread::WaitForReply( unsigned timeout, WaitFunc_t pfnWait )
{
	if (!pfnWait)
	{
		pfnWait = DefaultWaitFunc;
	}

	HANDLE waits[] =
	{
		GetThreadHandle(),
		m_EventComplete
	};

	unsigned result;
	bool bInDebugger = Plat_IsInDebugSession();

	do
	{
		// Make sure the thread handle hasn't been closed
		if ( !GetThreadHandle() )
		{
			result = WAIT_OBJECT_0 + 1;
			break;
		}

		result = (*pfnWait)((sizeof(waits) / sizeof(waits[0])), waits, false,
			(timeout != TT_INFINITE) ? timeout : 30000);

		AssertMsg(timeout != TT_INFINITE || result != WAIT_TIMEOUT, "Possible hung thread, call to thread timed out");

	} while ( bInDebugger && ( timeout == TT_INFINITE && result == WAIT_TIMEOUT ) );

	if ( result != WAIT_OBJECT_0 + 1 )
	{
		if (result == WAIT_TIMEOUT)
			m_ReturnVal = WTCR_TIMEOUT;
		else if (result == WAIT_OBJECT_0)
		{
			DevMsg( 2, "Thread failed to respond, probably exited\n");
			m_EventSend.Reset();
			m_ReturnVal = WTCR_TIMEOUT;
		}
		else
		{
			m_EventSend.Reset();
			m_ReturnVal = WTCR_THREAD_GONE;
		}
	}

	return m_ReturnVal;
}
예제 #2
0
    tracy_force_inline VkCtxScope( VkCtx* ctx, const SourceLocationData* srcloc, VkCommandBuffer cmdbuf, int depth )
        : m_cmdbuf( cmdbuf )
        , m_ctx( ctx )
#ifdef TRACY_ON_DEMAND
        , m_active( s_profiler.IsConnected() )
#endif
    {
#ifdef TRACY_ON_DEMAND
        if( !m_active ) return;
#endif
        const auto thread = GetThreadHandle();

        const auto queryId = ctx->NextQueryId();
        vkCmdWriteTimestamp( cmdbuf, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, ctx->m_query, queryId );

        Magic magic;
        auto& token = s_token.ptr;
        auto& tail = token->get_tail_index();
        auto item = token->enqueue_begin<tracy::moodycamel::CanAlloc>( magic );
        MemWrite( &item->hdr.type, QueueType::GpuZoneBeginCallstack );
        MemWrite( &item->gpuZoneBegin.cpuTime, Profiler::GetTime() );
        MemWrite( &item->gpuZoneBegin.srcloc, (uint64_t)srcloc );
        MemWrite( &item->gpuZoneBegin.thread, thread );
        MemWrite( &item->gpuZoneBegin.queryId, uint16_t( queryId ) );
        MemWrite( &item->gpuZoneBegin.context, ctx->GetId() );
        tail.store( magic + 1, std::memory_order_release );

        s_profiler.SendCallstack( depth, thread );
    }
예제 #3
0
파일: thread.c 프로젝트: Belxjander/nloader
NTSTATUS NTAPI NtQueryInformationThread(HANDLE ThreadHandle, THREADINFOCLASS ThreadInformationClass,
    PVOID ThreadInformation, ULONG ThreadInformationLength, PULONG ReturnLength)
{
    NTSTATUS result = STATUS_BUFFER_TOO_SMALL;

    ThreadHandle = GetThreadHandle(ThreadHandle);

    Log("ntdll.NtQueryInformationThread(%s:0x%08x)", strthinfo(ThreadInformationClass), ThreadInformationClass);

    switch (ThreadInformationClass)
    {
        case ThreadBasicInformation:
        {
            THREAD_BASIC_INFORMATION *thinfo = ThreadInformation;

            if (ReturnLength)
                *ReturnLength = sizeof(THREAD_BASIC_INFORMATION);

            thinfo->ExitStatus = ThreadHandle ? ThreadHandle->thread.ExitStatus : 0;
            thinfo->TebBaseAddress = NtCurrentTeb();
            result = STATUS_SUCCESS;
            break;
        }
        default:
            Log(" !!UNIMPLEMENTED!!");
            result = STATUS_NOT_IMPLEMENTED;
    }

    Log("\n");

    return result;
}
예제 #4
0
void CMyTaskThread::ExitThread()
{
	AssignTask(m_ExitTask,NULL);
	m_Exit	=true;

	if(!IsSelfThread())  //如果是自己线程调用则不用等待,否则引起死锁
		WaitForSingleObject(GetThreadHandle(),-1);
}
예제 #5
0
void CMyTaskThread::ExitThreadDirect()
{
	m_Exit			=true;
	m_ExitDirect	=true;
	SetEvent(m_Notify);

	if(!IsSelfThread())//如果是自己线程调用则不用等待,否则引起死锁
		WaitForSingleObject(GetThreadHandle(),-1);
}
예제 #6
0
BOOL CDOSObjectGroup::OnStart()
{
	FUNCTION_BEGIN;
	if(!CEasyThread::OnStart())
		return FALSE;

	m_ThreadPerformanceCounter.Init(GetThreadHandle(),THREAD_CPU_COUNT_TIME);

	PrintDOSLog(0xff0000,_T("对象组[%d]线程[%u]已启动"),m_Index,GetThreadID());
	return TRUE;
	FUNCTION_END;
	return FALSE;
}
static BOOL GetMainThreadContext(PCONTEXT context) {
  DWORD thread_id = GetMainThreadId();
  if (thread_id != 0) {
    HANDLE thread_handle = GetThreadHandle(thread_id, THREAD_GET_CONTEXT |
                                                      THREAD_SUSPEND_RESUME);
    if (thread_handle != NULL) {
      if (SuspendThread(thread_handle) != (DWORD)-1) {
        BOOL ok = GetThreadContext(thread_handle, context) != 0;
        ResumeThread(thread_handle);
        return ok;
      }
    }
  }
  return FALSE;
}
bool LGameServerMainLogic::StopGameServerMainLogic()
{
	Stop();
	pthread_t pID = GetThreadHandle();
	if (pID != 0)
	{
		pthread_join(pID, NULL);
	}
	NetWorkDown();

	m_GSServerManager.StopGSServerManagerConnectThread();

	m_GSConToServerNetWork.StopGSConnectToServerNetWork();

	m_GSConToMasterServer.StopGSConnectToMasterServer(); 
	return true;
}
static DWORD GetMainThreadId() {
  std::vector<ThreadInfo> threads;

  HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
  if (snapshot != INVALID_HANDLE_VALUE) {
    THREADENTRY32 thread_entry;
    thread_entry.dwSize = sizeof(thread_entry);
    if (Thread32First(snapshot, &thread_entry)) {
      DWORD process_id = GetProcessId(GetCurrentProcess());
      do {
        if (thread_entry.dwSize >=
            FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) +
                         sizeof(thread_entry.th32OwnerProcessID)) {
          if (thread_entry.th32OwnerProcessID == process_id) {
            ThreadInfo thread = {0};
            thread.id = thread_entry.th32ThreadID;
            threads.push_back(thread);
          }
        }
        thread_entry.dwSize = sizeof(thread_entry);
      } while (Thread32Next(snapshot, &thread_entry));
    }
    CloseHandle(snapshot);
  }

  for (std::vector<ThreadInfo>::iterator it = threads.begin();
       it != threads.end(); it++) {
    ThreadInfo &info = *it;
    HANDLE handle = GetThreadHandle(info.id, THREAD_QUERY_INFORMATION);
    GetThreadTimes(handle, &info.creation_time, &info.exit_time,
                           &info.kernel_time,   &info.user_time);
  }

  threads.erase(std::remove_if(threads.begin(), threads.end(),
                               InvalidThread()), threads.end());
  if (!threads.empty()) {
    return std::min_element(threads.begin(), threads.end(),
                            CompareThreads())->id;
  }
  return 0;
}
예제 #10
0
파일: thread.c 프로젝트: Belxjander/nloader
NTSTATUS NTAPI NtTerminateThread(HANDLE ThreadHandle, NTSTATUS ExitStatus)
{
    ThreadHandle = GetThreadHandle(ThreadHandle);

    if (ExitStatus != STATUS_SUCCESS)
    {
        fprintf(stderr, "ntdll.NtTerminateThread(\"%s\", 0x%08x)\n", strhandle(ThreadHandle), ExitStatus);
        abort();
    }

    Log("ntdll.NtTerminateThread(\"%s\", 0x%08x)\n", strhandle(ThreadHandle), ExitStatus);

    ThreadHandle->thread.ExitStatus = ExitStatus;
#ifdef THREADED
    pthread_exit(&ThreadHandle->thread.ExitStatus);
#else
    longjmp(env, 1);
#endif

    return STATUS_SUCCESS;
}
예제 #11
0
void Pathfinder::stop()
{
	running = false;

	WaitForSingleObject(GetThreadHandle(), INFINITE);
}
예제 #12
0
BOOL CDOSObjectProxyService::OnStart()
{
	FUNCTION_BEGIN;

	m_ThreadPerformanceCounter.Init(GetThreadHandle(),THREAD_CPU_COUNT_TIME);

	if(!m_ConnectionPool.Create(((CDOSServer *)GetServer())->GetConfig().MaxProxyConnection))
	{
		PrintDOSLog(0xff0000,_T("创建%u大小的连接池失败!"),
			((CDOSServer *)GetServer())->GetConfig().MaxProxyConnection);
		return FALSE;
	}
	if(!m_MsgQueue.Create(((CDOSServer *)GetServer())->GetConfig().MaxProxyMsgQueue))
	{
		PrintDOSLog(0xff0000,_T("创建%u大小的消息队列失败!"),
			((CDOSServer *)GetServer())->GetConfig().MaxProxyMsgQueue);
		return FALSE;
	}
	
	if(!m_MessageMap.Create(((CDOSServer *)GetServer())->GetConfig().MaxProxyGlobalMsgMap))
	{
		PrintDOSLog(0xff0000,_T("创建%u大小的消息映射表失败!"),
			((CDOSServer *)GetServer())->GetConfig().MaxProxyGlobalMsgMap);
		return FALSE;
	}

	if(((CDOSServer *)GetServer())->GetConfig().ProxyMsgMinCompressSize)
	{
		if (lzo_init() != LZO_E_OK)
		{
			PrintDOSLog(0xff0000,_T("代理服务开启消息压缩失败"));
			return FALSE;
		}
		PrintDOSDebugLog(0xff0000,_T("代理服务开启消息压缩"));
	}

	if(!Create(IPPROTO_TCP,
		DEFAULT_SERVER_ACCEPT_QUEUE,
		DEFAULT_SERVER_RECV_DATA_QUEUE,
		((CDOSServer *)GetServer())->GetConfig().ProxySendBufferSize,
		DEFAULT_PARALLEL_ACCEPT,
		DEFAULT_PARALLEL_RECV,
		false))
	{
		PrintDOSLog(0xffff,_T("代理服务创建失败!"));
		return FALSE;
	}

	if(!StartListen(((CDOSServer *)GetServer())->GetConfig().ObjectProxyServiceListenAddress))
	{
		PrintDOSLog(0xffff,_T("代理服务侦听于(%s:%u)失败!"),
			((CDOSServer *)GetServer())->GetConfig().ObjectProxyServiceListenAddress.GetIPString(),
			((CDOSServer *)GetServer())->GetConfig().ObjectProxyServiceListenAddress.GetPort());
		return FALSE;
	}
	PrintDOSLog(0xffff,_T("代理服务侦听于(%s:%u)!"),
		((CDOSServer *)GetServer())->GetConfig().ObjectProxyServiceListenAddress.GetIPString(),
		((CDOSServer *)GetServer())->GetConfig().ObjectProxyServiceListenAddress.GetPort());

	PrintDOSLog(0xff0000,_T("对象代理线程[%u]已启动"),GetThreadID());
	return TRUE;
	FUNCTION_END;
	return FALSE;
}
예제 #13
0
BOOL HandleBPM(DWORD dwThID)
{
	HANDLE   hTh;
	CONTEXT  Con                = {CON_DRX};
	BOOL     bHandle            = FALSE;
	DWORD    dwEip;
	char     cStatusBuff[50];

	hTh = GetThreadHandle(dwThID);
	if (!hTh)
		return FALSE;

	if (!GetThreadContext(hTh, &Con))
		return FALSE;

	// is EIP == a BPM address ?
	dwEip = Con.Eip;

	// BPM0 ?
	if ((Con.Dr6 & BPM0_DETECTED) == BPM0_DETECTED &&
		(dwEip >= Con.Eip && dwEip <= Con.Eip + MAX_RW_OPCODE) &&
		(Con.Dr7 & BPM0_LOCAL_ENABLED) == BPM0_LOCAL_ENABLED)
	{
		wsprintf(cStatusBuff, "BPM - %08lXh ", Con.Dr0);
		// build info string
		if ((Con.Dr7 & BPM0_RW) == BPM0_RW)
			lstrcat(cStatusBuff, "RW");
		else if ((Con.Dr7 & BPM0_W) == BPM0_W)
			lstrcat(cStatusBuff, "W");
		else // x !
			lstrcat(cStatusBuff, "X");
		lstrcat(cStatusBuff, " (Dr0)");
		lstrcat(cStatusBuff, " reached...");
		bHandle = TRUE;
	}

	// BPM1 ?
	if ((Con.Dr6 & BPM1_DETECTED) == BPM1_DETECTED &&
		(dwEip >= Con.Eip && dwEip <= Con.Eip + MAX_RW_OPCODE) &&
		(Con.Dr7 & BPM1_LOCAL_ENABLED) == BPM1_LOCAL_ENABLED)
	{
		wsprintf(cStatusBuff, "BPM - %08lXh ", Con.Dr1);
		// build info string
		if ((Con.Dr7 & BPM1_RW) == BPM1_RW)
			lstrcat(cStatusBuff, "RW");
		else if ((Con.Dr7 & BPM1_W) == BPM1_W)
			lstrcat(cStatusBuff, "W");
		else // x !
			lstrcat(cStatusBuff, "X");
		lstrcat(cStatusBuff, " (Dr1)");
		lstrcat(cStatusBuff, " reached...");
		bHandle = TRUE;
	}

	// BPM2 ?
	if ((Con.Dr6 & BPM2_DETECTED) == BPM2_DETECTED &&
		(dwEip >= Con.Eip && dwEip <= Con.Eip + MAX_RW_OPCODE) &&
		(Con.Dr7 & BPM2_LOCAL_ENABLED) == BPM2_LOCAL_ENABLED)
	{
		wsprintf(cStatusBuff, "BPM - %08lXh ", Con.Dr2);
		// build info string
		if ((Con.Dr7 & BPM2_RW) == BPM2_RW)
			lstrcat(cStatusBuff, "RW");
		else if ((Con.Dr7 & BPM2_W) == BPM2_W)
			lstrcat(cStatusBuff, "W");
		else // x !
			lstrcat(cStatusBuff, "X");
		lstrcat(cStatusBuff, " (Dr2)");
		lstrcat(cStatusBuff, " reached...");
		bHandle = TRUE;
	}

	// BPM3 ?
	if ((Con.Dr6 & BPM3_DETECTED) == BPM3_DETECTED &&
		(dwEip >= Con.Eip && dwEip <= Con.Eip + MAX_RW_OPCODE) &&
		(Con.Dr7 & BPM3_LOCAL_ENABLED) == BPM3_LOCAL_ENABLED)
	{
		wsprintf(cStatusBuff, "BPM - %08lXh ", Con.Dr3);
		// build info string
		if ((Con.Dr7 & BPM3_RW) == BPM3_RW)
			lstrcat(cStatusBuff, "RW");
		else if ((Con.Dr7 & BPM3_W) == BPM3_W)
			lstrcat(cStatusBuff, "W");
		else // x !
			lstrcat(cStatusBuff, "X");
		lstrcat(cStatusBuff, " (Dr3)");
		lstrcat(cStatusBuff, " reached...");
		bHandle = TRUE;
	}

	if (bHandle)
	{
		SuspendProcess();
		UpdateStatus(cStatusBuff);
		if (Option.bDlgOnBPM)
			CreateBPMDlg(hInst, hDlg_);		// open BPM Menu
		WaitForUser();
	}

	return bHandle;
}
예제 #14
0
BOOL ShowDrxInfo(HWND hDlg, DWORD dwThID)
{
	CONTEXT  Con                 = {CON_DRX};
	char     cBuff[9];
	HANDLE   hTh;

	hTh = GetThreadHandle(dwThID);
	if (!hTh)
		return FALSE;

	if (!GetThreadContext(hTh, &Con))
		return FALSE;

	// BPM0
	wsprintf(cBuff, szH, Con.Dr0);
	SDIT(hDlg, IDC_BPM0ADDR, cBuff);
	CheckDlgButton(
		hDlg,
		IDC_BPM0ON,
		(Con.Dr7 & BPM0_LOCAL_ENABLED) == BPM0_LOCAL_ENABLED ? TRUE : FALSE);
	if ((Con.Dr7 & BPM0_RW) == BPM0_RW)
		SDIM(hDlg, IDC_BPM0TYPE, CB_SETCURSEL, 2, 0);
	else if ((Con.Dr7 & BPM0_W) == BPM0_W)
		SDIM(hDlg, IDC_BPM0TYPE, CB_SETCURSEL, 1, 0);
	else
		SDIM(hDlg, IDC_BPM0TYPE, CB_SETCURSEL, 0, 0);

	// BPM1
	wsprintf(cBuff, szH, Con.Dr1);
	SDIT(hDlg, IDC_BPM1ADDR, cBuff);
	CheckDlgButton(
		hDlg,
		IDC_BPM1ON,
		(Con.Dr7 & BPM1_LOCAL_ENABLED) == BPM1_LOCAL_ENABLED ? TRUE : FALSE);
	if ((Con.Dr7 & BPM1_RW) == BPM1_RW)
		SDIM(hDlg, IDC_BPM1TYPE, CB_SETCURSEL, 2, 0);
	else if ((Con.Dr7 & BPM1_W) == BPM1_W)
		SDIM(hDlg, IDC_BPM1TYPE, CB_SETCURSEL, 1, 0);
	else
		SDIM(hDlg, IDC_BPM1TYPE, CB_SETCURSEL, 0, 0);

	// BPM2
	wsprintf(cBuff, szH, Con.Dr2);
	SDIT(hDlg, IDC_BPM2ADDR, cBuff);
	CheckDlgButton(
		hDlg,
		IDC_BPM2ON,
		(Con.Dr7 & BPM2_LOCAL_ENABLED) == BPM2_LOCAL_ENABLED ? TRUE : FALSE);
	if ((Con.Dr7 & BPM2_RW) == BPM2_RW)
		SDIM(hDlg, IDC_BPM2TYPE, CB_SETCURSEL, 2, 0);
	else if ((Con.Dr7 & BPM2_W) == BPM2_W)
		SDIM(hDlg, IDC_BPM2TYPE, CB_SETCURSEL, 1, 0);
	else
		SDIM(hDlg, IDC_BPM2TYPE, CB_SETCURSEL, 0, 0);

	// BPM3
	wsprintf(cBuff, szH, Con.Dr3);
	SDIT(hDlg, IDC_BPM3ADDR, cBuff);
	CheckDlgButton(
		hDlg,
		IDC_BPM3ON,
		(Con.Dr7 & BPM3_LOCAL_ENABLED) == BPM3_LOCAL_ENABLED ? TRUE : FALSE);
	if ((Con.Dr7 & BPM3_RW) == BPM3_RW)
		SDIM(hDlg, IDC_BPM3TYPE, CB_SETCURSEL, 2, 0);
	else if ((Con.Dr7 & BPM3_W) == BPM3_W)
		SDIM(hDlg, IDC_BPM3TYPE, CB_SETCURSEL, 1, 0);
	else
		SDIM(hDlg, IDC_BPM3TYPE, CB_SETCURSEL, 0, 0);

	return TRUE;
}