本文整理汇总了C++中openthreads::Mutex::lock方法的典型用法代码示例。如果您正苦于以下问题:C++ Mutex::lock方法的具体用法?C++ Mutex::lock怎么用?C++ Mutex::lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openthreads::Mutex
的用法示例。
在下文中一共展示了Mutex::lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetData
/* try to get video frame data in ARGB format, restore GXA state */
bool CScreenShot::GetData()
{
static OpenThreads::Mutex mutex;
bool res = false;
mutex.lock();
#ifdef USE_NEVIS_GXA
CFrameBuffer::getInstance()->setActive(false);
#endif
if (videoDecoder->getBlank())
get_video = false;
#if !HAVE_GENERIC_HARDWARE
res = videoDecoder->GetScreenImage(pixel_data, xres, yres, get_video, get_osd, scale_to_video);
#endif
#ifdef USE_NEVIS_GXA
/* sort of hack. GXA used to transfer/convert live image to RGB,
* so setup GXA back */
CFrameBuffer::getInstance()->setupGXA();
//CFrameBuffer::getInstance()->add_gxa_sync_marker();
CFrameBuffer::getInstance()->setActive(true);
#endif
mutex.unlock();
if (!res) {
printf("CScreenShot::Start: GetScreenImage failed\n");
return false;
}
printf("CScreenShot::GetData: data: %p %d x %d\n", pixel_data, xres, yres);
return true;
}
示例2: run
void SendThread::run()
{
#ifdef __linux__
prctl(PR_SET_NAME, "RRServer send", 0, 0, 0);
#endif
for (;;)
{
m_mutexData.lock();
m_condData.wait(&m_mutexData);
if (m_rrdpy && m_b)
{
try
{
m_rrdpy->sendframe(m_b);
m_rrdpy = NULL;
m_b = NULL;
}
catch (...)
{
fprintf(stderr, "send failed, client disconnectd?\n");
}
}
else
{
// finish thread
m_mutexData.unlock();
return;
}
m_mutexData.unlock();
}
}
示例3: getHeightAboveMSL
double ossimDtedElevationDatabase::getHeightAboveMSL(const ossimGpt& gpt)
{
if(!isSourceEnabled())
return ossim::nan();
double result = ossim::nan();
m_mutex.lock();
if(m_lastHandler.valid() && m_lastHandler->pointHasCoverage(gpt))
{
result = m_lastHandler->getHeightAboveMSL(gpt);
}
else
{
m_lastHandler = getOrCreateCellHandler(gpt);
if(m_lastHandler.valid())
result = m_lastHandler->getHeightAboveMSL(gpt);
}
#if 0
d_mutex.lock();
cout << "THREAD ID: "<<OpenThreads::Thread::CurrentThread()->getThreadId()<<" "
<<"ossimDtedElevationDatabase @ "<<(unsigned long)this<<" m_lastHandler @ "
<<(unsigned long)m_lastHandler.get()<<endl; //### TODO: for debug, remove
d_mutex.unlock();
#endif
m_mutex.unlock();
return result;
}
示例4: stop
void SendThread::stop()
{
m_mutexData.lock();
m_rrdpy = NULL;
m_b = NULL;
m_condData.signal();
m_mutexData.unlock();
}
示例5: send
void SendThread::send(rrdisplayclient *rrdpy, rrframe *b)
{
m_mutexData.lock();
m_rrdpy = rrdpy;
m_b = b;
m_condData.signal();
m_mutexData.unlock();
}
示例6: cleanup
void DiskCache::cleanup()
{
cleanupLock.lock();
mapLock.lock();
for(std::list<std::pair<int,int> >::iterator it = _cleanupList.begin(); it != _cleanupList.end(); )
{
#ifdef DC_PRINT_DEBUG
std::cerr << "Cleanup f: " << it->first << " i: " << it->second << std::endl;
#endif
if(_cacheMap.find(it->first) == _cacheMap.end() || _cacheMap[it->first].find(it->second) == _cacheMap[it->first].end())
{
#ifdef DC_PRINT_DEBUG
std::cerr << "Double Cleanup f: " << it->first << " i: " << it->second << std::endl;
#endif
it = _cleanupList.erase(it);
continue;
}
_cacheMap[it->first][it->second]->cji->lock.lock();
if(_cacheMap[it->first][it->second]->cji->refs <= 1)
{
_cacheMap[it->first][it->second]->cji->lock.unlock();
if(_cacheMap[it->first][it->second]->cji->data)
{
delete[] _cacheMap[it->first][it->second]->cji->data;
}
delete _cacheMap[it->first][it->second]->cji;
delete _cacheMap[it->first][it->second];
_cacheMap[it->first].erase(it->second);
it = _cleanupList.erase(it);
}
else
{
_cacheMap[it->first][it->second]->cji->lock.unlock();
it++;
}
}
mapLock.unlock();
cleanupLock.unlock();
}
示例7: run
virtual void run() {
helper::PerformanceMeasurer PM;
PM.tic();
while(!is->done()) {
_mutex.lock();
is->get(frame);
if(frame.empty()) {
loglni("[TrackThread] no valid frame, exit!!!");
OpenCVneedQuit = true;
_mutex.unlock();
break;
}
cvtColor(frame, gray, CV_BGR2GRAY);
double rms, ncc;
if( needToInit ) {
loglni("[TrackThread] INITing...");
Mat tmpH;
if( findAprilTag(frame, 0, tmpH, true) ) {
#if !USE_INTERNAL_DETECTOR
Mat initH = tmpH * iHI;
needToInit = !tracker.init(gray, initH, rms, ncc);
#else
needToInit=!tracker.init(gray,rms,ncc);
#endif
if(!needToInit) loglni("[TrackThread] ...INITed");
if(!needToInit) tracker.draw3D(frame);
}
} else {
needToInit=!tracker(gray, rms, ncc, opencvDraw?&frame:0);
if(!needToInit) tracker.GetCameraPose(camR,camT,false,true);
}
++BkgModifyCnt;
loglni("[TrackThread] fps="<<1.0/PM.toctic());
_mutex.unlock();
if(OpenCVneedQuit) {
break;
}
++framecnt;
}
OpenThreads::Thread::YieldCurrentThread();
loglni("[TrackThread] OpenCV quited...");
if(!videoFromWebcam) {
loglni("[TrackThread] OpenCV notify OSG to quit...");
viewer.setDone(true);
}
}
示例8: getFormattedTime
void ossim::getFormattedTime(
const std::string& format, bool gmtFlag, std::string& result )
{
timeMutex.lock();
time_t rawTime;
time(&rawTime);
struct tm* timeInfo;
if ( gmtFlag )
{
timeInfo = gmtime(&rawTime);
}
else
{
timeInfo = localtime(&rawTime);
}
size_t size = 0;
if ( timeInfo )
{
const size_t STRING_SIZE = 196; // This is a big time string size.
char outStr[STRING_SIZE];
size = strftime(outStr, STRING_SIZE, format.c_str(), timeInfo );
if ( size )
{
// Per strftime spec not needed but null terminating anyway.
outStr[STRING_SIZE-1] = '\0';
result = outStr;
}
}
if ( !size )
{
result.clear();
}
timeMutex.unlock();
}
示例9: add_file
int DiskCache::add_file(const std::string& name)
{
int id;
_fileAddLock.lock();
if(_fileIDMap.find(name) != _fileIDMap.end())
{
id = _fileIDMap[name];
}
else
{
listLock.lock();
_fileIDMap[name] = _nextID;
id = _nextID;
_cacheMap[id] = std::map<int,DiskCacheEntry*>();
_readList.push_back(std::list<std::pair<sph_task*, CopyJobInfo*> >());
for(int i = 0; i < _copyList.size(); i++)
{
_copyList[i].push_back(std::list<std::pair<sph_task*, CopyJobInfo*> >());
}
listLock.unlock();
_nextID++;
}
_fileAddLock.unlock();
#ifdef DC_PRINT_DEBUG
std::cerr << "add_file called with name: " << name << " given ID: " << id << std::endl;
#endif
return id;
}
示例10: add_task
void DiskCache::add_task(sph_task * task)
{
/*int curPages = 0;
mapLock.lock();
for(std::map<int, std::map<int,DiskCacheEntry*> >::iterator it = _cacheMap.begin(); it != _cacheMap.end(); it++)
{
curPages += it->second.size();
}
mapLock.unlock();
std::cerr << "Actual Current Pages: " << curPages << std::endl;*/
cleanup();
if(!_running || (task->f != _currentFileL && task->f != _currentFileR))
{
task->valid = false;
loadsLock.lock();
task->cache->loads.insert(*task);
loadsLock.unlock();
delete task;
return;
}
if(_cacheIndexMap.find(task->cache) == _cacheIndexMap.end())
{
listLock.lock();
int index = _cacheIndexMap.size();
_cacheIndexMap[task->cache] = index;
_copyList.push_back(std::vector<std::list<std::pair<sph_task*, CopyJobInfo*> > >());
for(int i = 0; i < _fileIDMap.size(); i++)
{
_copyList.back().push_back(std::list<std::pair<sph_task*, CopyJobInfo*> >());
}
listLock.unlock();
}
mapLock.lock();
if(!_cacheMap[task->f][task->i])
{
_cacheMap[task->f][task->i] = new DiskCacheEntry;
_cacheMap[task->f][task->i]->timestamp = task->timestamp;
_cacheMap[task->f][task->i]->f = task->f;
_cacheMap[task->f][task->i]->i = task->i;
CopyJobInfo * cji = new CopyJobInfo;
cji->data = NULL;
cji->size = 100;
cji->valid = 0;
cji->refs = 2;
_cacheMap[task->f][task->i]->cji = cji;
mapLock.unlock();
listLock.lock();
#ifdef DC_PRINT_DEBUG
std::cerr << "Job started for task f: " << task->f << " i: " << task->i << " t: " << task->timestamp << std::endl;
#endif
_readList[task->f].push_back(std::pair<sph_task*, CopyJobInfo*>(task,cji));
listLock.unlock();
pageCountLock.lock();
_numPages++;
/*while(_numPages >= _pages)
{
pageCountLock.unlock();
eject();
pageCountLock.lock();
}*/
pageCountLock.unlock();
}
else
{
CopyJobInfo * cji = _cacheMap[task->f][task->i]->cji;
cji->lock.lock();
if(!cji->size == 0)
{
_cacheMap[task->f][task->i]->timestamp = task->timestamp;
cji->refs++;
cji->lock.unlock();
mapLock.unlock();
#ifdef DC_PRINT_DEBUG
std::cerr << "DiskCache Hit f: " << task->f << " i: " << task->i << " t: " << task->timestamp << std::endl;
#endif
//.........这里部分代码省略.........
示例11: complete
void SendThread::complete()
{
m_mutexData.lock();
m_mutexData.unlock();
}
示例12: SetMetaData
bool CFfmpegDec::SetMetaData(FILE *_in, CAudioMetaData* m, bool save_cover)
{
if (!meta_data_valid)
{
if (!Init(_in, (const CFile::FileType) m->type))
return false;
mutex.lock();
int ret = avformat_find_stream_info(avc, NULL);
if (ret < 0) {
mutex.unlock();
DeInit();
printf("avformat_find_stream_info error %d\n", ret);
return false;
}
mutex.unlock();
if (!is_stream) {
GetMeta(avc->metadata);
for(unsigned int i = 0; i < avc->nb_streams; i++) {
if (avc->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
GetMeta(avc->streams[i]->metadata);
}
}
//fseek((FILE *) in, 0, SEEK_SET);
#ifdef FFDEC_DEBUG
av_dump_format(avc, 0, "", 0);
#endif
codec = NULL;
best_stream = av_find_best_stream(avc, AVMEDIA_TYPE_AUDIO, -1, -1, &codec, 0);
if (best_stream < 0) {
DeInit();
return false;
}
if (!codec)
codec = avcodec_find_decoder(avc->streams[best_stream]->codec->codec_id);
samplerate = avc->streams[best_stream]->codec->sample_rate;
mChannels = av_get_channel_layout_nb_channels(avc->streams[best_stream]->codec->channel_layout);
std::stringstream ss;
if (codec && codec->long_name != NULL)
type_info = codec->long_name;
else if(codec && codec->name != NULL)
type_info = codec->name;
else
type_info = "unknown";
ss << " / " << mChannels << " channel" << ( mChannels > 1 ? "s" : "");
type_info += ss.str();
bitrate = 0;
total_time = 0;
if (avc->duration != int64_t(AV_NOPTS_VALUE))
total_time = avc->duration / int64_t(AV_TIME_BASE);
printf("CFfmpegDec: format %s (%s) duration %ld\n", avc->iformat->name, type_info.c_str(), total_time);
for(unsigned int i = 0; i < avc->nb_streams; i++) {
if (avc->streams[i]->codec->bit_rate > 0)
bitrate += avc->streams[i]->codec->bit_rate;
if (save_cover && (avc->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC)) {
mkdir(COVERDIR, 0755);
std::string cover(COVERDIR);
cover += "/" + to_string(cover_count++) + ".jpg";
FILE *f = fopen(cover.c_str(), "wb");
if (f) {
AVPacket *pkt = &avc->streams[i]->attached_pic;
fwrite(pkt->data, pkt->size, 1, f);
fclose(f);
m->cover = cover;
m->cover_temporary = true;
}
}
}
if(!total_time && m->filesize && bitrate)
total_time = 8 * m->filesize / bitrate;
meta_data_valid = true;
m->changed = true;
}
if (!is_stream) {
m->title = title;
m->artist = artist;
m->date = date;
m->album = album;
m->genre = genre;
m->total_time = total_time;
}
m->type_info = type_info;
// make sure bitrate is set to prevent refresh metadata from gui, its a flag
m->bitrate = bitrate ? bitrate : 1;
m->samplerate = samplerate;
return true;
}
示例13: Decoder
CBaseDec::RetCode CFfmpegDec::Decoder(FILE *_in, int /*OutputFd*/, State* state, CAudioMetaData* _meta_data, time_t* time_played, unsigned int* secondsToSkip)
{
in = _in;
RetCode Status=OK;
is_stream = fseek((FILE *)in, 0, SEEK_SET);
if (!SetMetaData((FILE *)in, _meta_data, true)) {
DeInit();
Status=DATA_ERR;
return Status;
}
AVCodecContext *c = avc->streams[best_stream]->codec;
mutex.lock();
int r = avcodec_open2(c, codec, NULL);
mutex.unlock();
if (r)
{
DeInit();
Status=DATA_ERR;
return Status;
}
SwrContext *swr = swr_alloc();
if (!swr) {
mutex.lock();
avcodec_close(c);
mutex.unlock();
DeInit();
Status=DATA_ERR;
return Status;
}
mSampleRate = samplerate;
mChannels = av_get_channel_layout_nb_channels(AV_CH_LAYOUT_STEREO);
#if __BYTE_ORDER == __LITTLE_ENDIAN
audioDecoder->PrepareClipPlay(mChannels, mSampleRate, 16, 1);
#else
audioDecoder->PrepareClipPlay(mChannels, mSampleRate, 16, 0);
#endif
AVFrame *frame = NULL;
AVPacket rpacket;
av_init_packet(&rpacket);
av_opt_set_int(swr, "in_channel_layout", c->channel_layout, 0);
//av_opt_set_int(swr, "out_channel_layout", c->channel_layout, 0);
av_opt_set_int(swr, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
av_opt_set_int(swr, "in_sample_rate", c->sample_rate, 0);
av_opt_set_int(swr, "out_sample_rate", c->sample_rate, 0);
av_opt_set_int(swr, "in_sample_fmt", c->sample_fmt, 0);
av_opt_set_int(swr, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
swr_init(swr);
uint8_t *outbuf = NULL;
int outsamples = 0;
int outsamples_max = 0;
int64_t pts = 0, start_pts = 0, next_skip_pts = 0;
uint64_t skip = 0;
int seek_flags = 0;
do
{
int actSecsToSkip = *secondsToSkip;
if (!is_stream && (actSecsToSkip || *state==FF || *state==REV) && avc->streams[best_stream]->time_base.num) {
if (!next_skip_pts || pts >= next_skip_pts) {
skip = avc->streams[best_stream]->time_base.den / avc->streams[best_stream]->time_base.num;
if (actSecsToSkip)
skip *= actSecsToSkip;
if (*state == REV) {
next_skip_pts = pts - skip;
pts = next_skip_pts - skip/4;
seek_flags = AVSEEK_FLAG_BACKWARD;
if (pts < start_pts) {
pts = start_pts;
*state = PAUSE;
}
} else {
pts += skip;
next_skip_pts = pts + skip/4;
seek_flags = 0;
}
av_seek_frame(avc, best_stream, pts, seek_flags);
skip = 0;
// if a custom value was set we only jump once
if (actSecsToSkip != 0) {
*state=PLAY;
*secondsToSkip = 0;
}
}
}
while(*state==PAUSE && !is_stream)
usleep(10000);
if (av_read_frame(avc, &rpacket)) {
Status=DATA_ERR;
//.........这里部分代码省略.........
示例14: copy
void JobThread::copy()
{
std::pair<sph_task*, CopyJobInfo*> taskpair;
bool found = false;
listLock.lock();
if(_copyList->size())
{
_copyCacheNum = _copyCacheNum % _copyList->size();
_copyFileNum = _copyFileNum % _copyList->at(_copyCacheNum).size();
int lastFile = _copyFileNum;
for(int i = 0; i < _copyList->size(); i++)
{
for(; _copyFileNum < _copyList->at(_copyCacheNum).size(); _copyFileNum++)
{
if(_copyList->at(_copyCacheNum)[_copyFileNum].size())
{
for(std::list<std::pair<sph_task*, CopyJobInfo*> >::iterator it = _copyList->at(_copyCacheNum)[_copyFileNum].begin(); it != _copyList->at(_copyCacheNum)[_copyFileNum].end(); it++)
{
if(it->second->valid || !it->second->size)
{
taskpair = *it;
_copyList->at(_copyCacheNum)[_copyFileNum].erase(it);
found = true;
break;
}
}
if(found)
{
_copyFileNum++;
break;
}
//taskpair = _copyList->at(_copyCacheNum)[_copyFileNum].front();
//_copyList->at(_copyCacheNum)[_copyFileNum].pop_front();
//found = true;
//_copyFileNum++;
//break;
}
}
if(found)
{
if(_copyFileNum == _copyList->at(_copyCacheNum).size())
{
_copyCacheNum++;
_copyCacheNum = _copyCacheNum % _copyList->size();
_copyFileNum = 0;
}
break;
}
_copyFileNum = 0;
_copyCacheNum++;
_copyCacheNum = _copyCacheNum % _copyList->size();
}
if(!found)
{
for(_copyFileNum = 0; _copyFileNum < lastFile; _copyFileNum++)
{
if(_copyList->at(_copyCacheNum)[_copyFileNum].size())
{
for(std::list<std::pair<sph_task*, CopyJobInfo*> >::iterator it = _copyList->at(_copyCacheNum)[_copyFileNum].begin(); it != _copyList->at(_copyCacheNum)[_copyFileNum].end(); it++)
{
if(it->second->valid || !it->second->size)
{
taskpair = *it;
_copyList->at(_copyCacheNum)[_copyFileNum].erase(it);
found = true;
break;
}
}
if(found)
{
_copyFileNum++;
break;
}
//taskpair = _copyList->at(_copyCacheNum)[_copyFileNum].front();
//_copyList->at(_copyCacheNum)[_copyFileNum].pop_front();
//found = true;
//_copyFileNum++;
//break;
}
}
}
}
#ifdef DC_PRINT_DEBUG
int cjobsize = 0;
for(int i = 0; i < _copyList->size(); i++)
{
for(int j = 0; j < _copyList->at(i).size(); j++)
{
cjobsize += _copyList->at(i)[j].size();
}
}
if(cjobsize)
{
std::cerr << "Copy Jobs left: " << cjobsize << std::endl;
}
//.........这里部分代码省略.........
示例15: eject
bool DiskCache::eject()
{
#ifdef DC_PRINT_DEBUG
std::cerr << "DiskCache::eject()" << std::endl;
#endif
mapLock.lock();
// find oldest referenced page
int f = -1;
int i = -1;
int mint = INT_MAX;
for(std::map<int, std::map<int,DiskCacheEntry*> >::iterator it = _cacheMap.begin(); it != _cacheMap.end(); it++)
{
for(std::map<int,DiskCacheEntry*>::iterator it2 = it->second.begin(); it2 != it->second.end(); it2++)
{
if(!it2->second)
{
continue;
}
if(it2->second->timestamp < mint)
{
mint = it2->second->timestamp;
f = it2->second->f;
i = it2->second->i;
}
}
}
if(f == -1)
{
std::cerr << "No Min page found!?!?..." << std::endl;
mapLock.unlock();
return false;
}
_cacheMap[f][i]->timestamp = INT_MAX;
mapLock.unlock();
#ifdef DC_PRINT_DEBUG
std::cerr << "Eject f: " << f << " i: " << i << " t: " << mint << std::endl;
#endif
_cacheMap[f][i]->cji->lock.lock();
if(!_cacheMap[f][i]->cji->size)
{
#ifdef DC_PRINT_DEBUG
std::cerr << "Already Ejecting f: " << f << " i: " << i << " t: " << mint << std::endl;
#endif
_cacheMap[f][i]->cji->lock.unlock();
return false;
}
_cacheMap[f][i]->cji->size = 0;
_cacheMap[f][i]->cji->lock.unlock();
std::queue<sph_task> tempq;
loadsLock.lock();
for(std::map<sph_cache*,int>::iterator it = _cacheIndexMap.begin(); it != _cacheIndexMap.end(); it++)
{
while(!it->first->loads.empty())
{
tempq.push(it->first->loads.remove());
if(tempq.front().f == f && tempq.front().i == i)
{
tempq.front().valid = false;
}
}
while(tempq.size())
{
it->first->loads.insert(tempq.front());
tempq.pop();
}
}
loadsLock.unlock();
cleanupLock.lock();
_cleanupList.push_back(std::pair<int,int>(f,i));
cleanupLock.unlock();
/*delete[] _cacheMap[f][i]->cji->data;
delete _cacheMap[f][i]->cji;
delete _cacheMap[f][i];
_cacheMap[f].erase(i);*/
pageCountLock.lock();
_numPages--;
pageCountLock.unlock();
return true;
}