void locking_thread()
    {
        Lock lock(m);

        boost::lock_guard<boost::mutex> lk(done_mutex);
        locked=lock.owns_lock();
        done=true;
        done_cond.notify_one();
    }
Exemple #2
0
    void locking_thread()
    {
        Lock lock(m,boost::defer_lock);
        lock.timed_lock(boost::posix_time::milliseconds(50));

        boost::lock_guard<boost::mutex> lk(done_mutex);
        locked=lock.owns_lock();
        done=true;
        done_cond.notify_one();
    }
Exemple #3
0
    // Add data to the queue and notify others
    void enqueue (const T& data)
    {
        // Acquire lock on the queue
        boost::unique_lock<boost::mutex> lock (m_mutex);

        // Add the data to the queue
        m_queue.push (data);

        // Notify others that data is ready
        m_cond.notify_one();
    }
    /// Callback is executed, when shared mode is selected
    /// Left and right is expressed when facing the back of the camera in horizontal orientation.
    void colorImageCallback(const sensor_msgs::ImageConstPtr& color_camera_data,
                            const sensor_msgs::CameraInfoConstPtr& color_camera_info)
    {
        {
            boost::mutex::scoped_lock lock( mutexQ_ );

            ROS_DEBUG("[fiducials] color image callback");

            if (camera_matrix_initialized_ == false)
            {
                camera_matrix_ = cv::Mat::zeros(3,3,CV_64FC1);
                camera_matrix_.at<double>(0,0) = color_camera_info->K[0];
                camera_matrix_.at<double>(0,2) = color_camera_info->K[2];
                camera_matrix_.at<double>(1,1) = color_camera_info->K[4];
                camera_matrix_.at<double>(1,2) = color_camera_info->K[5];
                camera_matrix_.at<double>(2,2) = 1;

                ROS_INFO("[fiducials] Initializing fiducial detector with camera matrix");
                if (m_pi_tag->Init(camera_matrix_, model_directory_ + model_filename_) & ipa_Utils::RET_FAILED)
                {
                    ROS_ERROR("[fiducials] Initializing fiducial detector with camera matrix [FAILED]");
                    return;
                }

                camera_matrix_initialized_ = true;
            }

            // Receive
            color_image_8U3_ = cv_bridge_0_.imgMsgToCv(color_camera_data, "bgr8");
            received_timestamp_ = color_camera_data->header.stamp;
            received_frame_id_ = color_camera_data->header.frame_id;
            cv::Mat tmp = color_image_8U3_;
            color_mat_8U3_ = tmp.clone();

            if (ros_node_mode_ == MODE_TOPIC || ros_node_mode_ == MODE_TOPIC_AND_SERVICE)
            {
                cob_object_detection_msgs::DetectionArray detection_array;
                detectFiducials(detection_array, color_mat_8U3_);

                // Publish
                detect_fiducials_pub_.publish(detection_array);

                cv_bridge::CvImage cv_ptr;
                cv_ptr.image = color_mat_8U3_;
                cv_ptr.encoding = CobFiducialsNode::color_image_encoding_;
                img2D_pub_.publish(cv_ptr.toImageMsg());
            }

            synchronizer_received_ = true;

            // Notify waiting thread
        }
        condQ_.notify_one();
    }
Exemple #5
0
    // Add data to the queue and notify others
    void Enqueue(const T& data) {
        // Acquire lock on the queue
        boost::unique_lock<boost::mutex> lock(m_mutex);

        // Add the data to the queue
        m_queue.push(data);

        // Notify others that data is ready
        m_cond.notify_one();

    } // Lock is automatically released here
Exemple #6
0
    virtual void newBlock(uint64_t height)
    {
//        std::cout << "wallet: " << wallet->mainAddress()
//                  <<", new block received, blockHeight: " << height << std::endl;
        static int bc_height = wallet->daemonBlockChainHeight();
        std::cout << height
                  << " / " << bc_height/* 0*/
                  << std::endl;
        newblock_triggered = true;
        cv_newblock.notify_one();
    }
Exemple #7
0
bool CGpio::StopHardware()
{
	if (m_thread != NULL) {
		m_stoprequested=true;
		interruptCondition.notify_one();
		m_thread->join();
	}

	m_bIsStarted=false;

	return true;
}
Exemple #8
0
void A::RunConsumer() {
    while (true) {
        boost::mutex::scoped_lock lock(mutex_);
        pushed_.wait(lock, [this]{return queue_.size()>MIN_QUEUE_WORK;});

        Record res = queue_.front();
        std::cout << "Processed: " << res.response << std::endl;
        queue_.pop_front();

        popped_.notify_one();
    }
}
Exemple #9
0
void usr_signal(int SigNo)
{
	if (SigNo == SIGINT)
	{
		g_conditionMainRun.notify_one();
	}
	
#ifndef WIN32
	if (SigNo == SIGHUP)
	{
	}
#endif
}
	void push(T const& data)
	{
		boost::mutex::scoped_lock lock(_mutex);

		while(_queue.size() >= size)
		{
			_conditionVar.wait(lock);
		}

		_queue.push(data);
		lock.unlock();
		_conditionVar.notify_one();
	}
Exemple #11
0
	void push(const TaskPtr& task) {
		if (!_running) {
			return;
		}
		boost::unique_lock<boost::mutex> lock(_mutex);
		std::cout << "push A" << std::endl;
		_tasks.push_back(task);
		if (_tasks.size() >= 1) {
			std::cout << "push B" << std::endl;
			_no_task.notify_one();
			std::cout << "push C" << std::endl;
		}
	}
Exemple #12
0
	/*
		The actual work
	*/
	virtual int do_work()
	{
		for ( Iterator it = start ; it != end ; ++it )
		{
			privateSum += abs(abs(*it) + sin((unsigned long long)(*it)) * abs(cos(*it))) + ((float)*it * (unsigned short)*it) ;
		}
		boost::mutex::scoped_lock lock(m_mutex);
		total_result += privateSum;
		returned ++;
		lock.unlock();
		cv.notify_one();
		return 0;
	}
Exemple #13
0
void A::RunProducer() {
    int i = 0;

    while (i<1000) {
        boost::mutex::scoped_lock lock(mutex_);
        popped_.wait(lock, [this] { return queue_.size()<MAX_QUEUE_WORK; });

        queue_.push_back(Record { std::to_string(i).c_str() });
        std::cout << "Added: " << std::to_string(i) << " size: " << queue_.size() << std::endl;
        i++;
        pushed_.notify_one();
    }
}
Exemple #14
0
        bool DurableImpl::commitIfNeeded(OperationContext* txn) {
            // this is safe since since conceptually if you call commitIfNeeded, we're at a valid
            // spot in an operation to be terminated.
            cc().checkpointHappened();

            if (MONGO_likely(commitJob.bytes() < UncommittedBytesLimit)) {
                return false;
            }

            // Just wake up the flush thread
            flushRequested.notify_one();
            return true;
        }
Exemple #15
0
//Must be called from secondary thread context
void Invoker::UpdateInvoker()
{
    APP_API_ASSERT(m_Created);

    boost::mutex::scoped_try_lock lock(*m_Mutex);

    while(!m_Funcs.empty())
    {
		m_Funcs.front()();
        CondVar.notify_one();
		m_Funcs.pop();
    }
}
Exemple #16
0
bool 
MapsBuffer::pushBack(boost::shared_ptr<const MapsRgb> maps_rgb )
{
  bool retVal = false;
  {
    boost::mutex::scoped_lock buff_lock (bmutex_);
    if (!buffer_.full ())
      retVal = true;
    buffer_.push_back (maps_rgb);
  }
  buff_empty_.notify_one ();
  return (retVal);
}
	__inline__ void push(value_type const& data)
	{
		//bool const was_empty=mqueue.empty();
		using namespace std;
		{ //to unlock before notification
			boost::mutex::scoped_lock lock(mmutex);
			mqueue.push(data);
		}
		//if(was_empty)
       	//{
			mcond.notify_one();
		//}
	}
bool 
PCDBuffer::pushBack (pcl::PointCloud<pcl::PointXYZRGBA>::ConstPtr cloud)
{
	bool retVal = false;
	{
		boost::mutex::scoped_lock buff_lock (bmutex_);
		if (!buffer_.full ())
			retVal = true;
		buffer_.push_back (cloud);
	}
	buff_empty_.notify_one ();
	return (retVal);
}
Exemple #19
0
        bool DurableImpl::commitNow(OperationContext* txn) {
            stats.curr->_earlyCommits++;

            NotifyAll::When when = commitJob._notify.now();

            AutoYieldFlushLockForMMAPV1Commit flushLockYield(txn->lockState());

            // There is always just one waiting anyways
            flushRequested.notify_one();
            commitJob._notify.waitFor(when);

            cc().checkpointHappened();
            return true;
        }
Exemple #20
0
static void produce()
{
    int i = 0;

    while(true)
    {
        boost::mutex::scoped_lock lock(mutex);

        messages.push(i);
        ++i;

        cond.notify_one();
    }
}
Exemple #21
0
bool CGpio::StopHardware()
{
	if (m_thread != NULL) {
		m_stoprequested=true;
		interruptCondition.notify_one();
		m_thread->join();
	}
#ifdef WITH_GPIO_U401
	u401_detach();
#endif
	m_bIsStarted=false;

	return true;
}
Exemple #22
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;
}
	void add_task( Task task )
	{
		boost::unique_lock< boost::mutex > lock ( mutex_ );

		//If no threads are available, then return.
		if( 0 == available_ ) return;

		// Decrement count, indicating thread is no longer available.
		--available_;

		// Set task and signal condition variable so that a worker thread will
		// wake up and use the task.
		tasks_.push( boost::function< void() > ( task ) );
		cv_task_.notify_one();
	}
Exemple #24
0
    bool try_pop(T& data)
    {
        boost::mutex::scoped_lock     lockHandle(mutexHandle);

        if (!queueHandle.empty()) {
            data = queueHandle.front();
            queueHandle.pop();
            condFlag.notify_one();

            return true;
        }
        else {
            return false;
        }
    }
    void Producer(int Num)
    {
        std::cout<<"生产者"<<Num<<"初始化成功!"<<std::endl;

        while(1)
        {
            {
                boost::mutex::scoped_lock lock(Middle_mu);
                Middle_var++;
                std::cout<<"生产者"<<Num<<"准备好数据!"<<std::endl;
            }
            Middle_cv.notify_one();
            boost::this_thread::sleep(boost::posix_time::seconds(1));
        }
    }
	void push(T* data) {
		boost::mutex::scoped_lock lock(_mutex);
		if (_queue.size() >= size) {
			T* pDataToDelete = _queue.front().data;
			_queue.pop();
			if(pDataToDelete)
			{
				delete pDataToDelete;
			}
		}
		Element e = { getCurrentTimeMs(), data };
		_queue.push(e);
		lock.unlock();
		_conditionVar.notify_one();
	}
Exemple #27
0
//Must be called from secondary thread context
void Invoker::UpdateInvoker()
{
    //APP_API_ASSERT(m_Created);

    if (m_Created)
    {
        boost::lock_guard<boost::mutex> lock(*m_Mutex);

        while(!m_Funcs.empty())
        {
            m_Funcs.front()();
            CondVar.notify_one();
            m_Funcs.pop();
        }
    }
}
	T pop()
	{
		boost::mutex::scoped_lock lock(_mutex);

		while(_queue.empty())
		{
			_conditionVar.wait(lock);
		}

		T result =_queue.front();
		_queue.pop();

		lock.unlock();
		_conditionVar.notify_one();

		return result;
	}
Exemple #29
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 task(int operation, int key, int value, int* work_counter)
{

	if (operation == 0){
		storage->insert(key, value);
	}
	else {
		storage->get(key);
	}


    {
        boost::lock_guard<boost::mutex> lk(m);
        ++*work_counter;
    }
    cv.notify_one();
}