Ejemplo n.º 1
0
nOS_Error nOS_ThreadResume (nOS_Thread *thread)
{
    nOS_Error       err;
    nOS_StatusReg   sr;
#if (NOS_CONFIG_HIGHEST_THREAD_PRIO > 0) && (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
    bool            sched = false;
#endif

#if (NOS_CONFIG_SAFE > 0)
    if (thread == NULL) {
        err = NOS_E_INV_OBJ;
    } else if (thread == nOS_runningThread) {
        err = NOS_E_INV_OBJ;
    } else if (thread == &nOS_idleHandle) {
        err = NOS_E_INV_OBJ;
    } else
#endif
    {
        nOS_EnterCritical(sr);
#if (NOS_CONFIG_SAFE > 0)
        if (thread->state == NOS_THREAD_STOPPED) {
            err = NOS_E_INV_OBJ;
        } else if ( !(thread->state & NOS_THREAD_SUSPENDED) ) {
            err = NOS_E_INV_STATE;
        } else
#endif
        {
#if (NOS_CONFIG_HIGHEST_THREAD_PRIO > 0) && (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
            _ResumeThread(thread, &sched);
#else
            _ResumeThread(thread, NULL);
#endif
#if (NOS_CONFIG_HIGHEST_THREAD_PRIO > 0) && (NOS_CONFIG_SCHED_PREEMPTIVE_ENABLE > 0)
            if (sched) {
                nOS_Schedule();
            }
#endif
            err = NOS_OK;
        }
        nOS_LeaveCritical(sr);
    }

    return err;
}
Ejemplo n.º 2
0
DWORD ProcessMonitor::ThreadHandler( DWORD dwProc, DWORD dwMode, DWORD dwValue )
{
	BOOL bOut = FALSE;
	///DWORD dwErr = -1, dwOut = -1, dwOldPerm;
	DWORD dwErr = -1, dwOut = -1;
	HANDLE hSnapTh = INVALID_HANDLE_VALUE;
	THREADENTRY32  te;
	ZeroMemory(&te, sizeof(THREADENTRY32));
	te.dwSize = sizeof(THREADENTRY32);

	hSnapTh = _CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD | TH32CS_SNAPNOHEAPS, dwProc);

	if (hSnapTh == INVALID_HANDLE_VALUE) {
/***
		if (FALSE == SHCloseApps((0xA00000))) {
			return NULL;
		}
***/
		hSnapTh = _CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD | TH32CS_SNAPNOHEAPS, dwProc);
		if (hSnapTh == INVALID_HANDLE_VALUE) {
			return NULL;
		}
	}

	if (_Thread32First(hSnapTh, &te)) {
		do {
			if (dwProc == te.th32OwnerProcessID) {
				
				if ((dwMode&TH_MASK) == TH_BY_PRI) {
					if (te.tpBasePri == dwValue) {
						SetLastError(0);

						dwOut =	te.th32ThreadID;

						if (dwMode == TH_TERMINATE_BY_PRI)	{

							if (_TerminateThread((HANDLE)te.th32ThreadID, 0) == TRUE) {
								dwOut = 0;
							}
						}

						if (dwMode == TH_SUSPEND_BY_PRI) {
							///SetKMode(TRUE);
							///dwOldPerm = SetProcPermissions(0xFFFFFFFF);

							if (_SuspendThread((HANDLE)te.th32ThreadID) != 0xFFFFFFFF) {
								dwOut =	te.th32ThreadID;
							}
						}

						if (dwMode == TH_RESUME_BY_PRI) {
							///SetKMode(TRUE);
							///dwOldPerm = SetProcPermissions(0xFFFFFFFF);

							if (_ResumeThread((HANDLE)te.th32ThreadID) != 0xFFFFFFFF) {
								dwOut = te.th32ThreadID;;
							}
						}

						break;					
					}
				}

				if ((dwMode&TH_MASK) == TH_ALL) {

					if (dwMode == TH_TERMINATE_ALL)	{

						if (_TerminateThread((HANDLE)te.th32ThreadID, 0) == TRUE) {
							dwOut = 0;
						}
					}

					if (dwMode == TH_SUSPEND_ALL) {
						///SetKMode(TRUE);
						///dwOldPerm = SetProcPermissions(0xFFFFFFFF);

						if (_SuspendThread((HANDLE)te.th32ThreadID) != 0xFFFFFFFF) {
							dwOut =	te.th32ThreadID;
						}
					}

					if (dwMode == TH_RESUME_ALL) {
						///SetKMode(TRUE);
						///dwOldPerm = SetProcPermissions(0xFFFFFFFF);

						if (_ResumeThread((HANDLE)te.th32ThreadID) != 0xFFFFFFFF) {
							dwOut = te.th32ThreadID;;
						}
					}
				}
			}
		} while (_Thread32Next(hSnapTh, &te));
	}

	///if (dwOldPerm != 0)
		///SetProcPermissions(dwOldPerm);
	///SetKMode(FALSE);

	if (hSnapTh != INVALID_HANDLE_VALUE && hSnapTh != NULL)
		_CloseToolhelp32Snapshot(hSnapTh);

	return dwOut;
}