Sha256: 2e12b1b8788fabc7b98e21fa3aea268b35c4b7f4d0774b32ce6c785a77262dce

Contents?: true

Size: 1.95 KB

Versions: 38

Compression:

Stored size: 1.95 KB

Contents

#include "stdafx.h"

#include "RhoThreadImpl.h"

namespace rho{
namespace common{
IMPLEMENT_LOGCLASS(CRhoThreadImpl,"RhoThread");

CRhoThreadImpl::CRhoThreadImpl() : m_hAwakeEvent(0), m_hThread(0)
{
    m_hAwakeEvent = ::CreateEvent(NULL, FALSE, FALSE, NULL);
}

CRhoThreadImpl::~CRhoThreadImpl()
{
    if ( m_hAwakeEvent )
        ::CloseHandle(m_hAwakeEvent);
}

static DWORD WINAPI runProc(void* pv) throw()
{
	IRhoRunnable* p = static_cast<IRhoRunnable*>(pv);
	p->runObject();
    ::ExitThread(0);
	return 0;
}

void CRhoThreadImpl::start(IRhoRunnable* pRunnable, IRhoRunnable::EPriority ePriority)
{
    DWORD dwThreadID;
    m_hThread = ::CreateThread(NULL, 0, runProc, pRunnable, 0, &dwThreadID);
    setThreadPriority(ePriority);
}

void CRhoThreadImpl::setThreadPriority(IRhoRunnable::EPriority ePriority)
{
    int nPriority = THREAD_PRIORITY_NORMAL;
    if ( ePriority == IRhoRunnable::epHigh )
        nPriority = THREAD_PRIORITY_HIGHEST;
    else if (ePriority == IRhoRunnable::epLow)
        nPriority = THREAD_PRIORITY_LOWEST;

    ::SetThreadPriority(m_hThread,nPriority);
}

void CRhoThreadImpl::stop(unsigned int nTimeoutToKill)
{
    stopWait();
    if ( m_hThread )
    {
        DWORD dwRes = ::WaitForSingleObject( m_hThread, nTimeoutToKill*1000 );
        if ( dwRes != WAIT_OBJECT_0 )
        {
            LOG(INFO) + "Terminate thread. ID: " + ::GetCurrentThreadId() + "; Result: " + dwRes;
            ::TerminateThread(m_hThread,0);
        }
        ::CloseHandle(m_hThread);
        m_hThread = null;
    }
}

int CRhoThreadImpl::wait(unsigned int nTimeout)
{
    DWORD dwRes = ::WaitForSingleObject( m_hAwakeEvent, nTimeout*1000 );
    if ( dwRes == WAIT_FAILED )
        LOG(ERROR) + "WaitForSingleObject failed. ID: " + ::GetCurrentThreadId() + "; Result: " + dwRes;

    return dwRes == WAIT_TIMEOUT ? 1 : 0;
}

void CRhoThreadImpl::stopWait()
{
    ::SetEvent(m_hAwakeEvent);
}

void CRhoThreadImpl::sleep(unsigned int nTimeout)
{
    ::Sleep(nTimeout);
}

}
}

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
rhodes-3.0.2 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.2.beta.1 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.1 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.1.beta.8 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.1.beta.7 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.1.beta.6 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.1.beta.5 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.1.beta.4 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.1.beta.3 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.1.beta.2 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.0 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.0.beta.7 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.0.beta.6 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.0.beta.5 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.0.beta.4 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.0.beta.3 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.0.beta.2 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-3.0.0.beta.1 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-2.4.1 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp
rhodes-2.4.1.beta.1 platform/wm/rhodes/rho/common/RhoThreadImpl.cpp