本文整理汇总了C++中slock函数的典型用法代码示例。如果您正苦于以下问题:C++ slock函数的具体用法?C++ slock怎么用?C++ slock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runReal
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;
}
}
示例2: slock
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;
}
示例3: slock
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;
}
}
}
}
示例4: exception
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
}
示例5: main
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;
}
示例6: slock
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 ] );
}
示例7: slock
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 );
}
示例8: arrestTaskSystem
void arrestTaskSystem()
{
scoped_lock< mutex > slock( arrest_mutex );
arrested = true;
arrest_continue = true;
}
示例9: PlayerDataArrived
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;
}
示例10: getPlan
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;
}
示例11: get
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;
}
示例12: slock
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);
}
}
示例13: slock
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();
}
示例14: slock
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;
}
示例15: fy_gettid
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
}