void runReal() {
    bool debug  = false;
    bool loaded = false;
    cond::time::TimeType ttype = p->timeType();
    auto r = requests->find( p->tag() );
    cond::Session s;
    try{
      s = connectionPool.createSession( connectionString );
      p->init( s ); 
      p->reload();
      if( ttype==cond::runnumber ){
	p->get( runSel, debug );	
	boost::mutex::scoped_lock slock( my_lock );
	r->second++;
      } else if( ttype==cond::lumiid ){
	p->get( lumiSel, debug );
	boost::mutex::scoped_lock slock( my_lock );
	r->second++;
      } else if( ttype==cond::timestamp){
	p->get( tsSel, debug );
	boost::mutex my_lock;
	r->second++;
      } else {
	std::cout <<"WARNING: iov request on tag "<<p->tag()<<" (timeType="<<cond::time::timeTypeName(p->timeType())<<") has been skipped."<<std::endl;
      }
      s.close();
      //-ap:  not thread-safe!  timex.fetchInt(p->getBufferSize()); // keep track of time vs. size
    } catch ( const cond::Exception& e ){
      std::cout <<"ERROR:"<<e.what()<<std::endl;
    }
  }
Exemple #2
0
int32 event_slot_t::wait(slot_vec_t& signalled_vec, uint32 ms_timeout)
{
        signalled_vec.clear();

        smart_lock_t slock(&_cs);

        for(uint16 i=0; i<_slot_cnt; ++i)
        {
                if(_slot[i]) signalled_vec.push_back(i);
        }
        if(!signalled_vec.empty())
        {
                memset(_slot, 0, _slot_cnt);//reset slots
                return signalled_vec.size(); //only wait on demand
        }
	
	slock.unlock();

	if(!_evt.wait(ms_timeout)) //not time-out
        {
		smart_lock_t slock(&_cs);

                for(uint16 i=0; i<_slot_cnt; ++i)
                {
                        if(_slot[i]) signalled_vec.push_back(i);
                }
                memset(_slot, 0, _slot_cnt);//reset slots
		
		return signalled_vec.size();
        }
        return 0; 
}
Exemple #3
0
void CPlayerMgr::Process()
{
	if(! m_ForDelete.IsEmpty())
	{
		CSingleLock slock(&m_Mutex, true);
		POSITION pos = m_ForDelete.GetStartPosition();
		while(pos)
		{
			CPlayerTaskSocket * sk;
			m_ForDelete.GetNextAssoc(pos, sk, sk);
			TRACE("%08x delete socket\n", sk);
			delete sk;
		}

		m_ForDelete.RemoveAll();
	}

	if(m_TaskLst.IsEmpty())
		Sleep(1000);
	else
	{
		Sleep(80);

		CSingleLock slock(&m_Mutex, true);

		POSITION pos = m_TaskLst.GetStartPosition();

		// VC-linhai[2007-08-06]:warning C4189: “dwNow” : 局部变量已初始化但不引用
		//DWORD dwNow = GetTickCount();
		while(pos)
		{
			CPlayerTask * task=NULL;
			CSKey k;
			m_TaskLst.GetNextAssoc(pos, k, task);
			if(task && task->m_SockList.IsEmpty()==FALSE)
			{
				if(! task->RequestData())
				{
					m_TaskLst.RemoveKey(k);
					pos = m_TaskLst.GetStartPosition();
				}
			}

			if(task && task->m_SockList.IsEmpty() && task->m_bStarted)
			{
				if(task->m_tmEmptyTask==0)
					task->m_tmEmptyTask = time(NULL);
				else if(time(NULL) - task->m_tmEmptyTask > 12)
				{
					m_TaskLst.RemoveKey(k);
					delete task;
				}
			}
			else
			{
				if(task) task->m_tmEmptyTask = 0;
			}
		}
	}
}
Exemple #4
0
 void task_queue::push( task* item )
 {
     if( item == NULL )
         throw exception( "task_queue::push(): Cannot push a null task" );
     
     {
         scoped_lock< mutex > slock( tq_mutex );
         
         if( status == OPEN )
         {
             switch( item -> getPriority() )
             {
             case PRIVAL_HIGH:
                 data[ 0 ].push_back( item );
                 break;
             case PRIVAL_NONE:
                 data[ 1 ].push_back( item );
                 break;
             case PRIVAL_LOW:
                 data[ 2 ].push_back( item );
                 break;
             default:
                 throw exception( "task_queue::push(): Invalid priority level" );
             }
         }
         else
         {
             ff::write( bqt_out, "Warning: task_queue::push(): Queue closed, deleting pushed task\n" );
             delete item;
         }
     }
     
     tq_cond.broadcast();                                                    // Broadcast so all threads can match against mask
 }
Exemple #5
0
int main()
{
	int tid1;
	
	turnDebugOn();
	
	smutex_init(&mutex);
	
	printf("Códigos retornados:\n");
	
	printf("swait(12): %d\n", swait(12));
	printf("syield(): %d\n", syield());
	printf("slock(&mutex): %d\n", slock(&mutex));
	printf("sunlock(&mutex): %d\n", sunlock(&mutex));
	
	printf("E finalmente inicializando...\n");
	
	printf("tid1 = screate(1, f_thread, NULL);\n");
	tid1 = screate(1, f_thread, NULL);
	printf("tid1 : %d\n", tid1);
	
	swait(tid1);

	return 0;
}
 std::pair< float, float > canvas_view::getScrollPercent()
 {
     scoped_lock< mutex > slock( element_mutex );
     
     return std::pair< float, float >( ( float )scroll_offset[ 0 ] / ( float )data_dims[ 0 ],
                                       ( float )scroll_offset[ 1 ] / ( float )data_dims[ 1 ] );
 }
 void canvas_view::setScrollPercent( float x, float y )
 {
     scoped_lock< mutex > slock( element_mutex );
     
     scrollPixels( x * data_dims[ 0 ] - scroll_offset[ 0 ],
                   y * data_dims[ 1 ] - scroll_offset[ 1 ] );
 }
 void text_rsrc::draw()
 {
     scoped_lock< mutex > slock( text_mutex );
     
     if( update_tex )
         updateTexture();
     
     glColor4f( color[ 0 ], color[ 1 ], color[ 2 ], color[ 3 ] );
     {
         glBindTexture( GL_TEXTURE_2D, gl_tex );
         
         glTranslatef( tex_offset[ 0 ], tex_offset[ 1 ], 0.0f );
         
         glBegin( GL_QUADS );
         {
             glTexCoord2f( 0.0f, 0.0f );
             glVertex2f( 0.0f, 0.0f );
             
             glTexCoord2f( 0.0f, 1.0f );
             glVertex2f( 0.0f, dimensions[ 1 ] );
             
             glTexCoord2f( 1.0f, 1.0f );
             glVertex2f( dimensions[ 0 ], dimensions[ 1 ] );
             
             glTexCoord2f( 1.0f, 0.0f );
             glVertex2f( dimensions[ 0 ], 0.0f );
         }
         glEnd();
         
         glTranslatef( tex_offset[ 0 ] * -1.0f, tex_offset[ 1 ] * -1.0f, 0.0f );
         
         glBindTexture( GL_TEXTURE_2D, 0x00 );
     }
     glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
 }
Exemple #9
0
 void arrestTaskSystem()
 {
     scoped_lock< mutex > slock( arrest_mutex );
     
     arrested = true;
     arrest_continue = true;
 }
Exemple #10
0
int PlayerDataArrived(PLAYER_DATA_REQ * req, void * data, int len)
{
	if(req==NULL)
	{
		return 2;
	}
	if(!g_PlayerMgr) return 3;

	CSingleLock slock(&CPlayerMgr::m_Mutex, true);

	DWORD pos = req->pos;
	CSKey key(req->filehash);
	delete req;

	CPlayerTask * pTask = g_PlayerMgr->GetPlayerTask(key);
	if(! pTask)
		return 3;

	if(!pTask->SendData(pos, data, len))
	{
		return 4;
	}



	return 0;
}
Exemple #11
0
static Transform::shared_ptr_type getPlan(uint64_t const size, bool const forward)
{
	std::map < uint64_t, std::vector<Transform::shared_ptr_type> > & plans = forward ? forwardPlans : backwardPlans;
	libmaus2::parallel::ScopePosixMutex slock(planlock);

	if ( plans.find(size) == plans.end() )
		plans[size] = std::vector<Transform::shared_ptr_type>(0);

	std::map < uint64_t, std::vector<Transform::shared_ptr_type> >::iterator it = plans.find(size);
	assert ( it != plans.end() );

	std::vector<Transform::shared_ptr_type> & V = it->second;

	if ( ! V.size() )
	{
		// std::cerr << "allocating plan of size " << size << std::endl;
		V.push_back(Transform::shared_ptr_type(new Transform(size,forward)));
	}

	assert ( V.size() );

	Transform::shared_ptr_type T = V.back();
	V.pop_back();

	assert ( T->size == size );
	assert ( T->forward == forward );

	T->reset();

	return T;
}
			value_type get(uint64_t const i) const
			{
				if ( i >= numentries )
				{
					libmaus2::exception::LibMausException se;
					se.getStream() << "SparseGammaGapFileIndexDecoder::get() out of range: " << i << " >= " << numentries << std::endl;
					se.finish();
					throw se;
				}
			
				libmaus2::parallel::ScopeLock slock(lock);

				// check cache
				if ( cache.find(i) != cache.end() )
					return cache.find(i)->second;
				
				in.clear();
				in.seekg(-2*sizeof(uint64_t)-2*numentries*sizeof(uint64_t) + i*(2*sizeof(uint64_t)), std::ios::end);
				uint64_t const ikey = libmaus2::util::NumberSerialisation::deserialiseNumber(in);
				uint64_t const ibitoff = libmaus2::util::NumberSerialisation::deserialiseNumber(in);
				value_type const v(ikey,ibitoff);
				
				// extend cache
				cache[i] = v;
				
				return v;
			}
void ompl::tools::ParallelPlan::solveMore(base::Planner *planner, std::size_t minSolCount, std::size_t maxSolCount, const base::PlannerTerminationCondition *ptc)
{
    time::point start = time::now();
    if (planner->solve(*ptc))
    {
        double duration = time::seconds(time::now() - start);
        foundSolCountLock_.lock();
        unsigned int nrSol = ++foundSolCount_;
        foundSolCountLock_.unlock();

        if (nrSol >= maxSolCount)
            ptc->terminate();

        msg_.debug("Solution found by %s in %lf seconds", planner->getName().c_str(), duration);

        const std::vector<base::PlannerSolution> &paths = pdef_->getGoal()->getSolutions();

        boost::mutex::scoped_lock slock(phlock_);
        start = time::now();
        unsigned int attempts = 0;
        for (std::size_t i = 0 ; i < paths.size() ; ++i)
            attempts += phybrid_->recordPath(paths[i].path_, false);

        if (phybrid_->pathCount() >= minSolCount)
            phybrid_->computeHybridPath();

        duration = time::seconds(time::now() - start);
        msg_.debug("Spent %f seconds hybridizing %u solution paths (attempted %u connections between paths)", duration, (unsigned int)phybrid_->pathCount(), attempts);
    }
}
void ompl::base::CForestStateSampler::getNextSample(State *state)
{
    std::lock_guard<std::mutex> slock(statesLock_);
    space_->copyState(state, statesToSample_.back());
    space_->freeState(statesToSample_.back());
    statesToSample_.pop_back();
}
std::map<std::string, double> planning_scene_monitor::CurrentStateMonitor::getCurrentStateValues() const
{
  std::map<std::string, double> m;
  boost::mutex::scoped_lock slock(state_update_lock_);
  kstate_.getStateValues(m);
  return m;
}
Exemple #16
0
void aio_provider_t::init_hb_thd()
{
	_hb_tid = fy_gettid();

#ifdef LINUX
	signal(SIGPIPE, SIG_IGN);
#if defined(__ENABLE_EPOLL__)
#else
	if(!aio_provider_t::_s_sigio_is_hooked)
	{
		smart_lock_t slock(&aio_provider_t::_s_cs);
		if(!aio_provider_t::_s_sigio_is_hooked)
		{
			signal(SIGIO, _s_catch_sigio); //lazy hook SIGIO within process scope
			aio_provider_t::_s_sigio_is_hooked = true; 
		}	
	}
	_hb_tid=fy_gettid();
	sigaddset(&_sigset, AIO_RTS_NUM);
	//sigaddset(&_sigset, SIGIO); //it doesn't work on linux 2.6
	sigprocmask(SIG_BLOCK, &_sigset, NULL);
#endif
#elif defined(WIN32)
#endif
}
bool planning_scene_monitor::CurrentStateMonitor::haveCompleteState(const ros::Duration &age,
                                                                    std::vector<std::string> &missing_states) const
{
  bool result = true;
  const std::vector<std::string> &dof = robot_model_->getVariableNames();
  ros::Time now = ros::Time::now();
  ros::Time old = now - age;
  boost::mutex::scoped_lock slock(state_update_lock_);
  for (std::size_t i = 0 ; i < dof.size() ; ++i)
  {
    if (isPassiveDOF(dof[i]))
      continue;
    std::map<std::string, ros::Time>::const_iterator it = joint_time_.find(dof[i]);
    if (it == joint_time_.end())
    {
      ROS_DEBUG("Joint variable '%s' has never been updated", dof[i].c_str());
      missing_states.push_back(dof[i]);
      result = false;
    }
    else
      if (it->second < old)
      {
        ROS_DEBUG("Joint variable '%s' was last updated %0.3lf seconds ago (older than the allowed %0.3lf seconds)",
                  dof[i].c_str(), (now - it->second).toSec(), age.toSec());
        missing_states.push_back(dof[i]);
        result = false;
      }
  }
  return result;
}
 bool isOptimized()
 {
     std::lock_guard<std::mutex> slock(lock_);
     bool result = false;
     if (!solutions_.empty())
         result = solutions_[0].optimized_;
     return result;
 }
 bool isApproximate()
 {
     std::lock_guard<std::mutex> slock(lock_);
     bool result = false;
     if (!solutions_.empty())
         result = solutions_[0].approximate_;
     return result;
 }
			void post()
			{
				ScopeMutexLock slock(mutex);

				sigcnt += 1;
				
				pthread_cond_signal(&cond);
			}
 PathPtr getTopSolution()
 {
     std::lock_guard<std::mutex> slock(lock_);
     PathPtr copy;
     if (!solutions_.empty())
         copy = solutions_[0].path_;
     return copy;
 }
 double getDifference()
 {
     std::lock_guard<std::mutex> slock(lock_);
     double diff = -1.0;
     if (!solutions_.empty())
         diff = solutions_[0].difference_;
     return diff;
 }
Exemple #23
0
void libmaus2::math::Convolution::cleanup()
{
	#if defined(LIBMAUS2_HAVE_FFTW)
	libmaus2::parallel::ScopePosixMutex slock(planlock);
	forwardPlans.clear();
	backwardPlans.clear();
	#endif
}
 void add(const PlannerSolution &s)
 {
     std::lock_guard<std::mutex> slock(lock_);
     int index = solutions_.size();
     solutions_.push_back(s);
     solutions_.back().index_ = index;
     std::sort(solutions_.begin(), solutions_.end());
 }
cond::Session cond::ConnectionPoolWrapper::createSession( const std::string& connectionString ){
  Session s;
  {
    boost::mutex::scoped_lock slock( lock );
    s = connPool.createSession( connectionString );
  }
  return s;
}
Exemple #26
0
 void releaseTaskSystem()
 {
     scoped_lock< mutex > slock( arrest_mutex );
     
     arrested = false;
     
     arrest_condition.broadcast();
 }
void ompl::base::CForestStateSampler::clear()
{
    std::lock_guard<std::mutex> slock(statesLock_);
    for (auto & i : statesToSample_)
        space_->freeState(i);
    statesToSample_.clear();
    sampler_.reset();
}
Exemple #28
0
void CPlayerTaskSocket::OnReceive(int nErrorCode)
{
	ASSERT(g_PlayerMgr);

	char buffer[10240];
	int n=Receive(buffer, 10240);
	if(n == 0)
	{
		Close();
	}
	else if(n>0)
	{
		buffer[n] = 0;
		CStringA strHashId;
		int nRange = 0;
		if(ParseHttpReq(buffer, strHashId, nRange))
		{
			CSKey key;
			DWORD * pKey = (DWORD *)key.m_key;
			sscanf(strHashId, "%08x%08x%08x%08x", pKey, pKey+1, pKey+2, pKey+3);

			CSingleLock slock(&g_PlayerMgr->m_Mutex, true);

			CPlayerTask * pTask = g_PlayerMgr->GetPlayerTask(key);
			if(pTask)
			{
				TRACE("file size =%d\n", pTask->m_uTotalFileSize);
				//m_bRangeReq = true;
				ASSERT(m_nTotalBufferSize==0);
				pTask->AddSocket(this);
				//if(nRange > 222406523)
				//	nRange = 222406523;
				m_uCurrentPos = nRange;
				m_bSentData = true;
				if(nRange)
				{
					//if(m_uTailPos==0)
					{
						//m_uTailPos = m_uCurrentPos;
						//CStringA strHead = pTask->GetHeader(m_uTailPos);
						//SaveBuffer((void*)(const char*)strHead, strHead.GetLength());
					}
					//else
					{
					}
				}
				//else
				{
					CStringA strHead = pTask->GetHeader(nRange); 
					SaveBuffer((void*)(const char*)strHead, strHead.GetLength());
				}
			}

		}
	}

	CAsyncSocket::OnReceive(nErrorCode);
}
Exemple #29
0
void ompl::base::GoalLazySamples::goalSamplingThread()
{
    {
        /* Wait for startSampling() to finish assignment
         * samplingThread_ */
        std::lock_guard<std::mutex> slock(lock_);
    }

    if (!si_->isSetup())  // this looks racy
    {
        OMPL_DEBUG("Waiting for space information to be set up before the sampling thread can begin computation...");
        // wait for everything to be set up before performing computation
        while (!terminateSamplingThread_ && !si_->isSetup())
            std::this_thread::sleep_for(time::seconds(0.01));
    }
    unsigned int prevsa = samplingAttempts_;
    if (isSampling() && samplerFunc_)
    {
        OMPL_DEBUG("Beginning sampling thread computation");
        ScopedState<> s(si_);
        while (isSampling() && samplerFunc_(this, s.get()))
        {
            ++samplingAttempts_;
            if (si_->satisfiesBounds(s.get()) && si_->isValid(s.get()))
            {
                OMPL_DEBUG("Adding goal state");
                addStateIfDifferent(s.get(), minDist_);
            }
            else
            {
                OMPL_DEBUG("Invalid goal candidate");
            }
        }
    }
    else
        OMPL_WARN("Goal sampling thread never did any work.%s",
                  samplerFunc_ ? (si_->isSetup() ? "" : " Space information not set up.") : " No sampling function "
                                                                                            "set.");
    {
        std::lock_guard<std::mutex> slock(lock_);
        terminateSamplingThread_ = true;
    }

    OMPL_DEBUG("Stopped goal sampling thread after %u sampling attempts", samplingAttempts_ - prevsa);
}
void CWorkerThread::shutdown(void)
{
    IScopedLock slock(stop_mutex);
    Server->Log("waiting for worker...");
    run=false;
    clients_cond->notify_all();
    stop_cond->wait(&slock);
    Server->Log("done.");
}