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


C++ Runnable类代码示例

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


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

示例1: addProcessor

bool Worker::addProcessor(int id, Runnable *processor)
{
    bool ret = false;
    std::map<int, Runnable*> runnables;
    Runnable* current;

    std::lock_guard<std::mutex> guard(mtx);

    while (!processors.empty()){
        current = processors.top();
        processors.pop();
        runnables[current->getId()] = current;
    }

    if (runnables.count(id) == 0) {
        processor->setId(id);
        runnables[id] = processor;
        ret = true;
    }

    for (auto it : runnables){
        processors.push(it.second);
    }

    return ret;
}
开发者ID:donfanning,项目名称:liveMediaStreamer,代码行数:26,代码来源:Worker.cpp

示例2: removeProcessor

bool Worker::removeProcessor(int id)
{
    bool ret = false;
    std::map<int, Runnable*> runnables;
    Runnable* current;

    std::lock_guard<std::mutex> guard(mtx);

    while (!processors.empty()){
        current = processors.top();
        processors.pop();
        runnables[current->getId()] = current;
    }

    while (runnables.count(id) > 0) {
        runnables.erase(id);
        ret = true;
    }

    for (auto it : runnables){
        processors.push(it.second);
    }

    return ret;
}
开发者ID:donfanning,项目名称:liveMediaStreamer,代码行数:25,代码来源:Worker.cpp

示例3: execute_thread

	static void* execute_thread(void * ptr)
	{
		Runnable* runnable = static_cast<Runnable*>(ptr);
		assert(runnable);
		runnable->run();
		pthread_exit(NULL);
	}
开发者ID:francois-wellenreiter,项目名称:memkind,代码行数:7,代码来源:Thread.hpp

示例4: while

 void AsyncTaskExecutor::run()
 {
     while(_isRunning)
     {
         std::unique_lock<std::mutex> lock(_mutex);
         if(!_queue.empty())
         {
             Runnable *task = _queue.front();
             _queue.pop_front();
             if(task!=NULL)
             {
                 _isBusy = true;
                 _currentTask = task;
                 lock.unlock();
                 task->run();
                 lock.lock();
                 _currentTask = NULL;
                 if(task->toDelete())
                     delete task;
             }
         }
         else if(_isRunning)
         {
             _isBusy = false;
             _signal.wait(lock);
         }
     }
     return;
 }
开发者ID:hallahan,项目名称:OSMSpatialite,代码行数:29,代码来源:Thread.cpp

示例5: getState

//TODO: avoid void functions
void Worker::getState(Jzon::Object &workerNode)
{
    Jzon::Array pList;
    std::map<int, Runnable*> runnables;
    Runnable* current;

    {
        std::lock_guard<std::mutex> guard(mtx);

        while (!processors.empty()){
            current = processors.top();
            processors.pop();
            runnables[current->getId()] = current;
        }

        for (auto it : runnables){
            processors.push(it.second);
        }

    }

    for (auto it : runnables) {
        pList.Add(it.first);
    }

    workerNode.Add("type", utils::getWorkerTypeAsString(type));
    workerNode.Add("processors", pList);
}
开发者ID:donfanning,项目名称:liveMediaStreamer,代码行数:29,代码来源:Worker.cpp

示例6: lock

Milliseconds RunLoop::Impl::processRunnables() {
    std::lock_guard<std::recursive_mutex> lock(mtx);

    auto now = Clock::now();
    auto nextDue = TimePoint::max();

    // O(N) but in the render thread where we get tons
    // of messages, the size of the list is usually 1~2.
    for (nextRunnable = runnables.begin(); nextRunnable != runnables.end();) {
        Runnable* runnable = *(nextRunnable++);

        auto const dueTime = runnable->dueTime();
        if (dueTime <= now) {
            runnable->runTask();
        } else {
            nextDue = std::min(nextDue, dueTime);
        }
    }

    if (runnables.empty() || nextDue == TimePoint::max()) {
        return Milliseconds(-1);
    }

    auto timeout = std::chrono::duration_cast<Milliseconds>(nextDue - now);
    if (alarm) {
        alarm->invoke(&Alarm::set, timeout);
    }

    return timeout;
}
开发者ID:Mappy,项目名称:mapbox-gl-native,代码行数:30,代码来源:run_loop.cpp

示例7:

void
RunnableHandler::handleEvent( void * e)
{
    Runnable *r = reinterpret_cast< Runnable * > (e);
    r->run();
    if( d_->del_ )
    {
        delete r;
    }
}
开发者ID:mgrosso,项目名称:cplusql,代码行数:10,代码来源:RunnableHandler.cpp

示例8: pthread_setcanceltype

void *Thread_Unix::thread_main(void *data)
{
	// kill thread immediately - no cancellation point
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, nullptr);

	Runnable *runnable = (Runnable *)data;
	ThreadLocalStorage tls;
	runnable->run();
	return nullptr;
}
开发者ID:eoma,项目名称:gm-engine,代码行数:10,代码来源:thread_unix.cpp

示例9: lock

 void TaskExecutor::clearAll()
 {
     std::lock_guard<std::mutex> lock(_mutex);
     for(int i = 0; i < _queue.size(); i++)
     {
         Runnable *task = _queue[i];
         if(task && task->toDelete())
             delete task;
     }
     _queue.clear();
 }
开发者ID:hallahan,项目名称:OSMSpatialite,代码行数:11,代码来源:Thread.cpp

示例10: handleMessage

	virtual void handleMessage(const Message& message) {
		switch (message.what) {
		case 4:
		case 5: {
			Runnable* runnable = (Runnable*) message.obj;
			runnable->run();
			break;
		}
		default:
			Log::i(LOG_TAG, "Handler1::handleMessage 0x%x with ID %d by Looper 0x%x", &message, message.what, Looper::myLooper());
		}
	}
开发者ID:OrenHg,项目名称:Mindroid.ecpp,代码行数:12,代码来源:Loopers.cpp

示例11: Runnable

void test_suite::func_begin(const std::string & name)
{
	// Run test initializers
	const_it it = test_vec.find(name);
	if(it!=test_vec.end())
	{
		(*it).second->begin();
		return;
	}
	Runnable *pTest = new Runnable(name);
	test_vec.insert(pair<string,Runnable*>(name,pTest));
	none_init_vec.push_back(pTest);
	pTest->begin();
}
开发者ID:bigc2000,项目名称:tutu,代码行数:14,代码来源:st_stat.cpp

示例12: onStarted

void ThreadQueue::onStarted()
{
    Runnable* r;

    // qDebug() << "has started";

    while ((r = hasMore()) != NULL)
    {
        //qDebug() << "executing next from list" << r->name();
        QVariant result = r->run();
        emit     finished(r, result);
    }
    thread()->quit();
}
开发者ID:jaapgeurts,项目名称:photostage,代码行数:14,代码来源:threadqueue.cpp

示例13:

/**
执行任务的工作线程。
当前没有任务时,
如果当前线程数量大于最小线程数量,减少线程,
否则,执行清理程序,将线程类给释放掉
**/
void CThreadPoolExecutor::CWorker::Run()
{
	Runnable * pTask = NULL;
	while (m_bRun)
	{
		if (NULL == m_pFirstTask)
		{
			pTask = m_pThreadPool->GetTask();
		}
		else
		{
			pTask = m_pFirstTask;
			m_pFirstTask = NULL;
		}

		if (NULL == pTask)
		{
			EnterCriticalSection(&(m_pThreadPool->m_csThreadPoolLock));
			if (m_pThreadPool->GetThreadPoolSize() > m_pThreadPool->m_minThreads)
			{
				ThreadPoolItr itr = m_pThreadPool->m_ThreadPool.find(this);
				if (itr != m_pThreadPool->m_ThreadPool.end())
				{
					m_pThreadPool->m_ThreadPool.erase(itr);
					m_pThreadPool->m_TrashThread.insert(this);
				}
				m_bRun = false;
			}
			else
			{
				ThreadPoolItr itr = m_pThreadPool->m_TrashThread.begin();
				while (itr != m_pThreadPool->m_TrashThread.end())
				{
					(*itr)->Join();
					delete (*itr);
					m_pThreadPool->m_TrashThread.erase(itr);
					itr = m_pThreadPool->m_TrashThread.begin();
				}
			}
			LeaveCriticalSection(&(m_pThreadPool->m_csThreadPoolLock));
			continue;
		}
		else
		{
			pTask->Run();
			pTask = NULL;
		}
	}
}
开发者ID:tanlooger,项目名称:lootpool,代码行数:55,代码来源:ThreadPoolExecutor.cpp

示例14: switch

void ChannelService::OnSoftSignal(uint32 soft_signo, uint32 appendinfo)
{
    switch (soft_signo)
    {
        case CHANNEL_REMOVE:
        {
            //uint32 chanel_id = appendinfo;
            VerifyRemoveQueue();
            break;
        }
        case WAKEUP:
        {
            Runnable* task = NULL;
            while (m_pending_tasks.Pop(task))
            {
                if (NULL != task)
                {
                    task->Run();
                }
            }
            break;
        }
        case USER_DEFINED:
        {
            if (NULL != m_user_cb)
            {
                m_user_cb(this, appendinfo, m_user_cb_data);
            }
            break;
        }
        case CHANNEL_ASNC_IO:
        {
            ChannelAsyncIOContext ctx;
            while (m_async_io_queue.Pop(ctx))
            {
                if (NULL != ctx.cb)
                {
                    Channel* ch = GetChannel(ctx.channel_id);
                    ctx.cb(ch, ctx.data);
                }
            }
            break;
        }
        default:
        {
            break;
        }
    }
}
开发者ID:mrkeng,项目名称:ardb,代码行数:49,代码来源:channel_service.cpp

示例15: OnTaskHandleMsg

            LRESULT OnTaskHandleMsg(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
            {
                Runnable* pRunnable = (Runnable *)wParam;

                if (pRunnable)
                {
                    pRunnable->Run();

                    if (pRunnable->IsBeHosted())
                    {
                        pRunnable->Release();
                    }
                }

                return 0;
            }
开发者ID:java131313,项目名称:sparkthreadpool,代码行数:16,代码来源:sparkmsgwnd.hpp


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