示例#1
0
void ThreadImpl::startImpl(Callable target, void* pData)
{
    if (_pData->pCallbackTarget && _pData->pCallbackTarget->callback)
        throw SystemException("thread already running");

    pthread_attr_t attributes;
    pthread_attr_init(&attributes);

    if (_pData->stackSize != 0)
    {
        if (0 != pthread_attr_setstacksize(&attributes, _pData->stackSize))
            throw SystemException("can not set thread stack size");
    }

    if (0 == _pData->pCallbackTarget.get())
        _pData->pCallbackTarget = new CallbackData;

    _pData->pCallbackTarget->callback = target;
    _pData->pCallbackTarget->pData = pData;

    if (pthread_create(&_pData->thread, &attributes, callableEntry, this))
    {
        _pData->pCallbackTarget->callback = 0;
        _pData->pCallbackTarget->pData = 0;
        throw SystemException("cannot start thread");
    }

    if (_pData->prio != PRIO_NORMAL_IMPL)
    {
        struct sched_param par;
        par.sched_priority = mapPrio(_pData->prio);
        if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
            throw SystemException("cannot set thread priority");
    }
}
示例#2
0
void ThreadImpl::startImpl(Runnable& target)
{
    if (_pData->pRunnableTarget)
        throw SystemException("thread already running");

    pthread_attr_t attributes;
    pthread_attr_init(&attributes);

    if (_pData->stackSize != 0)
    {
        if (0 != pthread_attr_setstacksize(&attributes, _pData->stackSize))
            throw SystemException("cannot set thread stack size");
    }

    _pData->pRunnableTarget = ⌖
    if (pthread_create(&_pData->thread, &attributes, runnableEntry, this))
    {
        _pData->pRunnableTarget = 0;
        throw SystemException("cannot start thread");
    }

    if (_pData->prio != PRIO_NORMAL_IMPL)
    {
        struct sched_param par;
        par.sched_priority = mapPrio(_pData->prio);
        if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
            throw SystemException("cannot set thread priority");
    }
}
示例#3
0
void ThreadImpl::setPriorityImpl(int prio) {
    if (prio != _pData->prio) {
        _pData->prio = prio;
        _pData->policy = SCHED_OTHER;
        if (isRunningImpl()) {
            struct sched_param par;
            par.sched_priority = mapPrio(_pData->prio, SCHED_OTHER);
            if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
                throw SystemException("cannot set thread priority");
        }
    }
}
示例#4
0
void Core_ThreadImpl::setPriorityImpl(Int32 prio)
{
	if (prio != m_pData->prio)
	{
		m_pData->prio = prio;
		if (m_pData->pTarget)
		{
			struct sched_param par;
			par.sched_priority = mapPrio(m_pData->prio);
			pthread_setschedparam(m_pData->thread, SCHED_OTHER, &par);
		}
	}
}
示例#5
0
void ThreadImpl::setPriorityImpl(int prio)
{
    if (prio != _pData->prio)
    {
        _pData->prio   = prio;
        _pData->osPrio = mapPrio(_pData->prio);
        if (isRunningImpl())
        {
            if (taskPrioritySet(_pData->task, _pData->osPrio) != OK)
                throw SystemException("cannot set task priority");
        }
    }
}
示例#6
0
void ThreadImpl::startImpl(SharedPtr<Runnable> pTarget)
{
	if (_pData->pRunnableTarget)
		throw SystemException("thread already running");

	pthread_attr_t attributes;
	pthread_attr_init(&attributes);

	if (_pData->stackSize != 0)
	{
		if (0 != pthread_attr_setstacksize(&attributes, _pData->stackSize))
		{
			pthread_attr_destroy(&attributes);
			throw SystemException("cannot set thread stack size");
		}
	}

	_pData->pRunnableTarget = pTarget;
	if (pthread_create(&_pData->thread, &attributes, runnableEntry, this))
	{
		_pData->pRunnableTarget = 0;
		pthread_attr_destroy(&attributes);
		throw SystemException("cannot start thread");
	}
	_pData->started = true;
	pthread_attr_destroy(&attributes);

	if (_pData->policy == SCHED_OTHER)
	{
		if (_pData->prio != PRIO_NORMAL_IMPL)
		{
			struct sched_param par;
			par.sched_priority = mapPrio(_pData->prio, SCHED_OTHER);
			if (pthread_setschedparam(_pData->thread, SCHED_OTHER, &par))
				throw SystemException("cannot set thread priority");
		}
	}
	else
	{
		struct sched_param par;
		par.sched_priority = _pData->osPrio;
		if (pthread_setschedparam(_pData->thread, _pData->policy, &par))
			throw SystemException("cannot set thread priority");
	}
}
示例#7
0
void Core_ThreadImpl::startImpl(Runnable& target)
{
	if (m_pData->pTarget) 
	{
		return;
	}

	m_pData->pTarget = &target;
	m_pData->isRun=true;
	pthread_create(&m_pData->thread, NULL, entry, this);

	if (m_pData->prio != PRIO_NORMAL_IMPL)
	{
		struct sched_param par;
		par.sched_priority = mapPrio(m_pData->prio);
		pthread_setschedparam(m_pData->thread, SCHED_OTHER, &par);
	}
}