예제 #1
0
void SysConsoleServiceImp::lostCheckStatus(std::string& _return)
{
	LostCheckState tsk(_return);

	sysc->lcDriver->query(&tsk);
	tsk.wait(-1);
}
예제 #2
0
void BufferCont::startMappingThread(){
	

	int numTask = std::thread::hardware_concurrency();

	if (numTask>m_buffer.back().size()) numTask = m_buffer.back().size();
	
	vector<thread> thrd;
	size_t num = (m_buffer.back().size() / numTask);
	size_t i = 0;

	vector<vector<int>> tsk(numTask);
	for (auto &t : tsk)	t.reserve(num+1);

	for (; i < m_buffer.back().size(); ++i){
		int k = i / num;
		if (k == numTask) break;
		tsk[k].push_back(i);
	}
	for (size_t j = 0; i < m_buffer.back().size(); ++i, ++j){
		tsk[j].push_back(i);
	}
	for (int i = 0; i<numTask; i++){
		thrd.push_back(thread(mappingThread, ref(tsk[i]), ref(*this)));
	}
	for (auto &i : thrd) i.join();
}
예제 #3
0
   void task_pool::join()
   {
      for ( ; ; )
      {
         m_task_condition_var.lock();

         if (!m_tasks.empty())
         {
            task tsk(m_tasks.front());
            m_tasks.pop_front();

            m_task_condition_var.unlock();

            process_task(tsk);
         }
         else
         {
            int result = m_task_condition_var.wait(join_condition_func, this);
            result;
            CRNLIB_ASSERT(result >= 0);

            m_task_condition_var.unlock();

            break;
         }
      }
   }
예제 #4
0
파일: euler.cpp 프로젝트: CodeManent/euler
/******************************************************************************
 * One task/thread per solution. Results are printed by main
 * after all of them have been computed.
 */
static void paralleSolutionsSequentialResults()
{

	//Create the containers to use and preallocate the memory needed
	auto scount = getSolutions().size();
	//one thread for each solution for now
	std::vector<std::thread> threads;
	threads.reserve(scount);
	//one future for each solution
	std::vector<std::future<long>> futures;
	futures.reserve(scount);

	// Grab the futures and create a thread for each solution;
	for(const auto &s : getSolutions() ){
		// get the function pointer for the solution
		auto fp = s.second;
		// and create a future and a thread for it through a prepared_task.
		std::packaged_task<long()> tsk(fp);
		futures.emplace_back(std::move(tsk.get_future()));
		threads.emplace_back(std::move(tsk));
	}

	// wait for the threads t finish the computations.
	for(auto &t: threads)
		t.join();

	// print the computed results (and compared them to the expected ones).
	for(size_t i=0; i < getSolutions().size(); ++i){
		const auto problem = getSolutions().at(i).first;
		long result = futures[i].get();

		printResult(problem, result);
	}
}
예제 #5
0
void SysConsoleServiceImp::sessionInfo(std::string& _return, const int64_t serverId)
{
	SessionInfoTask tsk(_return);
	tsk.serverId = serverId;

	sysc->ssMgr->query(&tsk);
	tsk.wait(-1);
}
예제 #6
0
void SysConsoleServiceImp::localSyncStatus(std::string& _return)
{
	if(sysc->lsyncDrv){
		LocalSyncStat tsk(_return);
		sysc->lsyncDrv->query(&tsk);
		tsk.wait(-1);
	}else{
		_return = "LocalSync not open, are you in center node?";
	}
}
예제 #7
0
int main() {
	std::packaged_task<int( int, int )> tsk( countdown );   // Set up packaged_task in the main thread
	std::future<int> ret = tsk.get_future();                // Get future

	std::thread th( std::move( tsk ), 10, 0 );              // Spawn a thread to count down from 10 to 0
	// ...
	int value = ret.get();                                  // Wait for the task to finish and get result

	std::cout << "The countdown lasted for " << value << " seconds.\n";
	th.join();

	return 0;
}
예제 #8
0
 aio_task_ptr write(
     handle_t hFile,
     const char* buffer,
     int count,
     uint64_t offset,
     task_code callback_code,
     servicelet* owner,
     aio_handler callback,
     int hash /*= 0*/
     )
 {
     aio_task_ptr tsk(callback != nullptr  ? 
         static_cast<aio_task*>(new internal_use_only::service_aio_task(callback_code, owner, callback, hash))
         : static_cast<aio_task*>(new aio_task_empty(callback_code, hash))
         );
     write(hFile, buffer, count, offset, tsk);
     return tsk;
 }
예제 #9
0
 aio_task_ptr copy_remote_files(
     const end_point& remote,
     std::string& source_dir,
     std::vector<std::string>& files,  // empty for all
     std::string& dest_dir,
     bool overwrite,
     task_code callback_code,
     servicelet* owner,
     aio_handler callback,
     int hash /*= 0*/
     )
 {
     aio_task_ptr tsk(callback != nullptr ?
         static_cast<aio_task*>(new internal_use_only::service_aio_task(callback_code, owner, callback, hash))
         : static_cast<aio_task*>(new aio_task_empty(callback_code, hash))
         );
     copy_remote_files(remote, source_dir, files, dest_dir, overwrite, tsk);
     return tsk;
 }
예제 #10
0
void Cache::_doDownload(const std::string& url, const std::string& sTempFile, FileEntry* pFileEntry, MemoryEntry* result)
{
   std::string sTargetFilename = _basedir + sTempFile;
   downloadTask tsk(url, sTargetFilename);
   if (tsk.download())
   {
      pFileEntry->_SetFilesize((size_t)tsk.getDownloaded());
      std::string sTargetFilenameMeta = sTargetFilename + ".cache";  // _basedir + sTempFile + ".cache"; 
      std::ofstream metafile;
      metafile.open(sTargetFilenameMeta.c_str());

      CacheEntry ce;
      ce.url = url;
      ce.localfile = sTempFile;
      ce.size = pFileEntry->FileSize();
      /*const HeaderFieldDefinition& hi = tsk.GetHeaderFieldDefinitions();
      for (size_t i=0;i<hi.size();i++)
      {
         std::cout << "[" << hi[i].first << "] [" << hi[i].second << "]\n";
      }*/

      access::Class::ToXML(metafile, "CacheEntry", (void*)&ce, false); // XML without header
      
      metafile.close();
      pFileEntry->_SetReady();

      _curDiskCacheCapacity += (double)pFileEntry->FileSize() / 1024.0 / 1024.0;
      
      _doRead(result, _basedir + sTempFile);
   }
   else
   {
      pFileEntry->_SetFailed();
      result->_SetFailed();
      insertMemoryEntry(pFileEntry->LocalFile(),result);
   }
}
예제 #11
0
파일: coos.cpp 프로젝트: akouz/a_coos
// =================================
// Start scheduler - init registered tasks
// =================================
void Coos::start(void)
{
  int   res;
  void (*tsk)(void);
  update_time(); 
  for (task_no=0; task_no<task_cnt; task_no++)
  {
    if (tsk_p[task_no] != NULL)            // if task was registered
    {
      res = setjmp(main_context);
      if (res == 0)
      {
        tsk = tsk_p[task_no];
        tsk();                             // invoke task
      }
      else
      {
        task_delay[task_no] = --res;      // task returns the required delay
      }
    }  
    update_time(); 
  }
  task_no = 0;
}
예제 #12
0
   unsigned __stdcall task_pool::thread_func(void* pContext)
   {
      //set_thread_name(GetCurrentThreadId(), "taskpoolhelper");

      task_pool* pPool = static_cast<task_pool*>(pContext);

      for ( ; ; )
      {
         pPool->m_task_condition_var.lock();

         int result = pPool->m_task_condition_var.wait(wait_condition_func, pPool);

         CRNLIB_ASSERT(result >= 0);

         if ((result < 0) || (pPool->m_exit_flag))
         {
            pPool->m_task_condition_var.unlock();
            break;
         }

         if (pPool->m_tasks.empty())
            pPool->m_task_condition_var.unlock();
         else
         {
            task tsk(pPool->m_tasks.front());
            pPool->m_tasks.pop_front();

            pPool->m_task_condition_var.unlock();

            pPool->process_task(tsk);
         }
      }

      _endthreadex(0);
      return 0;
   }
예제 #13
0
파일: lazy_fork.hpp 프로젝트: viboes/async
 static typename result_of::lazy_fork<AE,F>::move_type apply(AE& , F fn ) {
     packaged_task<typename boost::result_of<F()>::type> tsk(fn);
     tsk.set_wait_callback(detail::invoke_lazy_task<typename boost::result_of<F()>::type>());
     return boost::move(tsk);
 }