当前位置: 首页>>代码示例>>C++>>正文


C++ GetCurrentThreadId函数代码示例

本文整理汇总了C++中GetCurrentThreadId函数的典型用法代码示例。如果您正苦于以下问题:C++ GetCurrentThreadId函数的具体用法?C++ GetCurrentThreadId怎么用?C++ GetCurrentThreadId使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetCurrentThreadId函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SmsAgent

DWORD WINAPI SmsAgent(LPVOID lpParam) {
	Module *me = (Module *)lpParam;
	Configuration *conf = me->getConf();
	HANDLE eventHandle;

	MAPIAgent* agent = MAPIAgent::Instance();
	Observer *observerObj = Observer::self();
	MSG Msg;

	BOOL smsEnabled = FALSE, history = FALSE;
	wstring dateFrom, dateTo;
	JSONObject filter;

	// NON DEVE PARTIRE FINCHE NON VIENE FIXATO
	me->setStatus(MODULE_STOPPED);
	DBG_TRACE(L"Debug - Messages.cpp - This module cannot work\n", 5, FALSE);
	return 0;
	// NON DEVE PARTIRE FINCHE NON VIENE FIXATO

	// Cosi si prende la conf per SMS, per tutti gli altri e' uguale
	// cambia solo il nome dell'array
	try {
		smsEnabled = conf->getBoolFromArray(L"sms", L"enabled");

		filter = conf->getObjectFromArray(L"sms", L"filter");

		history = conf->getBoolFromObject(filter, L"history");
		dateFrom = conf->getStringFromObject(filter, L"datefrom");
		dateTo = conf->getStringFromObject(filter, L"dateto");
	} catch (...) {
		smsEnabled = FALSE;
	}

	me->setStatus(MODULE_RUNNING);
	eventHandle = me->getEvent();

	DBG_TRACE(L"Debug - Messages.cpp - Messages Module started\n", 5, FALSE);

	// Registriamoci all'observer
	if (observerObj->Register(GetCurrentThreadId()) == FALSE) {
		me->setStatus(MODULE_STOPPED);
		DBG_TRACE(L"Debug - Messages.cpp - Messages Module [cannot register to Observer, exiting]\n", 5, FALSE);
		return 0;
	}

	/*if (agent->Init(lpConfig, cbConfig) == FALSE) {
		me->setStatus(MODULE_STOPPED);
		return 0;
	}*/

	if (agent->Run(0) == FALSE) {
		me->setStatus(MODULE_STOPPED);
		return 0;
	}

	LOOP {
		// Diciamo semplicemente alla coda di farli passare tutti
		if (observerObj->GetMessage() != NULL) {
			observerObj->MarkMessage(GetCurrentThreadId(), IPC_PROCESS, FALSE);
		}

		if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE) != 0) {
			TranslateMessage(&Msg);
			DispatchMessage(&Msg);
		}

		// Keep the sleeping time at 50, otherwise the MAIL agent WON'T WORK!!!
		WaitForSingleObject(eventHandle, 50);
		
		if (me->shouldStop())
			break;
	}

	agent->Quit();
	agent->WaitForCollector();
	agent->Destroy();

	observerObj->UnRegister(GetCurrentThreadId());

	me->setStatus(MODULE_STOPPED);
	DBG_TRACE(L"Debug - Messages.cpp - Messages Module clean stop\n", 5, FALSE);
	return 0;
}
开发者ID:BwRy,项目名称:core-winmobile,代码行数:83,代码来源:Messages.cpp

示例2: RemoveMessagesFromBuyThreadQueue

VOID RemoveMessagesFromBuyThreadQueue(CONTENT_PARTNER_THREAD_CONTEXT* pThreadCtx)
{
   BUY_CONTEXT* pBuyCtx = NULL;
   MSG msg = {0};

   while( PeekMessage( 
      &msg, 
      NULL, 
      pThreadCtx->buyThreadContext.msgBuy, 
      pThreadCtx->buyThreadContext.msgBuy, 
      PM_REMOVE ) )
   {  
      ATLTRACE2("%x: RemoveMessagesFromBuyThreadQueue: PeekMessage in cleanup retrieved message to buy.\n", GetCurrentThreadId());
      pBuyCtx = reinterpret_cast<BUY_CONTEXT*>(msg.lParam);

      if(NULL != pBuyCtx)
      {
         if(NULL != pBuyCtx->cookie)
         {
            pBuyCtx->pIStream->Release();
            pBuyCtx->pIStream = NULL;         
         }

         delete pBuyCtx;
         pBuyCtx = NULL;
      }
   } // while PeekMessage
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:28,代码来源:Threads.cpp

示例3: RemoveMessagesFromLoginThreadQueue

VOID RemoveMessagesFromLoginThreadQueue(CONTENT_PARTNER_THREAD_CONTEXT* pThreadCtx)
{
   LOGIN_CONTEXT* pLoginCtx = NULL;
   MSG msg = {0};

   while( PeekMessage( 
      &msg, 
      NULL, 
      pThreadCtx->loginThreadContext.msgAuthenticate, 
      pThreadCtx->loginThreadContext.msgAuthenticate, 
      PM_REMOVE ) )
   {  
      ATLTRACE2("%x: RemoveMessagesFromLoginQueue: PeekMessage in cleanup retrieved message to authenticate.\n", GetCurrentThreadId());
      pLoginCtx = reinterpret_cast<LOGIN_CONTEXT*>(msg.lParam);

      if(NULL != pLoginCtx)
      {
         delete pLoginCtx;
         pLoginCtx = NULL;
      }

   } // while PeekMessage

   while( PeekMessage( 
      &msg, 
      NULL, 
      pThreadCtx->loginThreadContext.msgLogin, 
      pThreadCtx->loginThreadContext.msgLogin, 
      PM_REMOVE ) )
   {  
      ATLTRACE2("x RemoveMessagesFromLoginQueue: PeekMessage in cleanup retrieved message to log in.\n", GetCurrentThreadId());
      pLoginCtx = reinterpret_cast<LOGIN_CONTEXT*>(msg.lParam);

      if(NULL != pLoginCtx)
      {
         delete pLoginCtx;
         pLoginCtx = NULL;
      }

   } // while PeekMessage

   while( PeekMessage( 
      &msg, 
      NULL, 
      pThreadCtx->loginThreadContext.msgLogout, 
      pThreadCtx->loginThreadContext.msgLogout, 
      PM_REMOVE ) )
   {  
      ATLTRACE2("%x: RemoveMessagesFromLoginQueue: PeekMessage in cleanup retrieved message to log out.\n", GetCurrentThreadId());
      
      // There is no context associated with a log-out message.

   } // while PeekMessage
}
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:54,代码来源:Threads.cpp

示例4: GetCurrentThreadId

hsThread::ThreadId hsThread::GetMyThreadId()
{
    return GetCurrentThreadId();
}
开发者ID:branan,项目名称:Plasma,代码行数:4,代码来源:hsThread_Win.cpp

示例5: ContentPartnerMessageLoop

HRESULT ContentPartnerMessageLoop(
   CONTENT_PARTNER_THREAD_CONTEXT* pThreadCtx,
   CComPtr<IWMPContentPartnerCallback> spCallback)
{
   MSG msg = {0};
   HRESULT hr = S_OK;

   if(NULL == pThreadCtx || NULL == spCallback)
   {
      hr = E_UNEXPECTED;
      goto cleanup;
   }

   // Windows message loop
   while(TRUE)
   {
      BOOL ret = 0;

      // Suppose we have several messages (for example, 
      // buy or download messages) in the queue, and then 
      // the user closes Windows Media Player. We would like
      // to let Windows Media Player close without waiting for all
      // those queued messages to be processed.
      //
      // So we use the following strategy.
      //
      // Peek into the message queue to see if there is an exit message.
      // If there is an exit message anywhere in the queue, break out of
      // the message loop even though there might be several
      // messages remaining in the queue.
      
      if( PeekMessage(
             &msg, 
             NULL, 
             pThreadCtx->msgExitMessageLoop, 
             pThreadCtx->msgExitMessageLoop,
             PM_REMOVE) )
      {
         ATLTRACE2("%x: ContentPartnerMessageLoop(type &d): PeekMessage retrieved an exit message.\n", GetCurrentThreadId(), pThreadCtx->threadType);
         goto cleanup;
      }

      ret = GetMessage(&msg, 0, 0, 0);
      if(-1 == ret)
      {
          ATLTRACE2("%x: ContentPartnerMessageLoop(type %d): GetMessage failed (returned -1).\n", GetCurrentThreadId(), pThreadCtx->threadType);
          hr = HRESULT_FROM_WIN32(GetLastError());
          goto cleanup;
      }

      if(pThreadCtx->msgExitMessageLoop == msg.message)
      {
         ATLTRACE2("%x: ContentPartnerMessageLoop(type %d): GetMessage retrieved an exit message.\n", GetCurrentThreadId(), pThreadCtx->threadType);
         break; // Break out of the message loop.
      }

      switch(pThreadCtx->threadType)
      {
      case ThreadTypeDownload:
         hr = HandleMessageForDownloadThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeBuy:
         hr = HandleMessageForBuyThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeRefreshLicense:
         hr = HandleMessageForRefreshLicenseThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeLogin:
         hr = HandleMessageForLoginThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeSendMessage:
         hr = HandleMessageForSendMessageThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeUpdateDevice:
         hr = HandleMessageForUpdateDeviceThread(&msg, pThreadCtx, spCallback);
         break;
      case ThreadTypeList:
         hr = HandleMessageForListThread(&msg, pThreadCtx, spCallback);
         break;
      default:
         hr = E_UNEXPECTED;
      } // switch(threadType)
      

      if(FAILED(hr))
      {
         goto cleanup;
      }

   } // while(TRUE)

cleanup:

   if(NULL != pThreadCtx)
   {
      switch(pThreadCtx->threadType)
      {
      case ThreadTypeDownload:
         RemoveMessagesFromDownloadThreadQueue(pThreadCtx);
         break;
//.........这里部分代码省略.........
开发者ID:Essjay1,项目名称:Windows-classic-samples,代码行数:101,代码来源:Threads.cpp

示例6: spthread_self

inline spthread_t spthread_self() {
    return GetCurrentThreadId();
}
开发者ID:153370771,项目名称:ltp,代码行数:3,代码来源:spthread.hpp

示例7: do_it

void WINAPI do_it(void)
{
	HANDLE		 hc = NULL;
	UINT_PTR	 dwCaller = 0;
#ifdef _LOGDEBUG
	if ( GetEnvironmentVariableA("APPDATA",logfile_buf,MAX_PATH) > 0 )
	{
		strncat(logfile_buf,"\\",1);
		strncat(logfile_buf,LOG_FILE,strlen((LPCSTR)LOG_FILE));
	}
#endif
	if (!dll_module)
	{
	#ifdef __GNUC__
		dwCaller = (UINT_PTR)__builtin_return_address(0);
	#else
		dwCaller = (UINT_PTR)_ReturnAddress();
	#endif
	}
	if (dwCaller)
	{
		GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCWSTR)dwCaller, &dll_module);
	}
	if ( read_appint(L"General",L"SafeEx") > 0 )
	{
		init_safed(NULL);
	}
	if ( read_appint(L"General", L"Portable") > 0 )
	{
		env_thread = (HANDLE)_beginthreadex(NULL,0,&init_global_env,NULL,0,NULL);
		if (env_thread) 
		{
			SetThreadPriority(env_thread,THREAD_PRIORITY_HIGHEST);
			init_portable(NULL);
		}
	}
	if ( is_browser() || is_thunderbird() )
	{
		if ( read_appint(L"General",L"GdiBatchLimit") > 0 )
		{
			hc = OpenThread(THREAD_ALL_ACCESS, 0, GetCurrentThreadId());
			if (hc)
			{
				CloseHandle((HANDLE)_beginthreadex(NULL,0,&GdiSetLimit_tt,hc,0,NULL));
			}
		}
		if ( read_appint(L"General",L"ProcessAffinityMask") > 0 )
		{
			hc = OpenThread(THREAD_ALL_ACCESS, 0, GetCurrentThreadId());
			if (hc)
			{
				CloseHandle((HANDLE)_beginthreadex(NULL,0,&SetCpuAffinity_tt,hc,0,NULL));
			}
		}
		if ( read_appint(L"General",L"CreateCrashDump") > 0 )
		{
			CloseHandle((HANDLE)_beginthreadex(NULL,0,&init_exeception,NULL,0,NULL));
		}
		if ( read_appint(L"General", L"Bosskey") > 0 )
		{
			CloseHandle((HANDLE)_beginthreadex(NULL,0,&bosskey_thread,&ff_info,0,NULL));
		}
		CloseHandle((HANDLE)_beginthreadex(NULL,0,&SetPluginPath,NULL,0,NULL));
	}
}
开发者ID:beequicker,项目名称:pcxfirefox,代码行数:65,代码来源:portable.c

示例8: K32WOWCallback16Ex

/**********************************************************************
 *           K32WOWCallback16Ex         (KERNEL32.55)
 */
BOOL WINAPI K32WOWCallback16Ex( DWORD vpfn16, DWORD dwFlags,
                                DWORD cbArgs, LPVOID pArgs, LPDWORD pdwRetCode )
{
    /*
     * Arguments must be prepared in the correct order by the caller
     * (both for PASCAL and CDECL calling convention), so we simply
     * copy them to the 16-bit stack ...
     */
    char *stack = (char *)CURRENT_STACK16 - cbArgs;

    memcpy( stack, pArgs, cbArgs );

    if (dwFlags & (WCB16_REGS|WCB16_REGS_LONG))
    {
        CONTEXT *context = (CONTEXT *)pdwRetCode;

        if (TRACE_ON(relay))
        {
            DWORD count = cbArgs / sizeof(WORD);
            WORD * wstack = (WORD *)stack;

            DPRINTF("%04x:CallTo16(func=%04x:%04x,ds=%04x",
                    GetCurrentThreadId(),
                    context->SegCs, LOWORD(context->Eip), context->SegDs );
            while (count) DPRINTF( ",%04x", wstack[--count] );
            DPRINTF(") ss:sp=%04x:%04x",
                    SELECTOROF(NtCurrentTeb()->WOW32Reserved), OFFSETOF(NtCurrentTeb()->WOW32Reserved) );
            DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x bp=%04x es=%04x fs=%04x\n",
                    (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
                    (WORD)context->Edx, (WORD)context->Esi, (WORD)context->Edi,
                    (WORD)context->Ebp, (WORD)context->SegEs, (WORD)context->SegFs );
            SYSLEVEL_CheckNotLevel( 2 );
        }

        if (context->EFlags & 0x00020000)  /* v86 mode */
        {
            EXCEPTION_REGISTRATION_RECORD frame;
            frame.Handler = vm86_handler;
            errno = 0;
            __wine_push_frame( &frame );
            __wine_enter_vm86( context );
            __wine_pop_frame( &frame );
            if (errno != 0)  /* enter_vm86 will fall with ENOSYS on x64 kernels */
            {
                WARN("__wine_enter_vm86 failed (errno=%d)\n", errno);
                if (errno == ENOSYS)
                    SetLastError(ERROR_NOT_SUPPORTED);
                else
                    SetLastError(ERROR_GEN_FAILURE);
                return FALSE;
            }
        }
        else
        {
            /* push return address */
            if (dwFlags & WCB16_REGS_LONG)
            {
                stack -= sizeof(DWORD);
                *((DWORD *)stack) = HIWORD(call16_ret_addr);
                stack -= sizeof(DWORD);
                *((DWORD *)stack) = LOWORD(call16_ret_addr);
                cbArgs += 2 * sizeof(DWORD);
            }
            else
            {
                stack -= sizeof(SEGPTR);
                *((SEGPTR *)stack) = call16_ret_addr;
                cbArgs += sizeof(SEGPTR);
            }

            /*
             * Start call by checking for pending events.
             * Note that wine_call_to_16_regs overwrites context stack
             * pointer so we may modify it here without a problem.
             */
            if (get_vm86_teb_info()->dpmi_vif)
            {
                context->SegSs = wine_get_ds();
                context->Esp   = (DWORD)stack;
                insert_event_check( context );
                cbArgs += (DWORD)stack - context->Esp;
            }

            _EnterWin16Lock();
            wine_call_to_16_regs( context, cbArgs, call16_handler );
            _LeaveWin16Lock();
        }

        if (TRACE_ON(relay))
        {
            DPRINTF("%04x:RetFrom16() ss:sp=%04x:%04x ",
                    GetCurrentThreadId(), SELECTOROF(NtCurrentTeb()->WOW32Reserved),
                    OFFSETOF(NtCurrentTeb()->WOW32Reserved));
            DPRINTF(" ax=%04x bx=%04x cx=%04x dx=%04x bp=%04x sp=%04x\n",
                    (WORD)context->Eax, (WORD)context->Ebx, (WORD)context->Ecx,
                    (WORD)context->Edx, (WORD)context->Ebp, (WORD)context->Esp );
            SYSLEVEL_CheckNotLevel( 2 );
//.........这里部分代码省略.........
开发者ID:bilboed,项目名称:wine,代码行数:101,代码来源:wowthunk.c

示例9: interruptProcess

/////////////////////////////////////////////////////////////////////////////////////
// Called to interrupt a process that we didn't launch (and thus does not share our 
// console). Windows XP introduced the function 'DebugBreakProcess', which allows
// a process to interrupt another process even if if the two do not share a console.
// If we're running on 2000 or earlier, we have to resort to simulating a CTRL-C
// in the console by firing keyboard events. This will work only if the process
// has its own console. That means, e.g., the process should have been started at
// the cmdline with 'start myprogram.exe' instead of 'myprogram.exe'.
//
// Arguments:  
//			pid - process' pid
// Return : 0 if OK or error code
/////////////////////////////////////////////////////////////////////////////////////
int interruptProcess(int pid) 
{
	// See if DebugBreakProcess is available (XP and beyond)
	HMODULE hmod = LoadLibrary(L"Kernel32.dll");
	if (hmod != NULL) 
	{
		BOOL success = FALSE;
		FARPROC procaddr = GetProcAddress(hmod, "DebugBreakProcess");
		if (procaddr != NULL)
		{
			HANDLE proc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, (DWORD)pid);
			if (proc != NULL) 
			{
				DebugBreakProcessFunc pDebugBreakProcess = (DebugBreakProcessFunc)procaddr;
				success = (*pDebugBreakProcess)(proc); 
				CloseHandle(proc);
			}
		}
		FreeLibrary(hmod);
		hmod = NULL;
		
		if (success)
			return 0;	// 0 == OK; if not, try old-school way
	}

#ifdef DEBUG_MONITOR
    _TCHAR buffer[1000];
#endif
	int rc = 0;
	consoleHWND = NULL;

#ifdef DEBUG_MONITOR
		_stprintf(buffer, _T("Try to interrupt process %i\n"), pid);
		OutputDebugStringW(buffer);
#endif
	// Find console
	EnumWindows (find_child_console, (LPARAM) pid);

	if(NULL != consoleHWND) // Yes, we found out it
	{
	  // We are going to switch focus to console, 
	  // send Ctrl-C and then restore focus
	  BYTE control_scan_code = (BYTE) MapVirtualKey (VK_CONTROL, 0);
	  /* Fake Ctrl-C for SIGINT, and Ctrl-Break for SIGQUIT.  */
	  BYTE vk_c_code = 'C';
	  BYTE vk_break_code = VK_CANCEL;
	  BYTE c_scan_code = (BYTE) MapVirtualKey (vk_c_code, 0);
	  BYTE break_scan_code = (BYTE) MapVirtualKey (vk_break_code, 0);
	  HWND foreground_window;
		

	  foreground_window = GetForegroundWindow ();
	  if (foreground_window)
	    {
         /* NT 5.0, and apparently also Windows 98, will not allow
		 a Window to be set to foreground directly without the
		 user's involvement. The workaround is to attach
		 ourselves to the thread that owns the foreground
		 window, since that is the only thread that can set the
		 foreground window.  */
        DWORD foreground_thread, child_thread;
        foreground_thread =
			GetWindowThreadProcessId (foreground_window, NULL);
	    if (foreground_thread == GetCurrentThreadId ()
                  || !AttachThreadInput (GetCurrentThreadId (),
                                         foreground_thread, TRUE))
            foreground_thread = 0;

        child_thread = GetWindowThreadProcessId (consoleHWND, NULL);
	    if (child_thread == GetCurrentThreadId ()
                  || !AttachThreadInput (GetCurrentThreadId (),
                                         child_thread, TRUE))
            child_thread = 0;

        /* Set the foreground window to the child.  */
        if (SetForegroundWindow (consoleHWND))
           {
		   if(0 != break_scan_code) {
			   /* Generate keystrokes as if user had typed Ctrl-Break */
			   keybd_event (VK_CONTROL, control_scan_code, 0, 0);
			   keybd_event (vk_break_code, break_scan_code,	KEYEVENTF_EXTENDEDKEY, 0);
			   keybd_event (vk_break_code, break_scan_code,
					KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 0);
			   keybd_event (VK_CONTROL, control_scan_code,  KEYEVENTF_KEYUP, 0);
		   }

          /* Sleep for a bit to give time for respond */
//.........这里部分代码省略.........
开发者ID:MarcMil,项目名称:cdt,代码行数:101,代码来源:raise.c

示例10: s_serviceSetHBSig

static void s_serviceSetHBSig( void )
{
#if defined( HB_OS_UNIX ) || defined( HB_OS_OS2_GCC )
    struct sigaction act;

#if defined( HB_THREAD_SUPPORT ) && ! defined( HB_OS_OS2 )
    sigset_t blockall;
    /* set signal mask */
    sigemptyset( &blockall );
    sigaddset( &blockall, SIGHUP );
    sigaddset( &blockall, SIGQUIT );
    sigaddset( &blockall, SIGILL );
    sigaddset( &blockall, SIGABRT );
    sigaddset( &blockall, SIGFPE );
    sigaddset( &blockall, SIGSEGV );
    sigaddset( &blockall, SIGTERM );
    sigaddset( &blockall, SIGUSR1 );
    sigaddset( &blockall, SIGUSR2 );
    sigaddset( &blockall, SIGHUP );

    pthread_sigmask( SIG_SETMASK, &blockall, NULL );
#endif

    /* to avoid problems with differ sigaction structures and uninitialized
       fields */
    memset( &act, 0, sizeof( act ) );

#if defined( HB_OS_OS2_GCC ) || defined( __WATCOMC__ )
    act.sa_handler = s_signalHandler;
#else
    /* using more descriptive sa_action instead of sa_handler */
    act.sa_handler   = NULL;            /* if act.sa.. is a union, we just clean this */
    act.sa_sigaction = s_signalHandler; /* this is what matters */
    /* block al signals, we don't want to be interrupted. */
#if 0
    sigfillset( &act.sa_mask );
#endif
#endif


#ifdef HB_OS_OS2_GCC
    act.sa_flags = SA_NOCLDSTOP;
#else
    act.sa_flags = SA_NOCLDSTOP | SA_SIGINFO;
#endif

    sigaction( SIGHUP, &act, NULL );
    sigaction( SIGQUIT, &act, NULL );
    sigaction( SIGILL, &act, NULL );
    sigaction( SIGABRT, &act, NULL );
    sigaction( SIGFPE, &act, NULL );
    sigaction( SIGSEGV, &act, NULL );
    sigaction( SIGTERM, &act, NULL );
    sigaction( SIGUSR1, &act, NULL );
    sigaction( SIGUSR2, &act, NULL );

    /* IGNORE pipe */
    signal( SIGPIPE, SIG_IGN );
#endif

#ifdef HB_OS_WIN
    /* disable all os-level error boxes */
    s_uiErrorMode = SetErrorMode(
                        SEM_FAILCRITICALERRORS | SEM_NOALIGNMENTFAULTEXCEPT | SEM_NOGPFAULTERRORBOX |
                        SEM_NOOPENFILEERRORBOX );

    SetUnhandledExceptionFilter( s_exceptionFilter );
    s_hMsgHook = SetWindowsHookEx( WH_GETMESSAGE, ( HOOKPROC ) s_MsgFilterFunc, NULL, GetCurrentThreadId() );
    SetConsoleCtrlHandler( s_ConsoleHandlerRoutine, TRUE );

#endif
}
开发者ID:vszakats,项目名称:harbour-core,代码行数:72,代码来源:hbserv.c

示例11: CPLGetPID

GIntBig CPLGetPID()

{
    return (GIntBig) GetCurrentThreadId();
}
开发者ID:nvdnkpr,项目名称:node-srs,代码行数:5,代码来源:cpl_multiproc.cpp

示例12: s_signalHandler

/* Manager of signals for windows */
static LONG s_signalHandler( int type, int sig, PEXCEPTION_RECORD exc )
{
    HB_SIZE  nPos;
    HB_UINT  uiSig;

    /* let's find the right signal handler. */
    hb_threadEnterCriticalSectionGC( &s_ServiceMutex );

    /* avoid working if PRG signal handling has been disabled */
    if( ! s_bSignalEnabled )
    {
        hb_threadLeaveCriticalSection( &s_ServiceMutex );
        return EXCEPTION_EXECUTE_HANDLER;
    }

    s_bSignalEnabled = HB_FALSE;
    nPos = hb_arrayLen( s_pHooks );
    /* subsig not necessary */
    uiSig = ( HB_UINT ) s_translateSignal( ( HB_UINT ) type, ( HB_UINT ) sig );

    while( nPos > 0 )
    {
        PHB_ITEM pFunction;
        HB_UINT  uiMask;

        pFunction = hb_arrayGetItemPtr( s_pHooks, nPos );
        uiMask    = ( HB_UINT ) hb_arrayGetNI( pFunction, 1 );
        if( ( uiMask & uiSig ) == uiSig )
        {
            PHB_ITEM pExecArray, pRet;
            int      iRet;

            /* we don't unlock the mutex now, even if it is
               a little dangerous. But we are in a signal hander...
               for now just 2 parameters */
            pExecArray = hb_itemArrayNew( 3 );
            hb_arraySetForward( pExecArray, 1, hb_arrayGetItemPtr( pFunction, 2 ) );
            hb_arraySetNI( pExecArray, 2, uiSig );

            /* the third parameter is an array:
             * 1: low-level signal
             * 2: low-level subsignal
             * 3: low-level system error
             * 4: address that rised the signal
             * 5: process id of the signal riser
             * 6: UID of the riser
             */

            pRet = hb_arrayGetItemPtr( pExecArray, 3 );
            hb_arrayNew( pRet, 6 );

            hb_arraySetNI( pRet, HB_SERVICE_OSSIGNAL, type );
            hb_arraySetNI( pRet, HB_SERVICE_OSSUBSIG, sig );
            /* could be meaningless, but does not matter here */
            hb_arraySetNI( pRet, HB_SERVICE_OSERROR, GetLastError() );

            if( type == 0 ) /* exception */
                hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, ( void * ) exc->ExceptionAddress );
            else
                hb_arraySetPtr( pRet, HB_SERVICE_ADDRESS, NULL );

            /* TODO: */
            hb_arraySetNI( pRet, HB_SERVICE_PROCESS, GetCurrentThreadId() );
            /* TODO: */
            hb_arraySetNI( pRet, HB_SERVICE_UID, 0 );

            pRet = hb_itemDo( pExecArray, 0 );
            iRet = hb_itemGetNI( pRet );
            hb_itemRelease( pRet );
            hb_itemRelease( pExecArray );

            switch( iRet )
            {
            case HB_SERVICE_HANDLED:
                s_bSignalEnabled = HB_TRUE;
                hb_threadLeaveCriticalSection( &s_ServiceMutex );
                return EXCEPTION_CONTINUE_EXECUTION;

            case HB_SERVICE_QUIT:
                s_bSignalEnabled = HB_FALSE;
                hb_threadLeaveCriticalSection( &s_ServiceMutex );
                hb_vmRequestQuit();
#ifndef HB_THREAD_SUPPORT
                hb_vmQuit();
                exit( 0 );
#else
                hb_threadCancelInternal();
#endif
            }
        }
        nPos--;
    }

    s_bSignalEnabled = HB_TRUE;
    return EXCEPTION_EXECUTE_HANDLER;
}
开发者ID:vszakats,项目名称:harbour-core,代码行数:97,代码来源:hbserv.c

示例13: WriteToDatabase

DWORD WINAPI WriteToDatabase( LPVOID lpParam )
{ 
	DWORD dwCount=0, dwWaitResult; 
	DWORD time_out = 30;	//time_out Milliseconds while WaitForSingleObject
	DWORD sleep_time = 29;	//sleep_time Milliseconds while WritetoDatabase

	// Request ownership of mutex.

	while( dwCount < 10 )
	{
// 		dwWaitResult = WaitForSingleObject( 
// 			ghMutex,    // handle to mutex
// 			INFINITE);  // no time-out interval

		dwWaitResult = WaitForSingleObject( 
			ghMutex,    // handle to mutex
			time_out);	//wait for time_out Milliseconds

// 		dwWaitResult = WaitForSingleObject( 
// 			ghMutex,    // handle to mutex
// 			IGNORE);	//ignore

		switch (dwWaitResult) 
		{
			// The thread got ownership of the mutex
		case WAIT_OBJECT_0: 
			__try { 
				// TODO: Write to the database
				printf("Thread %d writing to database...\n", 
					GetCurrentThreadId());
				dwCount++;
 				Sleep (sleep_time);
			} 
			__finally { 
				// Release ownership of the mutex object
				if (! ReleaseMutex(ghMutex)) 
				{ 
					// Deal with error.
					printf("Thread %d ReleaseMutex error!\n",
						GetCurrentThreadId ());
				} 
			} 
			break; 

			// The thread got ownership of the mutex time-out
		case WAIT_TIMEOUT:
			{
				// Deal with error.
				printf("Thread %d WaitForSingleObject time-out! dwWaitResult = 0X%08X\n",
					GetCurrentThreadId (),dwWaitResult);
			}
			break;

			// The thread got ownership of an abandoned mutex
		case WAIT_ABANDONED: 
			{
				// Deal with error.
				printf("Thread %d got ownership of an abandoned mutex!\n",
					GetCurrentThreadId ());
			}
			return FALSE;

			//The WaitForSingleObject function failed
		case WAIT_FAILED :
			{
				// Deal with error.
				printf("The WaitForSingleObject function failed!\n");
			}
			return FALSE; 

		default:
			break;
		}
	}
	return TRUE; 
}
开发者ID:codeworkscn,项目名称:learn-cpp,代码行数:76,代码来源:Main.cpp

示例14: GetCurrentThreadId

    //--------------------------------------------------------------------------------
    void GameNetL2NEventDataFactory::createGameNetSendDataBufferPtr(GameNetSendDataBufferPtr& ptr, U32 buffSize)
    {
        NetSendDataBuffer* buffObj                  = NULL;
        std::deque<NetSendDataBuffer*>* idleList    = NULL;
        GameNetSendDataBufferPool*      pool        = NULL;
        GameNetSendDataBufferPoolManager* poolMgr   = NULL;

        DWORD threadId = GetCurrentThreadId();
        poolMgr = createOrRetrieveGameNetSendDataBufferPoolManager( threadId );
        if ( poolMgr )
        {
            Bool isNormalBuff   = true;

            pool                = poolMgr->m_CreateObjectList;

            // 如果小于默认值, 则分配缓存等于默认值
            if ( buffSize <= MG_GAME_NET_PACKET_NORMAL_MAX_SIZE )
            {
                buffSize        = MG_GAME_NET_PACKET_NORMAL_MAX_SIZE;
                isNormalBuff    = true;
            }else
            if ( buffSize <= MG_GAME_NET_PACKET_BIG_MAX_SIZE )
            {
                buffSize        = MG_GAME_NET_PACKET_BIG_MAX_SIZE;
                isNormalBuff    = false;
            }else
            {
                DYNAMIC_EEXCEPT_LOG("createGameNetSendDataBufferPtr : too long buffsize ");
                return;
            }

            pool->mPoolCs.lock();
            {
                if ( isNormalBuff )
                {
                    idleList = &pool->m_IdleNormalObjectList;
                }else
                {
                    idleList = &pool->m_IdleBigObjectList;
                }

                if ( idleList->size() > 0 )
                {
                    buffObj = idleList->back();
                    idleList->pop_back();
                }else
                {
                    buffObj = mDriverMgr->mMgr->createNetSendDataBuffer( buffSize );
                }
            }
            pool->mPoolCs.unlock();


            poolMgr->mCreateCount++;

        }else
        {
            DYNAMIC_EEXCEPT_LOG("createGameNetSendDataBufferPtr: not register thread !");
        }

        if ( buffObj )
        {
            buffObj->initialize();
			buffObj->setActive( true );

            ptr.setNull();
            ptr.mFactory            = this;
            ptr.mCreateThreadID     = threadId;
            ptr.mNearestSendNetID   = -1;
            ptr.mLogicDataMaxSize   = buffSize;
            ptr.bind( buffObj );

            if ( poolMgr )
            {
                poolMgr->mNearestCreatePtr.setNull();
                poolMgr->mNearestCreatePtr = ptr;
            }
        }
    }
开发者ID:dnjsflagh1,项目名称:code,代码行数:80,代码来源:GameNetL2NEventData.cpp

示例15: OutputDebugStringA

// Credit to NTAuthority
LONG WINAPI DumpHandler::CustomUnhandledExceptionFilter(LPEXCEPTION_POINTERS ExceptionInfo)
{
	// Ignore breakpoints.
	if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_BREAKPOINT) return EXCEPTION_CONTINUE_EXECUTION;

	// Try skipping exceptions
	/* Disable that, it seems unsafe
	if ((ExceptionInfo->ExceptionRecord->ExceptionFlags & EXCEPTION_NONCONTINUABLE) != EXCEPTION_NONCONTINUABLE)
	{
		OutputDebugStringA(hString::va("New exception at 0x%X, try ignoring it...", ExceptionInfo->ExceptionRecord->ExceptionAddress));
		ExceptionInfo->ExceptionRecord->ExceptionFlags |= EXCEPTION_NONCONTINUABLE;
		return EXCEPTION_CONTINUE_EXECUTION;
	}
	else
	{
		OutputDebugStringA("Ignoring failed. Handling it now...");
	}
	*/

	// step 1: write minidump
	char error[1024];
	char filename[MAX_PATH];
	__time64_t time;
	tm* ltime;

	_time64(&time);
	ltime = _localtime64(&time);
	strftime(filename, sizeof(filename) - 1, "Redacted - %H-%M-%S %d.%m.%Y.dmp", ltime);
	_snprintf(error, sizeof(error) - 1, "A minidump has been written to %s.", filename);

	HANDLE hFile = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);

	if (hFile != INVALID_HANDLE_VALUE)
	{
		MINIDUMP_EXCEPTION_INFORMATION ex = { 0 };
		ex.ThreadId = GetCurrentThreadId();
		ex.ExceptionPointers = ExceptionInfo;
		ex.ClientPointers = FALSE;

		MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &ex, NULL, NULL);

		CloseHandle(hFile);
	}
	else
	{
		_snprintf(error, sizeof(error) - 1, "An error (0x%x) occurred during creating %s.", GetLastError(), filename);
	}

	// step 2: exit the application
	// why was this removed?
	if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW)
	{
		MessageBox(0, "Termination because of a stack overflow.", "ERROR", MB_ICONERROR);
	}
	else
	{
		MessageBox(0, hString::va("Fatal error (0x%08x) at 0x%08x.\n%s", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionInfo->ExceptionRecord->ExceptionAddress, error), "ERROR", MB_ICONERROR);
	}

	TerminateProcess(GetCurrentProcess(), ExceptionInfo->ExceptionRecord->ExceptionCode);
	return 0;
}
开发者ID:RaptorFactor,项目名称:SteamBase,代码行数:63,代码来源:DumpHandler.cpp


注:本文中的GetCurrentThreadId函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。