Exemple #1
0
  // Destructor : stop the brackground thread first !
  inline ~pyPTAM() {
    if (is_slam_started) {
      s->Stop();
      is_slam_started = false;
    }

    sys_thread->join();
  }
Exemple #2
0
 virtual ~Log()
 {
     _isStopping = true;
     _threadPool.interrupt_all();
     _threadPool.join_all();
     _stringLoggerThread.interrupt();
     _stringLoggerThread.join();
 }
    //! デバイスを開く
    //! 開くデバイスの指定は、現在WAVE_MAPPER固定。
    //! 簡単のため例外安全性などはあまり考慮されていない点に注意。
	bool OpenDevice(size_t sampling_rate, size_t channel, size_t block_size, size_t multiplicity, callback_function_t callback)
	{
		BOOST_ASSERT(0 < block_size);
		BOOST_ASSERT(0 < multiplicity);
		BOOST_ASSERT(0 < channel && channel <= 2);
		BOOST_ASSERT(callback);
		BOOST_ASSERT(!process_thread_.joinable());

		block_size_ = block_size;
		channel_ = channel;
		callback_ = callback;
		multiplicity_ = multiplicity;

        //! デバイスがオープン完了するまでcallbackが呼ばれないようにするためのロック
		boost::unique_lock<boost::mutex> lock(initial_lock_mutex_);

		terminated_ = false;
		process_thread_ = boost::thread([this] { ProcessThread(); });

		WAVEFORMATEX wf;
		wf.wFormatTag = WAVE_FORMAT_PCM;
		wf.nChannels = 2;
		wf.wBitsPerSample = 16;
		wf.nBlockAlign = wf.nChannels * (wf.wBitsPerSample / 8);
		wf.nSamplesPerSec = sampling_rate;
		wf.nAvgBytesPerSec = wf.nBlockAlign * wf.nSamplesPerSec;
		wf.cbSize = sizeof(WAVEFORMATEX);

		headers_.resize(multiplicity_);
		for(auto &header: headers_) {
			header.reset(new WaveHeader(block_size * channel * sizeof(short)));
		}

        //! WAVEHDR使用済み通知を受け取る方式として
        //! CALLBACK_FUNCTIONを指定。
        //! 正常にデバイスがオープンできると、
        //! waveOutWriteを呼び出した後でWaveOutProcessor::waveOutProcに通知が来るようになる。
		MMRESULT const result = 
			waveOutOpen(
				&hwo_, 
				0, 
				&wf, 
				reinterpret_cast<DWORD>(&WaveOutProcessor::waveOutProc), 
				reinterpret_cast<DWORD_PTR>(this),
				CALLBACK_FUNCTION
				);

		if(result != MMSYSERR_NOERROR) {
			terminated_ = true;
			process_thread_.join();
			terminated_ = false;
            hwo_ = NULL;

			return false;
		}

		return true;
	}
Exemple #4
0
  virtual void shutdown(ExecutorDriver* driver) {
  	driver->sendFrameworkMessage("Executor " + host_name+ "SHUTTING DOWN");
                  if (thread) {
                    thread->interrupt();
                    thread->join();
                    delete thread;
                    thread = 0;
                  }
	driver->stop();
  }
Exemple #5
0
  virtual void killTask(ExecutorDriver* driver, const TaskID& taskId) {
                  if (thread) {
                    thread->interrupt();
                    thread->join();
                    delete thread;
                    thread = 0;
                  }
	  	  driver->sendFrameworkMessage("Executor " + host_name+ " KILLING TASK");
		  driver->stop();
}
Exemple #6
0
/**
 * Disables the timer sub-system.
 */
void Timer::Uninitialize(void)
{
	{
		boost::mutex::scoped_lock lock(l_Mutex);
		l_StopThread = true;
		l_CV.notify_all();
	}

	l_Thread.join();
}
Exemple #7
0
 ~AsyncCRC32()
 {
   mutex.lock();
   finished = true;
   mutex.unlock();
   
   readCond.notify_one();
   thread.join();
   for (auto buf : queue) delete buf;
 }
Exemple #8
0
/**
 * Disables the timer sub-system.
 */
void Timer::Uninitialize(void)
{
	{
		boost::mutex::scoped_lock lock(l_TimerMutex);
		l_StopTimerThread = true;
		l_TimerCV.notify_all();
	}

	if (l_TimerThread.joinable())
		l_TimerThread.join();
}
void LoopbackControllerManager::fini()
{
  ROS_DEBUG("calling LoopbackControllerManager::fini");

  //pr2_hardware_interface::ActuatorMap::const_iterator it;
  //for (it = hw_.actuators_.begin(); it != hw_.actuators_.end(); ++it)
  //  delete it->second; // why is this causing double free corrpution?
  cm_->~ControllerManager();
  rosnode_->shutdown();

  ros_spinner_thread_->join();
}
void shutdown()
{
  boost::recursive_mutex::scoped_lock lock(g_shutting_down_mutex);
  // gracefully return if we've not fired ros up yet, or mid-shutdown
  if (g_shutting_down || !g_initialized)
  {
    return;
  }

  ROSCPP_LOG_DEBUG("Shutting down roscpp");

  g_shutting_down = true;

  g_global_queue->disable();
  g_global_queue->clear();

  if (g_internal_queue_thread.get_id() != boost::this_thread::get_id())
  {
    g_internal_queue_thread.join();
  }

  const log4cxx::LoggerPtr& logger = log4cxx::Logger::getLogger(ROSCONSOLE_ROOT_LOGGER_NAME);
  logger->removeAppender(g_rosout_appender);
  g_rosout_appender = 0;

  // reset this so that the logger doesn't get crashily destroyed
  // again during global destruction.  
  //
  // See https://code.ros.org/trac/ros/ticket/3271
  //
  log4cxx::Logger::getRootLogger()->getLoggerRepository()->shutdown();
  log4cxx::LoggerPtr& fo_logger = ros::file_log::getFileOnlyLogger();
  fo_logger = log4cxx::LoggerPtr();
  
  if (g_started)
  {
    TopicManager::instance()->shutdown();
    ServiceManager::instance()->shutdown();
    PollManager::instance()->shutdown();
    ConnectionManager::instance()->shutdown();
    XMLRPCManager::instance()->shutdown();
  }

  WallTime end = WallTime::now();

  ROSCPP_LOG_DEBUG("Shutdown finished");

  g_started = false;
  g_ok = false;
  Time::shutdown();
}
Exemple #11
0
int Worker::Stop()
{
    // lock nothing coz care nothing ...

    if(m_state <= 0) return m_state;
    m_state = 0;

    m_condition.notify_one(); // just send out a signal

    if(m_thread) m_thread->join(); // and wait for end

    m_state = -1;
    return m_state;
}
Exemple #12
0
inline threadTest::~threadTest()
{
  _glInit = false;

  _glThread.interrupt();
  std::cout << "Interrupting main thread" << std::endl;
  fflush(stdout);

  _glThread.join();
  std::cout << "Joinning main thread" << std::endl;
  fflush(stdout);

  printTest();
  std::cout << "Main thread destroyed" << std::endl;
  fflush(stdout);
};
Exemple #13
0
int WorkManagerImpl::StopDispaching()
{
    // lock nothing coz care nothing ...

    if(m_state <= 0) return m_state;
    m_state = 0;

    m_workreq = 1;

    m_condition.notify_one(); // just send out a signal

    if(m_dispatcherthread) m_dispatcherthread->join(); // and wait for end

    m_state = -1;
    return m_state;

}
void finishProcess() {
	while (mode == WAITING) {
		boost::this_thread::sleep(boost::posix_time::seconds(1));
	}

	ROS_INFO("Finished");

	if (mode == SLAM)
		killMapping();

	if (mode == LOCALIZATION)
		killLocalization();

	if (mode == OUTDOOR)
		killOutdoorMode();

	mappingProcessThread.join();
}
Exemple #15
0
 void join() {
     //terminated = true;
     m_Thread.join();
     std::cout << "[DIS] Thread Terminated\n";
     media->messageQueue->terminated = true;
 }
				void check_connection()
				{
					thread_.join();
					BOOST_CHECK_EQUAL( socket_.is_open(), true );
				}
Exemple #17
0
	// --------------------------------------------------------------
	/// Blocks the calling thread until this object's thread has completed.
	/// If this object's thread has already completed, or if this
	/// object represents Not-a-Thread, then this method returns immediately.
	virtual void join() {
		_thread.join();
	}
Exemple #18
0
  virtual void launchTask(ExecutorDriver* driver, const TaskInfo& task)    {
	localPeerCount++;

    TaskStatus status;
    status.mutable_task_id()->MergeFrom(task.task_id());
    status.set_state(TASK_RUNNING);
    driver->sendStatusUpdate(status);

    //-------------  START TASK OPERATIONS ----------
	cout << "Running K3 Program: " << task.name() << endl;
	string k3_cmd;

	using namespace YAML;

	Node hostParams = Load(task.data());
	Node peerParams;
	Node peers;
//	vector<Node> peers;

	cout << "WHAT I RECEIVED\n----------------------\n";
	cout << Dump(hostParams);
	cout << "\n---------------------------------\n";

	k3_cmd = "cd $MESOS_SANDBOX && bash -c 'ulimit -c unlimited && ./" + hostParams["binary"].as<string>();
	if (hostParams["logging"]) {
		k3_cmd += " -l INFO ";
	}
        if (hostParams["resultVar"]) {
          k3_cmd += " --result_path $MESOS_SANDBOX --result_var " + hostParams["resultVar"].as<string>();
        }


	string datavar, datapath;
	string datapolicy = "default";
	int peerStart = 0;
	int peerEnd = 0;

	for (const_iterator param=hostParams.begin(); param!=hostParams.end(); param++)  {
		string key = param->first.as<string>();
//		cout << " PROCESSING: " << key << endl;
		if (key == "logging" || key == "binary" ||
			key == "server" || key == "server_group") {
			continue;
		}
		if (key == "roles") {
		  continue;
		}

		else if (key == "peers") {
			peerParams["peers"] = hostParams["peers"];
		}
		else if (key == "me") {
			Node meList = param->second;
			YAML::Emitter emit;
			emit << YAML::Flow << meList;
			for (std::size_t i=0; i<meList.size(); i++)  {
				peers.push_back(meList[i]);
			}
		}
		else if (key == "data") {
		        // TODO: Datafiles per group. This is a hack
		        // that only includes the data files from the first peer group
		        // and assigns them to any peer
		        Node dataFilesNode = param->second[0];
			for(YAML::const_iterator it=dataFilesNode.begin();it!=dataFilesNode.end();++it) {
                          DataFile f;
                          auto d = *it;
			  f.path = d["path"].as<string>();
			  f.varName = d["var"].as<string>();
			  f.policy = d["policy"].as<string>();
			  dataFiles.push_back(f);
			}

		}

		//else if (key == "datavar") {
		//	datavar = param->second.as<string>();
		//}
		//else if (key == "datapath") {
		//	datapath = "{path: " + param->second.as<string>() + "}";
		//}
		//else if (key == "datapolicy") {
		//	datapolicy = param->second.as<string>();
		//}
		else if (key == "totalPeers")  {
			totalPeerCount = param->second.as<int>();
		}
		else if (key == "peerStart") {
			peerStart = param->second.as<int>();
		}
		else if (key == "peerEnd") {
			peerEnd = param->second.as<int>();
		}
		else if (key == "globals") {
		  // handled per peer

		}
		else {
//			string value = i->second.as<string>();
			//peerParams[key] = param->second;
		}
	}

	// DATA ALLOCATION *
		// TODO: Convert to multiple input dirs
	map<string, vector<string> > peerFiles[peers.size()];

        for (auto dataFile : dataFiles) {
                cout << "Top of loop" << endl;
	        vector<string> filePaths;

		// 1. GET DIR LIST IN datavar
		DIR *datadir = NULL;
		datadir = opendir(dataFile.path.c_str());
                if (!datadir) {
                  cout << "Failed to open data dir: " << dataFile.path << endl;
                  TaskStatus status;
                  status.mutable_task_id()->MergeFrom(task.task_id());
                  status.set_state(TASK_FAILED);
                  driver->sendStatusUpdate(status);
                  return;

                }
		else {
			cout << "Opened data dir: " << dataFile.path << endl;

		}
		struct dirent *srcfile = NULL;

		while (true) {
			srcfile = readdir(datadir);
			if (srcfile == NULL) {
				break;
			}
			cout << "FILE  " << srcfile->d_name << ":  ";
			if (srcfile->d_type == DT_REG) {
				string filename = srcfile->d_name;
			        filePaths.push_back(dataFile.path + "/" + filename);
				cout << "Added -> " << filename;
			}
			cout << endl;
		}
		closedir(datadir);
                cout << "read directory" << endl;

		int numfiles = filePaths.size();

		sort (filePaths.begin(), filePaths.end());


		int p_start = 0;
		int p_end = numfiles;

		int p_total = peers.size();
		int myfiles = 0;
		if (dataFile.policy == "global") {
		  for (int i = 0; i < numfiles; i++) {
	            int peer = i % totalPeerCount;

		    if (peer >= peerStart && peer <= peerEnd) {
		      myfiles++;
		      peerFiles[peer-peerStart][dataFile.varName].push_back(filePaths[i]);
		    }

		  }

		}
		else if (dataFile.policy == "replicate") {
		  for (int p = 0; p < peers.size(); p++) {
	            for (int i =0; i < numfiles; i++) {
		      myfiles++;
                      peerFiles[p][dataFile.varName].push_back(filePaths[i]);
	            }
		  }
		}

		//if (dataFile.policy == "global") {
		//	p_start = (numfiles / totalPeerCount) * peerStart;
		//	p_end = (numfiles / totalPeerCount) * (peerEnd+1);
		//	p_total = totalPeerCount;
		//	cout << ("Global files s=" + stringify(p_start) + " e=" + stringify(p_end) + " t=" + stringify(p_total)) << endl;
		//        for (int filenum = p_start; filenum < p_end; filenum++) {
		//        	int peer = floor((((p_total)*1.0*filenum) / numfiles)) - peerStart;
		//        	cout << "  Peer # " << peer << " : [" << filenum << "] " << filePaths[filenum] << endl;
		//        	peerFiles[peer][dataFile.varName].push_back(filePaths[filenum]);
		//		myfiles++;
		//        }
		//}
                else if (dataFile.policy == "pinned") {
                  for(int filenum = 0; filenum < numfiles; filenum++) {
	            peerFiles[0][dataFile.varName].push_back(filePaths[filenum]);
		  }

                }
		else if (dataFile.policy == "sharded") {
	          for (int i =0; i < numfiles; i++) {
		    myfiles++;
		    int p = i % peers.size();
                    peerFiles[p][dataFile.varName].push_back(filePaths[i]);
	          }
		}

                cout << "my files: " << myfiles << endl;

	}

	cout << "BUILDING PARAMS FOR PEERS" << endl;
	int pph = 0;
	if (peerParams["peers"].size() >= 1) {
	  YAML::Node peer_masters;
	  YAML::Node masters;
	  YAML::Node curMaster = YAML::Load(YAML::Dump(peerParams["peers"][0]));
	  masters.push_back(YAML::Load(YAML::Dump(curMaster)));
	  std::cout << peerParams["peers"].size() << " peers to map" << endl;
	  for (std::size_t i=0; i< peerParams["peers"].size(); i++) {
	    YAML::Node kv;
	    if (peerParams["peers"][i]["addr"][0].as<string>() != curMaster["addr"][0].as<string>()) {
	      cout << "Host: " << curMaster["addr"][0].as<string>() << ". Peers: " << pph << endl;
	      pph = 0;
	      masters.push_back(YAML::Load(YAML::Dump(peerParams["peers"][i])));
              curMaster = YAML::Load(YAML::Dump(peerParams["peers"][i]));
	    }
	    pph++;
	    std::cout << "added one" << endl;
	    kv["key"] = YAML::Load(YAML::Dump(peerParams["peers"][i]["addr"]));
	    kv["value"] = YAML::Load(YAML::Dump(curMaster["addr"]));
	    peer_masters.push_back(kv);
	  }
	  cout << "Host: " << curMaster["addr"][0].as<string>() << ". Peers: " << pph << endl;

	  peerParams["peer_masters"] = YAML::Load(YAML::Dump(peer_masters));
	  peerParams["masters"] = YAML::Load(YAML::Dump(masters));
          std::cout << "Masters: " << YAML::Dump(masters) << endl;
	}


        std::ostringstream oss;
	oss << "PEERS!!! (" << std::endl;
	for (std::size_t i=0; i<peers.size(); i++)  {
		oss << "---" << std::endl;
		YAML::Node thispeer = peerParams;
		YAML::Node globals = hostParams["globals"][i];
	        for (const_iterator p=globals.begin(); p!=globals.end(); p++)  {
	          thispeer[p->first.as<string>()] = p->second;
	        }
		YAML::Node me = peers[i];
		thispeer["me"] = me;
		YAML::Node local_peers;
		std::cout << "start: " << peerStart << ". end: " << peerEnd << std::endl;
		for (int j=peerStart; j<= peerEnd; j++) {
                  local_peers.push_back(YAML::Load(YAML::Dump(peerParams["peers"][j])));
		}

		thispeer["local_peers"] = YAML::Load(YAML::Dump(local_peers));

		for (auto it : peerFiles[i])  {
			auto datavar = it.first;
                        if (thispeer[datavar]) {
                          thispeer.remove(datavar);
                        }
			for (auto &f : it.second) {
				Node src;
				src["path"] = f;
				thispeer[datavar].push_back(src);
			}
		}
		// ADD DATA SOURCE DIR HERE
		YAML::Emitter emit;
		emit << YAML::Flow << thispeer;
		string param = emit.c_str();
		std::ofstream peerFile;
		string peerFileName = "/mnt/mesos/sandbox/peers" + std::to_string(i) + ".yaml";
		peerFile.open(peerFileName, std::ofstream::out);
		peerFile << param;
		peerFile.close();
		oss << param << std::endl;
		std::cout << param << std::endl;
		k3_cmd += " -p " + peerFileName;
		for (auto it : peerFiles[i])  {
			auto datavar = it.first;
                        if (thispeer[datavar]) {
                          thispeer.remove(datavar);
                        }
                }
	}
	oss << ") END PEERS!!!" << std::endl;
	cout << oss.str() << std::endl;

	k3_cmd += "'";
	cout << "FINAL COMMAND: " << k3_cmd << endl;
        if (thread) {
	  driver->sendFrameworkMessage("Debug: thread already existed!");
          thread->interrupt();
          thread->join();
          delete thread;
          thread = 0;
        }

        bool isMaster = false;
        cout << "Checking master" << endl;
        if (Dump(hostParams["me"][0]) == Dump(hostParams["master"])) {
		isMaster = true;
                cout << "I am master" << endl;
	}
        else {
          cout << "me: " << Dump(hostParams["me"][0]) << endl;
          cout << "master: " << Dump(hostParams["master"]) << endl;
        }
        cout << "Launching K3: " << endl;
        thread = new boost::thread(TaskThread(task, k3_cmd, driver, isMaster));
  }
 ~UEyeNodelet() {
     stop = true;
     node_thread.join();
 }
Exemple #20
0
void stopBTTrackers()
{
    g_IOService.stop();
    g_Thread.join();
}
Exemple #21
0
 void join() {
     terminated = true;
     m_Thread.join();
     std::cout << "[DEC] Thread Terminated\n";
 }
Exemple #22
0
 ~throws_in_bg() {
     serv.stop();
     runthread.join();
 }
 // DESTRUCTOR
 ~Nao_control() {
   stop_thread = true;
   sleep(1);
   spin_thread->join();
 }
Exemple #24
0
    ~timer_queue_t() {
	watchdog.interrupt();
	watchdog.join();
    }
Exemple #25
0
 inline void join(void) { thread->join(); }
Exemple #26
0
	~impl()
	{		
		thread_.join();
	}
	~impl()
	{
		work_.reset();
		service_.stop();
		thread_.join();
	}
	~filesystem_service()
	{
		worker_service_.stop();
		worker_thread_.join();
	}
Exemple #29
0
void Worker::join(){
  wthread.join();
}
 void join(){///Join thread
     m_Thread.join();
     UpdateStats(new string("Thread has been doing something for: "+ Conv::TimeToString(Time::TimeDiff(*blt_ldt_Start))));
 }