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


C++ ResumeThread函数代码示例

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


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

示例1: SearchWorkThreadMgrProc

DWORD WINAPI SearchWorkThreadMgrProc(LPVOID lpParm)
{
	CQuickSearchDlg * lpDlg = (CQuickSearchDlg *)lpParm;
	if (lpDlg == NULL)
	{
		lpDlg->NotifyStatusMsg(_T("线程的非法引用!请退出程序,然后重试。"));
		return ERROR_INVALID_PARAMETER;
	}
	if (!EnablePrivilege(SE_DEBUG_NAME, TRUE))
	{
		lpDlg->NotifyStatusMsg(_T("提权失败!"));
		return ERROR_ACCESS_DENIED;
	}
	for (int i = 0; lpDlg->GetSafeHwnd() == NULL && i < 10; i++)
		Sleep(100);

	lpDlg->NotifyStatusMsg(_T("就绪..."));
	while (TRUE)
	{
		TCHAR szMsg[nMSG_SIZE] = { 0 };
		ULONG nFoundedCont = 0;

		WaitForSingleObject(g_hSearchEvent, INFINITE);
		if (WaitForSingleObject(g_hQuitEvent, 50) == WAIT_OBJECT_0)
		{
			// 执行搜索之前检测有无退出信号
			break;
		}

		lpDlg->InitList();
		SEARCH_PROGRRESS_INFO spi[26] = { 0 };
		for (short i = 0; i < 26; i++)
		{
			spi[i].m_nFoundCount = 0;
			spi[i].m_nViewCount = 0;
			spi[i].m_lpDlg = lpDlg;
			spi[i].m_Update = update;
			ParseSearchObject(lpDlg->GetSearchString().GetBuffer(), spi[i].m_vecSearchStrings);
			lpDlg->GetSearchString().ReleaseBuffer();
		}

		g_nTotalFound = 0;			// 已经找到的数量
		g_nTotalView = 0;			// 已经查找了的数量
		CString strSearchStartPath(lpDlg->GetSearchLocation());
		short nSearchThreadIndex = 0;
		HANDLE hSearchThread[26] = { 0 };
		DWORD dwSeachThreadId[26] = { 0 };
		if (strSearchStartPath == _T("0"))
		{
			TCHAR szAllDriverLetters[100] = { 0 };
			DWORD len = GetLogicalDriveStrings(sizeof(szAllDriverLetters) / sizeof(TCHAR), szAllDriverLetters);
			for (TCHAR * lpszCurrentDriverLetter = szAllDriverLetters; *lpszCurrentDriverLetter; lpszCurrentDriverLetter += _tcslen(lpszCurrentDriverLetter) + 1)
			{
				// 创建搜索线程
				Sleep(nSearchThreadIndex * 1000);
				StringCchPrintf(spi[nSearchThreadIndex].m_szStartLocation, MAX_PATH - 1, _T("%C:"), lpszCurrentDriverLetter[0]);
				spi[nSearchThreadIndex].m_bFastMode = lpDlg->GetFastMode();
				hSearchThread[nSearchThreadIndex] = CreateThread(
					NULL,         // 使用默认的安全描述符
					0,            // 使用默认的栈大小
					(LPTHREAD_START_ROUTINE)SearchThreadProc,
					(LPVOID)(spi + nSearchThreadIndex),
					CREATE_SUSPENDED,						// 先挂起
					dwSeachThreadId + nSearchThreadIndex);	// 取得线程ID
				if (hSearchThread[nSearchThreadIndex])
				{
					if (spi[nSearchThreadIndex].m_bFastMode)
						if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_TIME_CRITICAL))
							if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_HIGHEST))
								if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_ABOVE_NORMAL))
									if (!SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_HIGHEST))
										SetThreadPriority(hSearchThread[nSearchThreadIndex], THREAD_PRIORITY_NORMAL);
					ResumeThread(hSearchThread[nSearchThreadIndex]);
					SetThreadPriorityBoost(hSearchThread[nSearchThreadIndex], !spi[nSearchThreadIndex].m_bFastMode);	// 系统动态调整线程优先级选项
					nSearchThreadIndex++;
				}
			}
			WaitForMultipleObjects(nSearchThreadIndex, hSearchThread, TRUE, INFINITE);
			for (short i = 0; i < nSearchThreadIndex; i++)
			{
				if (hSearchThread[i])
					CloseHandle(hSearchThread[i]);
			}
		}
		else
		{
			// 创建搜索线程
			DWORD ThreadID = 0;
			StringCchPrintf(spi[0].m_szStartLocation, MAX_PATH - 1, _T("%s"), strSearchStartPath);
			spi[0].m_bFastMode = lpDlg->GetFastMode();
			hSearchThread[0] = CreateThread(
				NULL,         // 使用默认的安全描述符
				0,            // 使用默认的栈大小
				(LPTHREAD_START_ROUTINE)SearchThreadProc,
				(LPVOID)&spi[0],
				CREATE_SUSPENDED,						// 先挂起
				&ThreadID);	// 取得线程ID
			if (hSearchThread)
			{
				if (spi[0].m_bFastMode)
//.........这里部分代码省略.........
开发者ID:ccpwcn,项目名称:QuickSearch,代码行数:101,代码来源:SearchModule.cpp

示例2: ListenForClientConnection

/*
Name: ListenForClientConnection
Description: This function will have an infinite loop where it will wait forever for client connections. Once client connection is established.
			 It will process it in a fast way or religate the work to a thread and keeps waiting for new connections.
Parameters: - 
ReturnValue: 0 for success else error codes.
*/
int ListenForClientConnection()
{
	int nReturnValue = 0;
	struct addrinfo *structClientAddrInfo = NULL;
	SOCKET scClientSocket = INVALID_SOCKET;
	HANDLE hClientThread = NULL;
	DWORD dwClientThreadId = 0;
	char szMessage[1024] = { '\0' };

	LogMessage(LOG_DEBUG, "Started to listen for client connection");

	if (INVALID_SOCKET == scListenSocket)
	{
		LogMessage(LOG_ERROR, "Invalid listen socket");
		nReturnValue = ERR_INVALIDLISTENSOCKET;
		return nReturnValue;
	}

	LogMessage(LOG_INFO, "listening.........");
	nReturnValue = listen(scListenSocket, SOMAXCONN);
	if (nReturnValue == SOCKET_ERROR)
	{
		//printf_s("BHS:ERROR:listen failed with error %d\n", WSAGetLastError());
		sprintf_s(szMessage, 1024, "listen failed with error %d\n", WSAGetLastError());
		LogMessage(LOG_ERROR, szMessage);
		closesocket(scListenSocket);
		scListenSocket = INVALID_SOCKET;
		WSACleanup();
		nReturnValue = ERR_LISTENFAILURE;
		return nReturnValue;
	}

	LogMessage(LOG_INFO, "Initializing synchronization elements");

	InitializeCriticalSection(&mcriticalThreadSync);
	InitializeConditionVariable(&mcvThreadCount);

	LogMessage(LOG_INFO, "Going for infinite loop of accepts");
	while ((scClientSocket = accept(scListenSocket, NULL, NULL)) != INVALID_SOCKET)
	{

		//printf_s("BHS:INFO:Client connection established: \n");
		LogMessage(LOG_INFO, "Client connection established, Creating a thread to handle the connection");
		//printf_s("BHS:INFO:Creating a thread to handle the connection\n");
		
		hClientThread = CreateThread(NULL, 0, HandleClientRequestThread, scClientSocket, 0x00000004, &dwClientThreadId);

		EnterCriticalSection(&mcriticalThreadSync);


		if (nThread_Count >= nThreadPoolSize)
		{
			LogMessage(LOG_DEBUG, "Active thread count is more than thread pool size");
			SleepConditionVariableCS(&mcvThreadCount, &mcriticalThreadSync, INFINITE);
			LogMessage(LOG_DEBUG, "Got up from sleep(wait), now waking the creating thread to handle client request");
			
		}

		nThread_Count++;
		ResumeThread(hClientThread);

		LeaveCriticalSection(&mcriticalThreadSync);

		LogMessage(LOG_INFO, "Returning to wait for new client connections......");
		//printf_s("BHS:INFO:Returning to wait for new connections......\n");
	}

	if (scClientSocket == INVALID_SOCKET)
	{
		//printf_s("BHS:ERROR:Invalid client socket %d\n", WSAGetLastError());
		sprintf_s(szMessage, 1024, "Invalid client socket %d\n", WSAGetLastError());
		LogMessage(LOG_ERROR, szMessage);
		nReturnValue = ERR_INVALIDCLIENTSOCKET;
	}
	else
	{
		LogMessage(LOG_INFO, "Closing the client socket");
		closesocket(scClientSocket);
		scClientSocket = INVALID_SOCKET;
	}
	
	LogMessage(LOG_INFO, "Closing the listen socket");
	closesocket(scListenSocket);
	scListenSocket = INVALID_SOCKET;
	WSACleanup();

	DeleteCriticalSection(&mcriticalThreadSync);
	
	LogMessage(LOG_DEBUG, "Finished listening for client connection");
	return nReturnValue;
}
开发者ID:harsha-kadekar,项目名称:BasicHttpServerClient,代码行数:98,代码来源:BasicHttpServer.c

示例3: fork


//.........这里部分代码省略.........
	 *       that the parameters in the structure are trustworthy.
	 *    5. Wait for h64Child so that we know the child has created the stack
	 *       in dynamic memory.
	 *
	 *   The rest of the fork hack should now proceed as in x86
	 *
	 */
	if (bIsWow64Process) {

		// allocate the heap for the child. this can be done even when
		// the child is suspended. 
		// avoids inexplicable allocation failures in the child.
		if (VirtualAllocEx(hProc,
							__heap_base,
							__heap_size,
							MEM_RESERVE,
							PAGE_READWRITE) == NULL) {
			dprintf("virtual allocex failed %d\n",GetLastError());
			goto error;
		}
		if (VirtualAllocEx(hProc,
							__heap_base,
							__heap_size,
							MEM_COMMIT,
							PAGE_READWRITE) == NULL) {
			dprintf("virtual allocex2 failed %d\n",GetLastError());
			goto error;
		}

		// Do NOT expect existing events
		if (!CreateWow64Events(pi.dwProcessId,&h64Parent,&h64Child,FALSE)) {
			goto error;
		}
		ResumeThread(hThread);

		// wait for the child to tell us it is running
		//if (WaitForSingleObject(h64Child,FORK_TIMEOUT) != WAIT_OBJECT_0) {
		//	rc = GetLastError();
		//	goto error;
		//}
		hArray[0] = h64Child;
		hArray[1] = hProc;

		if (WaitForMultipleObjects(2,hArray,FALSE,FORK_TIMEOUT) != 
						WAIT_OBJECT_0){

			rc = GetLastError();
			goto error;
		}

	}
	//
	// Copy all the shared data
	//
	if (!WriteProcessMemory(hProc,&gForkData,&gForkData,
			sizeof(ForkData),&rc)) {
		goto error;
	}
	if (rc != sizeof(ForkData)) 
		goto error;

	if (!bIsWow64Process) {
		rc = ResumeThread(hThread);
	}
	// in the wow64 case, the child will be waiting  on h64parent again.
	// set it, and then wait for h64child. This will mean the child has
开发者ID:cftyngit,项目名称:nctuns,代码行数:67,代码来源:fork.c

示例4: InjectDll

JECT_EXTERN
unsigned WINAPI InjectDll(void *mpara)
{
    BOOL			bRet		= FALSE;
    LPVOID			funcBuff	= NULL;
    HANDLE			hRemote		= NULL;
    LPVOID			pBuff		= NULL;
    SIZE_T			cbSize		= sizeof(RemotePara);
    SIZE_T			cbCodeSize	= (LPBYTE)AfterThreadProc - (LPBYTE)ThreadProc;
    HMODULE			hNtdll;
    WCHAR			dll_name[VALUE_LEN+1];
    RemotePara		myPara;
    DWORD           os	   = GetOsVersion();
    PROCESS_INFORMATION pi = *(LPPROCESS_INFORMATION)mpara;

    if ( GetModuleFileNameW(dll_module,dll_name,VALUE_LEN) <=0 )
    {
        return bRet;
    }
    /* when tcmalloc enabled or MinGW x64 compile time,InjectDll crash on win8/8.1 */
#if !defined(ENABLE_TCMALLOC) && !defined(__MINGW64__)
    if ( os > 601 )
    {
#ifdef _LOGDEBUG
        logmsg("pic inject runing\n");
#endif
        return pic_inject(mpara,dll_name);
    }
#endif
    hNtdll = GetModuleHandleW(L"ntdll.dll");
    if (!hNtdll)
    {
        return bRet;
    }
    fzero(&myPara, sizeof(myPara));
    myPara.dwLoadLibraryAddr = (DWORD_PTR)GetProcAddress(hNtdll, "LdrLoadDll");
    myPara.dwRtlInitUnicodeString = (DWORD_PTR)GetProcAddress(hNtdll, "RtlInitUnicodeString");
    if ( (myPara.dwLoadLibraryAddr)&&(myPara.dwRtlInitUnicodeString) )
    {
        DWORD dwThreadId  = 0;
        wcsncpy(myPara.strDll,dll_name,VALUE_LEN);
        /* 在进程内分配空间 */
        pBuff = VirtualAllocEx(pi.hProcess, 0, cbSize+cbCodeSize, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
        funcBuff = ((BYTE *)pBuff+cbSize);
        /* 写入参数空间 */
        WriteProcessMemory(pi.hProcess, pBuff, (PVOID)&myPara, cbSize, NULL);
        /* 写入代码空间 */
        WriteProcessMemory(pi.hProcess, funcBuff, (PVOID)ThreadProc, cbCodeSize, NULL);
        hRemote = CreateRemoteThread(pi.hProcess,
                                     NULL,
                                     1024*1024,
                                     (LPTHREAD_START_ROUTINE)funcBuff,
                                     pBuff,
                                     CREATE_SUSPENDED,
                                     &dwThreadId);
        if (hRemote)
        {
            ResumeThread(hRemote);
            WaitForSingleObject(hRemote,1500);
            CloseHandle(hRemote);
        }
        if (pBuff)
        {
            VirtualFreeEx(pi.hProcess, pBuff, 0, MEM_RELEASE);
        }
        if (funcBuff)
        {
            VirtualFreeEx(pi.hProcess, funcBuff, 0, MEM_RELEASE);
        }
    }
    ResumeThread(pi.hThread);
    return bRet;
}
开发者ID:DINKIN,项目名称:pcxfirefox,代码行数:73,代码来源:inject.c

示例5: pthread_create


//.........这里部分代码省略.........
     * race condition between the creating and the created threads.
     * Note that we also retain a local copy of the handle for use
     * by us in case thread.p->threadH gets NULLed later but before we've
     * finished with it here.
     */

#if ! defined (PTW32_CONFIG_MINGW) || defined (__MSVCRT__) || defined (__DMC__)

    tp->threadH =
        threadH =
            (HANDLE) _beginthreadex ((void *) NULL,	/* No security info             */
                                     stackSize,		/* default stack size   */
                                     ptw32_threadStart,
                                     parms,
                                     (unsigned)
                                     CREATE_SUSPENDED,
                                     (unsigned *) &(tp->thread));

    if (threadH != 0)
    {
        if (a != NULL)
        {
            (void) ptw32_setthreadpriority (thread, SCHED_OTHER, priority);
        }

#if defined(HAVE_CPU_AFFINITY)

        SetThreadAffinityMask(tp->threadH, tp->cpuset);

#endif

        if (run)
        {
            ResumeThread (threadH);
        }
    }

#else

    {
        ptw32_mcs_local_node_t stateLock;

        /*
         * This lock will force pthread_threadStart() to wait until we have
         * the thread handle and have set the priority.
         */
        ptw32_mcs_lock_acquire(&tp->stateLock, &stateLock);

        tp->threadH =
            threadH =
                (HANDLE) _beginthread (ptw32_threadStart, stackSize,	/* default stack size   */
                                       parms);

        /*
         * Make the return code match _beginthreadex's.
         */
        if (threadH == (HANDLE) - 1L)
        {
            tp->threadH = threadH = 0;
        }
        else
        {
            if (!run)
            {
                /*
                 * beginthread does not allow for create flags, so we do it now.
开发者ID:nicolaichuk,项目名称:pthread-win32,代码行数:67,代码来源:create.c

示例6: main

/**
 * main
 *
 * executable entry point
 */
INT __cdecl main( INT argc, CHAR **argv )
{
    DWORD IDThread;

    int i;

    /* PAL initialization */
    if( (PAL_Initialize(argc, argv)) != 0 )
    {
        return( FAIL );
    }

    /* set the thread priority of the main to the highest possible value
       this will give the chance to the main thread to create all the
       other threads */
    if(!SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL))
    {
        DWORD dwError;

        dwError = GetLastError();
        Fail( "Unexpected SetThreadPriority() failure with error %d\n",
			  dwError );
    }

    printf( "Launching multiple threads, please wait...\n" );

    /* Create multiple threads. */
    for( i = 0; i < NUM_THREADS; i++ )
    {
        hThread[i] = CreateThread( NULL,         /* no security attributes */
                                   0,            /* use default stack size */
          (LPTHREAD_START_ROUTINE) ThreadFunc,   /* thread function */
                          (LPVOID) i,            /* pass thread index as */
                                                 /* function argument */
                                   CREATE_SUSPENDED, /* create suspended */
                                   &IDThread );  /* returns thread identifier */

        /* Check the return value for success. */
        if( hThread[i] == NULL )
        {
	        /*ERROR */
            DWORD dwError = GetLastError();
            Fail( "Unexpected CreateThread error %d\n",
                  dwError );
        }

        ResumeThread(hThread[i]);
    }

    /* Wait for all threads to finish */
    for (i = 0; i < NUM_THREADS; i++)
    {
        DWORD dwRet;

        dwRet = WaitForSingleObject( hThread[i], INFINITE );

        if( dwRet == WAIT_FAILED )
        {
            /* ERROR */
            DWORD dwError = GetLastError();
            Fail( "Unexpected WaitForSingleObject error %d\n",
                  dwError );
        }
    }

    /* make sure the thread processing times match the priorities */
    for( i=NUM_THREADS-1; i > 0; i-- )
    {
        if( nElapsedTime[i] >= nElapsedTime[i-1] )
        {
            /*
             * a lower-priority thread finished faster than a lower-priority
             * thread -- this shouldn't happen if the dummy thread function
             * is non-trivial in length
             */
            Fail( "Failed: processing time doesn't match thread priority\n" );
        }
    }

    PAL_Terminate();
    return PASS;
}
开发者ID:ArildF,项目名称:masters,代码行数:87,代码来源:threadpriority.c

示例7: SpkrThread

unsigned int __stdcall SpkrThread(LPVOID Unused)
{
    int      i;
    DWORD    bufLen = ((N_SAMPLES * BITS_PER_SAMPLE) / 8);
    WAVEHDR* pWH;
    MMRESULT ret;
    int      played;
    MSG      tMsg;
    BOOL     bGotMsg ;
    int      n;
    bool     bDone ;
    static bool sLastRingerEnabled = false;
    OsStatus res;
    static bool bRunning = false ;
    HWAVEOUT hOut = NULL;

    // Verify that only 1 instance of the MicThread is running
    if (bRunning) 
    {
       ResumeThread(hMicThread);
       return 1 ;
    }
    else
    {
       bRunning = true ;
    }
    ResumeThread(hMicThread);


#ifdef OHISTORY /* [ */
    WAVEHDR* lastWH[OHISTORY];
    int      lastInd[OHISTORY];
    int      last = 0;

    for (i=0;i<OHISTORY;i++) 
    {
        lastWH[i] = 0;
        lastInd[i] = 0;
    }

    memset(histOut, 0xff, sizeof(histOut));
    lastOut = 0;
#endif /* OHISTORY ] */
    
    // Initialize headers
    for (i=0; i<N_OUT_BUFFERS; i++) 
    {
        hOutHdr[i] = hOutBuf[i] = NULL;
        pOutHdr[i] = NULL;
    }
    
    if (openSpeakerDevices(pWH, hOut))
    {
        // NOT using a sound card
        // Set up a 10ms timer to call back to this routine
        timeSetEvent(10, 0, TimerCallbackProc, GetCurrentThreadId(), TIME_PERIODIC);
    }

    played = 0;   
    bDone = false ;
    while (!bDone)
    {
        bGotMsg = GetMessage(&tMsg, NULL, 0, 0);
              
        // when switching devices, ringer to in-call we need to make 
        // sure any outstanding buffers are flushed
        if (sLastRingerEnabled != DmaTask::isRingerEnabled())
        {
            if (audioOutH)
            {
                waveOutReset(audioOutH);
            }
            if (audioOutCallH)
            {
                waveOutReset(audioOutCallH);
            }
        }

        if (bGotMsg) 
        {
            switch (tMsg.message) 
            {
            case WM_ALT_HEARTBEAT:
                res = MpMediaTask::signalFrameStart();
                switch (res) 
                {
                    case OS_SUCCESS:
                        frameCount++;
                        break;
                    case OS_LIMIT_REACHED:
                    case OS_WAIT_TIMEOUT:
                    case OS_ALREADY_SIGNALED:
                    default:
                        // Should bump missed frame statistic
                        break;
                }
                break ;
            case WOM_DONE:
                pWH = (WAVEHDR *) tMsg.wParam;
                n = (pWH->dwUser) & USER_BUFFER_MASK;
//.........这里部分代码省略.........
开发者ID:mranga,项目名称:sipxecs,代码行数:101,代码来源:SpeakerThreadWnt.cpp

示例8: xPortStartScheduler

BaseType_t xPortStartScheduler( void )
{
void *pvHandle;
int32_t lSuccess = pdPASS;
xThreadState *pxThreadState;

	/* Install the interrupt handlers used by the scheduler itself. */
	vPortSetInterruptHandler( portINTERRUPT_YIELD, prvProcessYieldInterrupt );
	vPortSetInterruptHandler( portINTERRUPT_TICK, prvProcessTickInterrupt );

	/* Create the events and mutexes that are used to synchronise all the
	threads. */
	pvInterruptEventMutex = CreateMutex( NULL, FALSE, NULL );
	pvInterruptEvent = CreateEvent( NULL, FALSE, FALSE, NULL );

	if( ( pvInterruptEventMutex == NULL ) || ( pvInterruptEvent == NULL ) )
	{
		lSuccess = pdFAIL;
	}

	/* Set the priority of this thread such that it is above the priority of
	the threads that run tasks.  This higher priority is required to ensure
	simulated interrupts take priority over tasks. */
	pvHandle = GetCurrentThread();
	if( pvHandle == NULL )
	{
		lSuccess = pdFAIL;
	}

	if( lSuccess == pdPASS )
	{
		if( SetThreadPriority( pvHandle, THREAD_PRIORITY_NORMAL ) == 0 )
		{
			lSuccess = pdFAIL;
		}
		SetThreadPriorityBoost( pvHandle, TRUE );
		SetThreadAffinityMask( pvHandle, 0x01 );
	}

	if( lSuccess == pdPASS )
	{
		/* Start the thread that simulates the timer peripheral to generate
		tick interrupts.  The priority is set below that of the simulated
		interrupt handler so the interrupt event mutex is used for the
		handshake / overrun protection. */
		pvHandle = CreateThread( NULL, 0, prvSimulatedPeripheralTimer, NULL, 0, NULL );
		if( pvHandle != NULL )
		{
			SetThreadPriority( pvHandle, THREAD_PRIORITY_BELOW_NORMAL );
			SetThreadPriorityBoost( pvHandle, TRUE );
			SetThreadAffinityMask( pvHandle, 0x01 );
		}

		/* Start the highest priority task by obtaining its associated thread
		state structure, in which is stored the thread handle. */
		pxThreadState = ( xThreadState * ) *( ( uint32_t * ) pxCurrentTCB );
		ulCriticalNesting = portNO_CRITICAL_NESTING;

		/* Bump up the priority of the thread that is going to run, in the
		hope that this will assist in getting the Windows thread scheduler to
		behave as an embedded engineer might expect. */
		ResumeThread( pxThreadState->pvThread );

		/* Handle all simulated interrupts - including yield requests and
		simulated ticks. */
		prvProcessSimulatedInterrupts();
	}

	/* Would not expect to return from prvProcessSimulatedInterrupts(), so should
	not get here. */
	return 0;
}
开发者ID:Krezminski,项目名称:BeirutBotCode,代码行数:72,代码来源:port.c

示例9: prvProcessSimulatedInterrupts

static void prvProcessSimulatedInterrupts( void )
{
uint32_t ulSwitchRequired, i;
xThreadState *pxThreadState;
void *pvObjectList[ 2 ];

	/* Going to block on the mutex that ensured exclusive access to the simulated
	interrupt objects, and the event that signals that a simulated interrupt
	should be processed. */
	pvObjectList[ 0 ] = pvInterruptEventMutex;
	pvObjectList[ 1 ] = pvInterruptEvent;

	/* Create a pending tick to ensure the first task is started as soon as
	this thread pends. */
	ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK );
	SetEvent( pvInterruptEvent );

	xPortRunning = pdTRUE;

	for(;;)
	{
		WaitForMultipleObjects( sizeof( pvObjectList ) / sizeof( void * ), pvObjectList, TRUE, INFINITE );

		/* Used to indicate whether the simulated interrupt processing has
		necessitated a context switch to another task/thread. */
		ulSwitchRequired = pdFALSE;

		/* For each interrupt we are interested in processing, each of which is
		represented by a bit in the 32bit ulPendingInterrupts variable. */
		for( i = 0; i < portMAX_INTERRUPTS; i++ )
		{
			/* Is the simulated interrupt pending? */
			if( ulPendingInterrupts & ( 1UL << i ) )
			{
				/* Is a handler installed? */
				if( ulIsrHandler[ i ] != NULL )
				{
					/* Run the actual handler. */
					if( ulIsrHandler[ i ]() != pdFALSE )
					{
						ulSwitchRequired |= ( 1 << i );
					}
				}

				/* Clear the interrupt pending bit. */
				ulPendingInterrupts &= ~( 1UL << i );
			}
		}

		if( ulSwitchRequired != pdFALSE )
		{
			void *pvOldCurrentTCB;

			pvOldCurrentTCB = pxCurrentTCB;

			/* Select the next task to run. */
			vTaskSwitchContext();

			/* If the task selected to enter the running state is not the task
			that is already in the running state. */
			if( pvOldCurrentTCB != pxCurrentTCB )
			{
				/* Suspend the old thread. */
				pxThreadState = ( xThreadState *) *( ( uint32_t * ) pvOldCurrentTCB );
				SuspendThread( pxThreadState->pvThread );

				/* Obtain the state of the task now selected to enter the
				Running state. */
				pxThreadState = ( xThreadState * ) ( *( uint32_t *) pxCurrentTCB );
				ResumeThread( pxThreadState->pvThread );
			}
		}

		ReleaseMutex( pvInterruptEventMutex );
	}
}
开发者ID:Krezminski,项目名称:BeirutBotCode,代码行数:76,代码来源:port.c

示例10: resume_thread

void resume_thread(uint32_t tid)
{
    HANDLE thread_handle = open_thread(tid);
    ResumeThread(thread_handle);
    CloseHandle(thread_handle);
}
开发者ID:Axi0m-S,项目名称:CuckooMon---Calling-address,代码行数:6,代码来源:inject.c

示例11: main

int __cdecl main(int argc, char **argv)
{

    DWORD dwRet;
    DWORD dwRet1;
    bTestResult = FAIL;
    
    if ((PAL_Initialize(argc,argv)) != 0)
    {
        return(bTestResult);
    }

    /*
     * Create Critical Section Object
     */
    InitializeCriticalSection ( &CriticalSection );

    EnterCriticalSection ( &CriticalSection );

    hThread[0] = CreateThread(NULL,
                              0,
                              &ThreadTest1,
                              (LPVOID) 0,
                              CREATE_SUSPENDED,
                              &dwThreadId[0]);
    if (hThread[0] == NULL)
    {
        Trace("PALSUITE ERROR: CreateThread(%p, %d, %p, %p, %d, %p) call "
             "failed.\nGetLastError returned %d.\n", NULL, 0, &ThreadTest1,
             (LPVOID) 0, CREATE_SUSPENDED, &dwThreadId[0], GetLastError());
        LeaveCriticalSection(&CriticalSection);
        DeleteCriticalSection ( &CriticalSection );
        Fail("");
    }
    
    hThread[1] = CreateThread(NULL,
                              0,
                              &ThreadTest2,
                              (LPVOID) 0,
                              CREATE_SUSPENDED,
                              &dwThreadId[1]);
    if (hThread[1] == NULL)
    {
        Trace("PALSUITE ERROR: CreateThread(%p, %d, %p, %p, %d, %p) call "
             "failed.\nGetLastError returned %d.\n", NULL, 0, &ThreadTest2,
             (LPVOID) 0, CREATE_SUSPENDED, &dwThreadId[1], GetLastError());
        LeaveCriticalSection(&CriticalSection);

        dwRet = ResumeThread(hThread[0]);
        if (-1 == dwRet)
        {
            Trace("PALSUITE ERROR: ResumeThread(%p) call failed.\n"
                  "GetLastError returned '%d'.\n", hThread[0],
             GetLastError());
    }

        dwRet = WaitForSingleObject(hThread[0], 10000);
        if (WAIT_OBJECT_0 == dwRet)
        {
            Trace("PALSUITE ERROR: WaitForSingleObject(%p, %d) call "
                  "failed.  '%d' was returned instead of the expected '%d'.\n"
                  "GetLastError returned '%d'.\n", hThread[0], 10000, dwRet, 
                  WAIT_OBJECT_0, GetLastError());
        }

        if (0 == CloseHandle(hThread[0]))
        {
            Trace("PALSUITE NOTIFICATION: CloseHandle(%p) call failed.\n"
                  "GetLastError returned %d.  Not failing tests.\n", 
                  hThread[0], GetLastError());
        }

        DeleteCriticalSection(&CriticalSection);
        Fail("");
    }

    /* 
     * Set other thread priorities to be higher than ours & Sleep to ensure 
     * we give up the processor. 
     */
    dwRet = (DWORD) SetThreadPriority(hThread[0], 
                                      THREAD_PRIORITY_ABOVE_NORMAL);
    if (0 == dwRet)
    {
        Trace("PALSUITE ERROR: SetThreadPriority(%p, %d) call failed.\n"
              "GetLastError returned %d", hThread[0], 
              THREAD_PRIORITY_ABOVE_NORMAL, GetLastError());
    }
    
    dwRet = (DWORD) SetThreadPriority(hThread[1], 
                                      THREAD_PRIORITY_ABOVE_NORMAL);
    if (0 == dwRet)
    {
        Trace("PALSUITE ERROR: SetThreadPriority(%p, %d) call failed.\n"
              "GetLastError returned %d", hThread[1], 
              THREAD_PRIORITY_ABOVE_NORMAL, GetLastError());
    }

    dwRet = ResumeThread(hThread[0]);
    if (-1 == dwRet)
//.........这里部分代码省略.........
开发者ID:0-wiz-0,项目名称:coreclr,代码行数:101,代码来源:test4.cpp

示例12: cbDebugLoadLib

bool cbDebugLoadLib(int argc, char* argv[])
{
    if(argc < 2)
    {
        dputs(QT_TRANSLATE_NOOP("DBG", "Error: you must specify the name of the DLL to load\n"));
        return false;
    }

    LoadLibThreadID = fdProcessInfo->dwThreadId;
    HANDLE LoadLibThread = ThreadGetHandle((DWORD)LoadLibThreadID);

    DLLNameMem = MemAllocRemote(0, strlen(argv[1]) + 1);
    ASMAddr = MemAllocRemote(0, 0x1000);

    if(!DLLNameMem || !ASMAddr)
    {
        dputs(QT_TRANSLATE_NOOP("DBG", "Error: couldn't allocate memory in debuggee"));
        return false;
    }

    if(!MemWrite(DLLNameMem, argv[1], strlen(argv[1])))
    {
        dputs(QT_TRANSLATE_NOOP("DBG", "Error: couldn't write process memory"));
        return false;
    }

    int size = 0;
    int counter = 0;
    duint LoadLibraryA = 0;
    char command[50] = "";
    char error[MAX_ERROR_SIZE] = "";

    GetFullContextDataEx(LoadLibThread, &backupctx);

    if(!valfromstring("kernel32:LoadLibraryA", &LoadLibraryA, false))
    {
        dputs(QT_TRANSLATE_NOOP("DBG", "Error: couldn't get kernel32:LoadLibraryA"));
        return false;
    }

    // Arch specific asm code
#ifdef _WIN64
    sprintf_s(command, "mov rcx, %p", DLLNameMem);
#else
    sprintf_s(command, "push %p", DLLNameMem);
#endif // _WIN64

    assembleat(ASMAddr, command, &size, error, true);
    counter += size;

#ifdef _WIN64
    sprintf_s(command, "mov rax, %p", LoadLibraryA);
    assembleat(ASMAddr + counter, command, &size, error, true);
    counter += size;
    sprintf_s(command, "call rax");
#else
    sprintf_s(command, "call %p", LoadLibraryA);
#endif // _WIN64

    assembleat(ASMAddr + counter, command, &size, error, true);
    counter += size;

    SetContextDataEx(LoadLibThread, UE_CIP, ASMAddr);
    auto ok = SetBPX(ASMAddr + counter, UE_SINGLESHOOT | UE_BREAKPOINT_TYPE_INT3, (void*)cbDebugLoadLibBPX);

    ThreadSuspendAll();
    ResumeThread(LoadLibThread);

    unlock(WAITID_RUN);

    return ok;
}
开发者ID:bloodwrath,项目名称:x64dbg,代码行数:72,代码来源:cmd-misc.cpp

示例13: Quant_Init

CodecError CCodec_BC6H::CInitializeBC6HLibrary()
{
    if (!m_LibraryInitialized)
    {
        // This is shared between BC7 also
        // and checked for initialization based on static flag
        // See the function for details.
        Quant_Init();

        // One time initialisation for quantizer and shaker
        // check this is ok to remove for when we are encoding 
        // should have no effect on decoding
        BC6H_init_ramps();


        for(DWORD i=0; i < BC6H_MAX_THREADS; i++)
        {
            m_encoder[i] = NULL;
        }

        // Create threaded encoder instances
        m_LiveThreads = 0;
        m_LastThread  = 0;
        m_NumEncodingThreads = min(m_NumThreads, BC6H_MAX_THREADS);
        if (m_NumEncodingThreads == 0) m_NumEncodingThreads = 1; 
        m_Use_MultiThreading = m_NumEncodingThreads > 1;

        g_BC6EncodeParameterStorage = new BC6HEncodeThreadParam[m_NumEncodingThreads];
        if(!g_BC6EncodeParameterStorage)
        {
            return CE_Unknown;
        }

        for (int i=0; i<m_NumEncodingThreads; i++)
            g_BC6EncodeParameterStorage[i].run = false;

        m_EncodingThreadHandle = new HANDLE[m_NumEncodingThreads];
        if(!m_EncodingThreadHandle)
        {
            delete[] g_BC6EncodeParameterStorage;
            g_BC6EncodeParameterStorage = NULL;

            return CE_Unknown;
        }

        for(int i=0; i < m_NumEncodingThreads; i++)
        {
            // Create single encoder instance
            CMP_BC6H_BLOCK_PARAMETERS user_options;

            user_options.bIsSigned      = m_bIsSigned;
            user_options.fQuality       = m_Quality;
            user_options.dwMask         = m_ModeMask;
            user_options.fExposure      = m_Exposure;
            user_options.bUsePatternRec = m_UsePatternRec;

            m_encoder[i] = new BC6HBlockEncoder(user_options);
                        
            // Cleanup if problem!
            if(!m_encoder[i])
            {

                delete[] g_BC6EncodeParameterStorage;
                g_BC6EncodeParameterStorage = NULL;

                delete[] m_EncodingThreadHandle;
                m_EncodingThreadHandle = NULL;

                for(int j=0; j<i; j++)
                {
                    delete m_encoder[j];
                    m_encoder[j] = NULL;
                }

                return CE_Unknown;
            }
            
            #ifdef USE_DBGTRACE
                DbgTrace(("Encoder[%d]:ModeMask %X, Quality %f\n",i,m_ModeMask,m_Quality));
            #endif
        }

        // Create the encoding threads in the suspended state
        for(int i=0; i<m_NumEncodingThreads; i++)
        {
            m_EncodingThreadHandle[i] = (HANDLE)_beginthreadex(NULL,
                                               0,
                                               BC6HThreadProcEncode,
                                               (void*)&g_BC6EncodeParameterStorage[i],
                                               CREATE_SUSPENDED,
                                               NULL);
            if(m_EncodingThreadHandle[i])
            {
                g_BC6EncodeParameterStorage[i].encoder = m_encoder[i];
                // Inform the thread that at the moment it doesn't have any work to do
                // but that it should wait for some and not exit
                g_BC6EncodeParameterStorage[i].run = FALSE;
                g_BC6EncodeParameterStorage[i].exit = FALSE;
                // Start the thread and have it wait for work
                ResumeThread(m_EncodingThreadHandle[i]);
//.........这里部分代码省略.........
开发者ID:NoSuchProcess,项目名称:Compressonator,代码行数:101,代码来源:Codec_BC6H.cpp

示例14: ResumeThread

DWORD CThread::Resume()
{
	return ResumeThread(m_hThread);
}
开发者ID:linstyle,项目名称:0xTiger2,代码行数:4,代码来源:CThread.cpp

示例15: DetourTransactionCommitEx


//.........这里部分代码省略.........
#ifdef DETOURS_X64
#error Feature not supported in this release.

#endif // DETOURS_X64

#ifdef DETOURS_IA64
#error Feature not supported in this release.

#endif // DETOURS_IA64

#ifdef DETOURS_ARM
#error Feature not supported in this release.

#endif // DETOURS_ARM

        if (GetThreadContext(t->hThread, &cxt)) {
            for (DetourOperation *o = s_pPendingOperations; o != NULL; o = o->pNext) {
                if (o->fIsRemove) {
                    if (cxt.DETOURS_EIP >= (DETOURS_EIP_TYPE)(ULONG_PTR)o->pTrampoline &&
                        cxt.DETOURS_EIP < (DETOURS_EIP_TYPE)((ULONG_PTR)o->pTrampoline
                                                             + sizeof(o->pTrampoline))
                       ) {

                        cxt.DETOURS_EIP = (DETOURS_EIP_TYPE)
                            ((ULONG_PTR)o->pbTarget
                             + detour_align_from_trampoline(o->pTrampoline,
                                                            (BYTE)(cxt.DETOURS_EIP
                                                                   - (DETOURS_EIP_TYPE)(ULONG_PTR)
                                                                   o->pTrampoline)));

                        SetThreadContext(t->hThread, &cxt);
                    }
                }
                else {
                    if (cxt.DETOURS_EIP >= (DETOURS_EIP_TYPE)(ULONG_PTR)o->pbTarget &&
                        cxt.DETOURS_EIP < (DETOURS_EIP_TYPE)((ULONG_PTR)o->pbTarget
                                                             + o->pTrampoline->cbRestore)
                       ) {

                        cxt.DETOURS_EIP = (DETOURS_EIP_TYPE)
                            ((ULONG_PTR)o->pTrampoline
                             + detour_align_from_target(o->pTrampoline,
                                                        (BYTE)(cxt.DETOURS_EIP
                                                               - (DETOURS_EIP_TYPE)(ULONG_PTR)
                                                               o->pbTarget)));

                        SetThreadContext(t->hThread, &cxt);
                    }
                }
            }
        }
#undef DETOURS_EIP
    }

    // Restore all of the page permissions and flush the icache.
    HANDLE hProcess = GetCurrentProcess();
    for (o = s_pPendingOperations; o != NULL;) {
        // We don't care if this fails, because the code is still accessible.
        DWORD dwOld;
        VirtualProtect(o->pbTarget, o->pTrampoline->cbRestore, o->dwPerm, &dwOld);
        FlushInstructionCache(hProcess, o->pbTarget, o->pTrampoline->cbRestore);

        if (o->fIsRemove && o->pTrampoline) {
            detour_free_trampoline(o->pTrampoline);
            o->pTrampoline = NULL;
            freed = true;
        }

        DetourOperation *n = o->pNext;
        delete o;
        o = n;
    }
    s_pPendingOperations = NULL;

    // Free any trampoline regions that are now unused.
    if (freed && !s_fRetainRegions) {
        detour_free_unused_trampoline_regions();
    }

    // Make sure the trampoline pages are no longer writable.
    detour_runnable_trampoline_regions();

    // Resume any suspended threads.
    for (t = s_pPendingThreads; t != NULL;) {
        // There is nothing we can do if this fails.
        ResumeThread(t->hThread);

        DetourThread *n = t->pNext;
        delete t;
        t = n;
    }
    s_pPendingThreads = NULL;
    s_nPendingThreadId = 0;

    if (pppFailedPointer != NULL) {
        *pppFailedPointer = s_ppPendingError;
    }

    return s_nPendingError;
}
开发者ID:chikyukotei,项目名称:MESSAGEBOX-HOOK,代码行数:101,代码来源:detours.cpp


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