码迷,mamicode.com
首页 > 其他好文 > 详细

第16月第10天 poco target

时间:2018-01-10 14:06:07      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:fine   get   lock   normal   href   --   std   bsp   policy   

 1.

void TCPServer::start()

{

    poco_assert (_stopped);

 

    _stopped = false;

    _thread.start(*this);

}

 

void Thread::start(Runnable& target)
{
    startImpl(target);
}

...

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))
        {
            pthread_attr_destroy(&attributes);
            throw SystemException("cannot set thread stack size");
        }
    }

    _pData->pRunnableTarget = ⌖
    if (pthread_create(&_pData->thread, &attributes, runnableEntry, this))
    {
        _pData->pRunnableTarget = 0;
        pthread_attr_destroy(&attributes);
        throw SystemException("cannot start thread");
    }
    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 = mapPrio(_pData->prio, _pData->policy);
        if (pthread_setschedparam(_pData->thread, _pData->policy, &par))
            throw SystemException("cannot set thread priority");
    }
}
...

void* ThreadImpl::runnableEntry(void* pThread)
{
    _currentThreadHolder.set(reinterpret_cast<ThreadImpl*>(pThread));

#if defined(POCO_OS_FAMILY_UNIX)
    sigset_t sset;
    sigemptyset(&sset);
    sigaddset(&sset, SIGQUIT);
    sigaddset(&sset, SIGTERM);
    sigaddset(&sset, SIGPIPE);
    pthread_sigmask(SIG_BLOCK, &sset, 0);
#endif

    ThreadImpl* pThreadImpl = reinterpret_cast<ThreadImpl*>(pThread);
    AutoPtr<ThreadData> pData = pThreadImpl->_pData;
    try
    {
        pData->pRunnableTarget->run();
    }
    catch (Exception& exc)
    {
        ErrorHandler::handle(exc);
    }
    catch (std::exception& exc)
    {
        ErrorHandler::handle(exc);
    }
    catch (...)
    {
        ErrorHandler::handle();
    }

    pData->pRunnableTarget = 0;
    pData->done.set();
    return 0;
}

 

 

https://codeload.github.com/JetMeta/ZPoco/zip/master

第16月第10天 poco target

标签:fine   get   lock   normal   href   --   std   bsp   policy   

原文地址:https://www.cnblogs.com/javastart/p/8257897.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!