• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ TaskScheduler类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

int main()
{
	TaskScheduler scheduler;
	for (size_t i = 0; i < 10; i++) {

		scheduler.schedule({ TaskCategory::Standard, TaskPriority::Standard, [&scheduler, i]() {
			std::cout << "[standard] hello from standard task " << i << "!\nscheduling new task\n";
			scheduler.schedule({ TaskCategory::IO, TaskPriority::Standard, [i] {
				std::cout << "[io] hello from io task " << i << "!\n[io] sleeping...\n";
				std::this_thread::sleep_for(7s); }
			});
			std::cout << "[standard] sleeping...\n";
			std::this_thread::sleep_for(5s);
			std::cout << "[standard] Done sleeping!\n"; }
		});
	}
	scheduler.schedule({ TaskCategory::LongComputation, TaskPriority::Standard, [] {
		std::cout << "[long_comp] hello from long_comp task!\n[long_comp] sleeping...\n";
		std::this_thread::sleep_for(3s);
		std::cout << "[long_comp] Done sleeping!\n";
		} 
	});
	std::cin.get();
    return 0;
}
开发者ID:UsYer,项目名称:TaskScheduler,代码行数:25,代码来源:TaskSchedulerProgram.cpp


示例2: CoInitializeEx

void TaskScheduler::TaskingThreadFunction( const ThreadArgs& args_ )
{
	CoInitializeEx(NULL, COINIT_MULTITHREADED);
    
    uint32_t threadNum				= args_.threadNum;
	TaskScheduler*  pTS				= args_.pTaskScheduler;
    gtl_threadNum					= threadNum;
	gtl_pCurrTS						= pTS;
	pTS->m_NumThreadsRunning.fetch_add(1, std::memory_order_relaxed );
    
    uint32_t spinCount = 0;
	uint32_t hintPipeToCheck_io = threadNum + 1;	// does not need to be clamped.
    while( pTS->m_bRunning.load( std::memory_order_relaxed ) )
    {
		if( !pTS->TryRunTask( threadNum, hintPipeToCheck_io ) )
		{
			// no tasks, will spin then wait
			++spinCount;
			if( spinCount > SPIN_COUNT )
			{
				pTS->WaitForTasks<false>( threadNum );
			}
		}
		else
		{
			spinCount = 0;
		}
    }

    pTS->m_NumThreadsRunning.fetch_sub( 1, std::memory_order_relaxed );
	gtl_threadNum = NO_THREAD_NUM;
	gtl_pCurrTS   = NULL;
    return;
}
开发者ID:TheRealMJP,项目名称:DeferredTexturing,代码行数:34,代码来源:TaskScheduler.cpp


示例3: test10_testThread

OSTHREAD_FUNC test10_testThread(void *parm){
  TaskInfo *ti;
  TaskScheduler *ts = tgetTaskScheduler();
  ti = ts->createTask(test10_PROGTest, 0); assert(ti);
  ts->run();
  return (void*)-1;
}
开发者ID:mkaguilera,项目名称:yesquel,代码行数:7,代码来源:test-various.cpp


示例4: ThreadMain

DWORD WINAPI TaskScheduler::ThreadMain(VOID* thread_instance)
{
    TaskScheduler *pScheduler = reinterpret_cast<TaskScheduler*>(thread_instance);
    pScheduler->ExecuteTasks();

    return 0;
}
开发者ID:yumingsam,项目名称:OcclusionCulling,代码行数:7,代码来源:TaskScheduler.cpp


示例5: lock

void  RTSPManager::createRTSPServer(unsigned int id , unsigned int port , volatile char * watcher)
{
	std::unique_lock<std::mutex> lock(_lock);
	TaskScheduler* taskSchedular = BasicTaskScheduler::createNew();
	BasicUsageEnvironment* usageEnvironment = BasicUsageEnvironment::createNew(*taskSchedular);
	RTSPServer* rtspServer = RTSPServer::createNew(*usageEnvironment, port, NULL);

	if(rtspServer == NULL)
	{
		logger::log(usageEnvironment->getResultMsg() , logger::logType::FAILURE);
		*watcher = -1;
		this->_done = true;
		this->_condition.notify_all();
		return;
	}

		H264LiveServerMediaSession *liveSubSession = H264LiveServerMediaSession::createNew(*usageEnvironment, true , id);
		std::string streamName = "camera_" + std::to_string(id);
		ServerMediaSession* sms = ServerMediaSession::createNew(*usageEnvironment, streamName.c_str(), streamName.c_str(), "Live H264 Stream");
		sms->addSubsession(liveSubSession);
		rtspServer->addServerMediaSession(sms);
		char* url = rtspServer->rtspURL(sms);
		logger::log(INFO_RTSP_URL(url) , logger::logType::PRIORITY);
		delete[] url;

		this->_done = true;
		this->_condition.notify_all();
		lock.unlock();
		taskSchedular->doEventLoop(watcher);

		return;
}
开发者ID:Remote-Oculus-Controller,项目名称:R.O.C-SERVER,代码行数:32,代码来源:RTSPManager.cpp


示例6: assert

void TaskScheduler::TaskFunc(Task *task)
{
  assert(task->m_State == Task::State::Scheduled || task->m_State == Task::State::Runnable);
  TaskScheduler *scheduler = task->m_Scheduler;
  scheduler->m_Current = task;
  task->m_Func(*task);
  scheduler->SetState(*task, Task::State::Finished);
}
开发者ID:aaalexandrov,项目名称:Alex,代码行数:8,代码来源:TaskScheduler.cpp


示例7: signalNewFrameData

// The following code would be called to signal that a new frame of data has become available.
// This (unlike other "LIVE555 Streaming Media" library code) may be called from a separate thread.
// (Note, however, that "triggerEvent()" cannot be called with the same 'event trigger id' from different threads.
// Also, if you want to have multiple device threads, each one using a different 'event trigger id', then you will need
// to make "eventTriggerId" a non-static member variable of "DeviceSource".)
void signalNewFrameData() {
  TaskScheduler* ourScheduler = NULL; //%%% TO BE WRITTEN %%%
  DeviceSource* ourDevice  = NULL; //%%% TO BE WRITTEN %%%

  if (ourScheduler != NULL) { // sanity check
    ourScheduler->triggerEvent(DeviceSource::eventTriggerId, ourDevice);
  }
}
开发者ID:Optimus1072,项目名称:mediafoundationsamples,代码行数:13,代码来源:DeviceSource.cpp


示例8:

void * TaskScheduler::thread_func(void * arg)
{
    boost::shared_ptr<ThreadParameters> tp = *(boost::shared_ptr<ThreadParameters>*)arg;
	TaskScheduler *that = tp->that;
	pthread_cleanup_push(cleanitup,&tp);
	that->runTask(tp);
	pthread_cleanup_pop(1);
	return NULL;
}
开发者ID:BenoitLescot,项目名称:ros_task_manager,代码行数:9,代码来源:TaskScheduler.cpp


示例9: signalNewVideoFrameData

static void
signalNewVideoFrameData(int channelId) {
	TaskScheduler* ourScheduler = (TaskScheduler*) liveserver_taskscheduler(); //%%% TO BE WRITTEN %%%
	GAVideoLiveSource* ourDevice = vLiveSource[channelId]; //%%% TO BE WRITTEN %%%

	if (ourScheduler != NULL) { // sanity check
		ourScheduler->triggerEvent(eventTriggerId[channelId], ourDevice);
	}
}
开发者ID:Ljinod,项目名称:gaminganywhere,代码行数:9,代码来源:ga-videolivesource.cpp


示例10: test10_incThread

OSTHREAD_FUNC test10_incThread(void *parm){
  TaskInfo *ti;
  TaskScheduler *ts = tgetTaskScheduler();
  ti = ts->createTask(test10_PROGIncrement, 0);
  ts->assignFixedTask(1, ti);
  test10_event.set();
  ts->run();
  return (void*)-1;
}
开发者ID:mkaguilera,项目名称:yesquel,代码行数:9,代码来源:test-various.cpp


示例11: RepetitiveTask

void RepetitiveTask(Task::TaskData & parTask)
{
    TaskScheduler * scheduler = parTask.RepetetiveTaskData.Scheduler;
    TaskId taskToExec = parTask.RepetetiveTaskData.RepetiveTask;
    std::chrono::milliseconds repeatTimer = parTask.RepetetiveTaskData.RepeatTimer;

    Task * task = scheduler->GetTask(taskToExec);
    assert(task != nullptr);
    task->Run();
    scheduler->ScheduleEvery(repeatTimer, taskToExec, false);
}
开发者ID:Pamilator,项目名称:TaskScheduler,代码行数:11,代码来源:Task.cpp


示例12: FIBER_START_FUNCTION_CLASS_IMPL

FIBER_START_FUNCTION_CLASS_IMPL(TaskScheduler, FiberStart) {
	GlobalArgs *globalArgs = reinterpret_cast<GlobalArgs *>(arg);
	TaskScheduler *taskScheduler = &globalArgs->g_taskScheduler;

	while (!taskScheduler->m_quit.load()) {
		// Check if any of the waiting tasks are ready
		WaitingTask waitingTask;
		bool waitingTaskReady = false;

		taskScheduler->m_waitingTaskLock.lock();
		auto iter = taskScheduler->m_waitingTasks.begin();
		for (; iter != taskScheduler->m_waitingTasks.end(); ++iter) {
			if (iter->Counter->load() == iter->Value) {
				waitingTaskReady = true;
				break;
			}
		}
		if (waitingTaskReady) {
			waitingTask = *iter;

			// Optimization for removing an item from a vector as suggested by ryeguy on reddit
			// Explained here: http://stackoverflow.com/questions/4442477/remove-ith-item-from-c-stdvector/4442529#4442529
			// Essentially, rather than forcing a memcpy to shift all the remaining elements down after the erase,
			// we move the last element into the place where the erased element was. Then we pop off the last element

			// Check that we're not already the last item
			// Move assignment to self is not defined
			if (iter != (--taskScheduler->m_waitingTasks.end())) {
				*iter = std::move(taskScheduler->m_waitingTasks.back());
			}
			taskScheduler->m_waitingTasks.pop_back();

		}
		taskScheduler->m_waitingTaskLock.unlock();

		if (waitingTaskReady) {
			taskScheduler->SwitchFibers(waitingTask.Fiber);
		}


		TaskBundle nextTask;
		if (!taskScheduler->GetNextTask(&nextTask)) {
			std::this_thread::yield();
		} else {
			nextTask.TaskToExecute.Function(&globalArgs->g_taskScheduler, &globalArgs->g_heap, &globalArgs->g_allocator, nextTask.TaskToExecute.ArgData);
			nextTask.Counter->fetch_sub(1);
		}
	}

	FTLConvertFiberToThread(FTLGetCurrentFiber());
	globalArgs->g_taskScheduler.m_numActiveWorkerThreads.fetch_sub(1);
	FTLEndCurrentThread();
}
开发者ID:Strongc,项目名称:FiberTaskingLib,代码行数:53,代码来源:task_scheduler.cpp


示例13: setOutput

void UIWindow::setOutput()
{
    TaskScheduler tsd;
    QString qstr = textEdit->toPlainText();
    tsd.input(1,qstr.toStdString());
    string str="";
    tsd.execute();
    tsd.output(str);
    QString qst = "";
    qst=qst+str.c_str();
    output->setText(qst);
    outputLabel->setText("Output");
    repaint();
}
开发者ID:sanmayaj,项目名称:task-scheduler,代码行数:14,代码来源:UIWindow.cpp


示例14: parfor

void parfor(std::size_t idx_start,
            std::size_t idx_end,
            Lambda &&loopBody,
            TaskScheduler &scheduler,
            std::size_t blockSize = 32)
{
    static_assert(std::is_same<void, typename std::result_of<Lambda(std::size_t)>::type>::value,
                  "Loop body must return void");

    auto loopLen = (idx_end - idx_start);

    //Execute short loops in serial
    if(loopLen < 10*blockSize) {
        for(std::size_t i=idx_start; i<idx_end; ++i) {
            loopBody(i);
        }
        return;
    }

    auto full_blocks = loopLen / blockSize;
    auto cleanup_start = full_blocks * blockSize + idx_start;
    auto Nblocks = full_blocks + ((cleanup_start < idx_end) ? 1 : 0);


    std::vector<std::future<void>> futs;
    futs.reserve(Nblocks);

    for (std::size_t iblock = 0; iblock < Nblocks; ++iblock) {

        std::size_t i_start = idx_start + iblock * blockSize;
        std::size_t i_end = i_start + blockSize;
        i_end = (i_end < idx_end) ? i_end : idx_end;

        auto [task, fut] = scheduler.createTask([&loopBody, i_start, i_end]() {
            for (auto i = i_start; i < i_end; ++i) {
                loopBody(i);
            }
        });
        scheduler.enqueue(task);
        futs.push_back(std::move(fut));

    }

    wait_all(futs);
    //return futs;
}
开发者ID:tjolsen,项目名称:YAFEL,代码行数:46,代码来源:parfor.hpp


示例15: MainFiberStart

void TaskScheduler::MainFiberStart(intptr_t arg) {
	MainFiberStartArgs *mainFiberArgs = reinterpret_cast<MainFiberStartArgs *>(arg);
	TaskScheduler *taskScheduler = mainFiberArgs->taskScheduler;

	// Call the main task procedure
	mainFiberArgs->MainTask(taskScheduler, mainFiberArgs->Arg);


	// Request that all the threads quit
	taskScheduler->m_quit.store(true, std::memory_order_release);

	// Switch to the thread fibers
	ThreadLocalStorage &tls = taskScheduler->m_tls[taskScheduler->GetCurrentThreadIndex()];
	taskScheduler->m_fibers[tls.CurrentFiberIndex].SwitchToFiber(&tls.ThreadFiber);


	// We should never get here
	printf("Error: FiberStart should never return");
}
开发者ID:fmutant,项目名称:FiberTaskingLib,代码行数:19,代码来源:task_scheduler.cpp


示例16: MainThreadHook

void cPluginRestfulapi::MainThreadHook(void)
{
  // Perform actions in the context of the main program thread.
  // WARNING: Use with great care - see PLUGINS.html!
  TaskScheduler* scheduler = TaskScheduler::get();

  scheduler->DoTasks();
 
  tChannelID channelID = scheduler->SwitchableChannel();
  
  if (!( channelID == tChannelID::InvalidID )) {
     cChannel* channel = Channels.GetByChannelID(channelID);
     if (channel != NULL) {
        Channels.SwitchTo( channel->Number() );
        scheduler->SwitchableChannel(tChannelID::InvalidID);
     }
  }

  cRecording* recording = scheduler->SwitchableRecording();

  if (recording != NULL) {
     #if APIVERSNUM > 10727
     cReplayControl::SetRecording(recording->FileName());
     #else
     cReplayControl::SetRecording(recording->FileName(), recording->Title());
     #endif
     scheduler->SwitchableRecording(NULL);
     cControl::Shutdown();
     cControl::Launch(new cReplayControl);
  }
}
开发者ID:smallint,项目名称:vdr-plugin-restfulapi,代码行数:31,代码来源:restfulapi.cpp


示例17: while

  //realtime thread for handling all scheduled tasks
  void* TaskScheduler::queue_thread_callback(void* obj_p)
  {
    // if TIME_DIVISION == 1 then lock to audiodevice.
    if(UNIV::TIME_DIVISION == 1) {      
      TaskScheduler* sched = static_cast<TaskScheduler*>(obj_p);					
      EXTMonitor* guard = sched->getGuard();
      while(true) {
#ifdef EXT_BOOST
        sched->timeSlice();		
        guard->wait();
#else
        sched->timeSlice();
        guard->lock();
        guard->wait();
        guard->unlock();
#endif
      }
      return obj_p;
    }else{ // otherwise if TIME_DIVISION > 1 then timeSlice never returns!
      TaskScheduler* sched = static_cast<TaskScheduler*>(obj_p);					      
      sched->timeSlice();
      // should never return from timeSlice
      return NULL;
    }
  }
开发者ID:antoinevg,项目名称:extempore,代码行数:26,代码来源:TaskScheduler.cpp


示例18: tr

void SearchQualifierDialog::search( bool searchAll /* = false*/ ){
    QString name = AVQualifierItem::simplifyText(ui->nameEdit->text());
    QString val = AVQualifierItem::simplifyText(ui->valueEdit->text());
    if (!(name.length() < 20 && TextUtils::fits(TextUtils::QUALIFIER_NAME_CHARS, name.toLatin1().data(), name.length()))) {
        QMessageBox::critical(this, tr("Error!"), tr("Illegal qualifier name"));
        return;
    }
    if (!Annotation::isValidQualifierValue(val)) {
        QMessageBox::critical(this, tr("Error!"), tr("Illegal qualifier value"));
        return;
    }
    if(searchAll){
        clearPrevResults();
    }

    FindQualifierTaskSettings settings(groupToSearchIn, name, val, ui->exactButton->isChecked(), searchAll, parentAnnotationofPrevResult, indexOfPrevResult);


    FindQualifierTask* findTask = new FindQualifierTask(treeView, settings);
    connect(findTask, SIGNAL( si_stateChanged() ), SLOT( sl_searchTaskStateChanged() ));
    TaskScheduler* s = AppContext::getTaskScheduler();
    s->registerTopLevelTask(findTask);
}
开发者ID:m-angelov,项目名称:ugene,代码行数:23,代码来源:SearchQualifierDialog.cpp


示例19: while

void TaskScheduler::FiberStart(void *arg) {
	GlobalArgs *globalArgs = (GlobalArgs *)arg;
	TaskScheduler *taskScheduler = &globalArgs->TaskScheduler;

	while (!taskScheduler->m_quit.load()) {
		// Check if any of the waiting tasks are ready
		WaitingTask waitingTask;
		bool waitingTaskReady = false;

		EnterCriticalSection(&taskScheduler->m_waitingTaskLock);
		auto iter = taskScheduler->m_waitingTasks.begin();
		for ( ; iter != taskScheduler->m_waitingTasks.end(); ++iter) {
			if (iter->Counter->load() == iter->Value) {
				waitingTaskReady = true;
				break;
			}
		}
		if (waitingTaskReady) {
			waitingTask = *iter;
			taskScheduler->m_waitingTasks.erase(iter);
		}
		LeaveCriticalSection(&taskScheduler->m_waitingTaskLock);

		if (waitingTaskReady) {
			taskScheduler->SwitchFibers(waitingTask.Fiber);
		}


		TaskBundle nextTask;
		if (!taskScheduler->GetNextTask(&nextTask)) {
			SwitchToThread();
		} else {
			nextTask.Task.Function(&globalArgs->TaskScheduler, &globalArgs->Heap, &globalArgs->Allocator, nextTask.Task.ArgData);
			nextTask.Counter->fetch_sub(1);
		}
	}
}
开发者ID:galek,项目名称:FiberTaskingLib,代码行数:37,代码来源:task_scheduler.cpp


示例20: ThreadStart

THREAD_FUNC_RETURN_TYPE TaskScheduler::ThreadStart(void *arg) {
	ThreadStartArgs *threadArgs = reinterpret_cast<ThreadStartArgs *>(arg);
	TaskScheduler *taskScheduler = threadArgs->taskScheduler;
	uint index = threadArgs->threadIndex;

	// Clean up
	delete threadArgs;


	// Get a free fiber to switch to
	std::size_t freeFiberIndex = taskScheduler->GetNextFreeFiberIndex();

	// Initialize tls
	taskScheduler->m_tls[index].CurrentFiberIndex = freeFiberIndex;
	// Switch
	taskScheduler->m_tls[index].ThreadFiber.SwitchToFiber(&taskScheduler->m_fibers[freeFiberIndex]);


	// And we've returned

	// Cleanup and shutdown
	FTLEndCurrentThread();
	THREAD_FUNC_END;
}
开发者ID:fmutant,项目名称:FiberTaskingLib,代码行数:24,代码来源:task_scheduler.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ TaskSet类代码示例发布时间:2022-05-31
下一篇:
C++ TaskQueue类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap