本文整理汇总了C++中QMutex::lock方法的典型用法代码示例。如果您正苦于以下问题:C++ QMutex::lock方法的具体用法?C++ QMutex::lock怎么用?C++ QMutex::lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMutex
的用法示例。
在下文中一共展示了QMutex::lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadFrame
// функция считывания изображения из очереди
bool TSDataHandler::ReadFrame(cv::Mat &output)
{
QMutex m;
m.lock();
if (mFrameQueue.empty())
{
m.unlock();
return false;
}
mFrame = mFrameQueue.back();
mFrame.copyTo(output);
mFrameQueue.pop_back();
mFrame.release();
m.unlock();
return true;
}
示例2: run
void run()
{
test_mutex.lock();
test_mutex.lock();
test_mutex.lock();
test_mutex.lock();
mutex.lock();
for (int i = 0; i < iterations; ++i) {
cond.wakeOne();
cond.wait(&mutex);
}
mutex.unlock();
test_mutex.unlock();
test_mutex.unlock();
test_mutex.unlock();
test_mutex.unlock();
}
示例3: sendLoadSceneRPC
void sendLoadSceneRPC(Player* player, QString sceneName, UVector pos) // Loads a scene and send to the given pos
{
win.logMessage(QString(QString("UDP: Loading scene \"")+sceneName
+"\" to "+QString().setNum(player->pony.netviewId)
+" at "+QString().setNum(pos.x)+" "
+QString().setNum(pos.y)+" "
+QString().setNum(pos.z)));
Scene* scene = findScene(sceneName);
Scene* oldScene = findScene(player->pony.sceneName);
if (scene->name.isEmpty() || oldScene->name.isEmpty())
{
win.logMessage("UDP: Can't find the scene, aborting");
return;
}
// Update scene players
//win.logMessage("sendLoadSceneRPC pos: locking");
levelLoadMutex.lock();
player->inGame=1;
player->pony.pos = pos;
player->pony.sceneName = sceneName.toLower();
player->lastValidReceivedAnimation.clear(); // Changing scenes resets animations
Player::removePlayer(oldScene->players, player->IP, player->port);
if (oldScene->name.toLower() != sceneName.toLower())
{
// Send remove RPC to the other players of the old scene
for (int i=0; i<oldScene->players.size(); i++)
sendNetviewRemove(oldScene->players[i], player->pony.netviewId);
// Send instantiate to the players of the new scene
for (int i=0; i<scene->players.size(); i++)
if (scene->players[i]->inGame>=2)
sendNetviewInstantiate(&player->pony, scene->players[i]);
}
scene->players << player;
QByteArray data(1,5);
data += stringToData(sceneName.toLower());
sendMessage(player,MsgUserReliableOrdered6,data); // Sends a 48
//win.logMessage("sendLoadSceneRPC pos: unlocking");
levelLoadMutex.unlock();
}
示例4: seq
void CmdTestProgress2::activated(int iMsg)
{
try
{
QMutex mutex;
mutex.lock();
unsigned long steps = 1000;
Base::SequencerLauncher seq("Starting progress bar", steps);
for (unsigned long i=0; i<steps;i++)
{
seq.next(false);
QWaitCondition().wait(&mutex, 10);
}
}
catch (...)
{
}
}
示例5: while
void CG27::run()
{
HRESULT hr;
if (g_pJoystick == NULL)
{
return;
}
while(1)
{
hr = g_pJoystick->Poll();
g_pJoystick->Acquire();
g_mutexG27.lock();
hr = g_pJoystick->GetDeviceState( sizeof( DIJOYSTATE2 ), &g_G27State);
emit(GetG27Info());
qDebug() << g_G27State.lX;
/* qDebug() << g_G27State.lY;
qDebug() << g_G27State.lZ;
qDebug() << g_G27State.lRx;
qDebug() << g_G27State.lRy;
qDebug() << g_G27State.lRz;
qDebug() << g_G27State.lVX;
qDebug() << g_G27State.lVY;
qDebug() << g_G27State.lVZ;
qDebug() << g_G27State.lAX;
qDebug() << g_G27State.lAY;
qDebug() << g_G27State.lAZ;
qDebug() << " ";
*/
qDebug() << " ";
qDebug() << " ";
g_mutexG27.unlock();
usleep(5000);
}
return;
}
示例6: evaluateWithWeighting
void evaluateWithWeighting(ScanMatchingConfiguration &conf) {
const TruthMap &map = *conf.map;
QList<MeasureError> errors[4];
int correctCounts[4] = {0, 0, 0, 0};
static QMutex mutex;
Eigen::Matrix3d sqrtCov = conf.covariance.llt().matrixL();
Eigen::Matrix3d newCov = 4 * conf.covariance;
QList<LineSegment *> segments = map.map();
for(int i = 0; i < conf.sampleCount; i++) {
int pickedIndex = Shared::Random::integer(0, map.nodeCount() - 1);
const SegmentScan *scan = map.scan(pickedIndex);
const Pose &pose = map.pose(pickedIndex);
const UncertainRototranslation corruptedPose(
Rototranslation(Shared::Random::multiNormalRoot(
pose.vectorForm(), sqrtCov)), newCov);
SemiDeterministicRetriever sdr(segments, *scan, corruptedPose);
doScanMatch<LiGriffithsICL<SemiDeterministicRetriever> >(sdr, pose, newCov, correctCounts[0], errors[0]);
doScanMatch<ClassicICL<SemiDeterministicRetriever, AssociationType, W> >(sdr, pose, newCov, correctCounts[1], errors[1]);
doScanMatch<FilteredICL<SemiDeterministicRetriever, AssociationType, W> >(sdr, pose, newCov, correctCounts[2], errors[2]);
doScanMatch<RANSACMatcher<SemiDeterministicRetriever, AssociationType, W> >(sdr, pose, newCov, correctCounts[3], errors[3]);
}
mutex.lock();
lprint << conf << endl;
lprint << "ligriffithsAccuracy=" << correctCounts[0] / (double) conf.sampleCount << ";" << endl;
lprint << "classiciclAccuracy=" << correctCounts[1] / (double) conf.sampleCount << ";" << endl;
lprint << "filterediclAccuracy=" << correctCounts[2] / (double) conf.sampleCount << ";" << endl;
lprint << "ransacmatcherAccuracy=" << correctCounts[3] / (double) conf.sampleCount << ";" << endl;
lprint << "ligriffithsErrors=" << errors[0] << ";" << endl;
lprint << "classiciclErrors=" << errors[1] << ";" << endl;
lprint << "filterediclErrors=" << errors[2] << ";" << endl;
lprint << "ransacmatcherErrors=" << errors[3] << ";" << endl;
lprint << endl;
mutex.unlock();
}
示例7: run
void RadioSendThread::run()
{
RadioServer Server;
if (!Server.Open())
{
printf("Server Open failed!\r\n");
return;
}
int size;
while (true)
{
qDebug() << "Available: " << RadioSendRequest.available();
RadioSendRequest.acquire();
if (shutdownView)break;
RadioSendMutex.lock();
RadioCmds.set_time_stamp(0);
size= RadioCmds.cmds_size();
qDebug() << "size:" << size;
qDebug() << "IsInitialized: " << RadioCmds.IsInitialized();
if (RadioCmds.IsInitialized() && size>0 && size<10)
{
RadioCmds.set_time_stamp(0);
Server.Send(RadioCmds);
qDebug() << "sending";
}
else
{
printf("Radio Send Packet Error!\r\n");
}
Server.Send(RadioCmds);
RadioCmds.clear_cmds();
RadioSendMutex.unlock();
RadioSendRequest.release();
}
}
示例8: loadExtensions
/*!
\internal
Loads the mime type to extensions mapping
*/
static void loadExtensions()
{
QMutex mutex;
mutex.lock();
static bool loaded = false;
if(loaded)
{
mutex.unlock();
return;
}
QFile file(":qtopiamail/mime.types");
if ( file.open(QIODevice::ReadOnly) ) {
char line[1024];
while (file.readLine(line, sizeof(line)) > 0) {
if (line[0] == '\0' || line[0] == '#')
continue;
int posn = 0;
QString id = nextString(line, posn);
if ( id.isEmpty() )
continue;
id = id.toLower();
QStringList exts = extFor()->value(id);
for( QString ext = nextString( line, posn ); !ext.isEmpty(); ext = nextString(line, posn).toLower() )
{
if( !exts.contains( ext ) )
{
exts.append( ext );
typeFor()->insert(ext, id);
}
}
(*extFor())[ id ] = exts;
}
loaded = true;
}
mutex.unlock();
}
示例9: OpenConnection
bool OpenConnection(in_addr_t ipReal, const QString & strClient)
{
std::map<in_addr_t, Client *>::iterator iterClient, iterOldClient;
std::map<QString, ClientCreator>::iterator iterCreator;
bool bSuccess = false;
Client * pClient;
g_mutexClients.lock();
g_pLogger->LogInfo(QString("Starting %1 to host %2...").arg(strClient).arg(IPAddressToString(ipReal)));
iterCreator = g_mapClientCreators.find(strClient);
iterClient = g_mapClients.find(ipReal);
if (iterClient != g_mapClients.end())
{
if (iterClient->second != NULL)
{
iterClient->second->Stop();
delete iterClient->second;
}
g_mapClients.erase(iterClient);
}
if (iterCreator != g_mapClientCreators.end())
pClient = (*iterCreator->second)();
else
pClient = NULL;
if (pClient != NULL && pClient->Start(ipReal))
bSuccess = g_mapClients.insert(std::pair<in_addr_t, Client *>(ipReal, pClient)).second;
else if (pClient != NULL)
delete pClient;
if (bSuccess)
g_pLogger->LogInfo("Successful\n");
else
g_pLogger->LogInfo("Failed\n");
g_mutexClients.unlock();
return bSuccess;
}
示例10: CloseConnection
void CloseConnection(in_addr_t ipReal)
{
std::map<in_addr_t, Client *>::iterator iterConnection;
g_mutexClients.lock();
g_pLogger->LogInfo(QString("Stopping client to host %1...").arg(IPAddressToString(ipReal)));
iterConnection = g_mapClients.find(ipReal);
if (iterConnection != g_mapClients.end())
{
if (iterConnection->second != NULL)
{
iterConnection->second->Stop();
delete iterConnection->second;
iterConnection->second = NULL;
}
g_mapClients.erase(iterConnection);
}
g_pLogger->LogInfo("Successful\n");
g_mutexClients.unlock();
}
示例11: run
void OutputDataThread::run()
{
_byteList->clear();
QMutex mutex;
while(!_exitThread)
{
mutex.lock();
if(_sendData > 0 && !_byteList->isEmpty())
{
_sendData--;
_connection->sendAudioData(_byteList->takeFirst());
}
mutex.unlock();
}
return;
exec();
}
示例12: printme
void printme()
{
qDebug() << "printme " << QThread::currentThread()->objectName() << " begin running";
g_mutex.lock();
for(int i = 0; i < 60000;i++)
{
for(int j = 0; j < 40000; j++)
int r = i+j;
if(i%10000 == 0)
qDebug() << "Producer " << QThread::currentThread()->objectName() << " is running" << i;
}
qDebug() << "printme " << QThread::currentThread()->objectName() << " begin running";
g_mutex.unlock();
}
示例13: GetThreadPriority
QWaitConditionEvent *QWaitConditionPrivate::pre()
{
mtx.lock();
QWaitConditionEvent *wce =
freeQueue.isEmpty() ? new QWaitConditionEvent : freeQueue.takeFirst();
wce->priority = GetThreadPriority(GetCurrentThread());
wce->wokenUp = false;
// insert 'wce' into the queue (sorted by priority)
int index = 0;
for (; index < queue.size(); ++index) {
QWaitConditionEvent *current = queue.at(index);
if (current->priority < wce->priority)
break;
}
queue.insert(index, wce);
mtx.unlock();
return wce;
}
示例14: releaseAll
void TActionContext::releaseAll()
{
if (contextCount() > 0) {
setMutex.lock();
for (QSetIterator<TActionContext *> i(actionContexts); i.hasNext(); ) {
i.next()->stop(); // Stops application server
}
setMutex.unlock();
for (;;) {
Tf::msleep(1);
qApp->processEvents();
QMutexLocker locker(&setMutex);
if (actionContexts.isEmpty()) {
break;
}
}
}
}
示例15: run
void ThreadLearning::run(){
cOCR->iterasi = 0;
do
{
for(unsigned n = 0; n < cOCR->input.size(); ++n){
cOCR->ocrNet.feedForward(cOCR->input[n]);
cOCR->ocrNet.backProp(cOCR->target[n]);
}
cOCR->iterasi++;
cOCR->prosesPersen = cOCR->targetError / cOCR->ocrNet.getError() * 100;
QMutex mutex;
mutex.lock();
if(this->Stop) break;
mutex.unlock();
emit LearningProses();
}while (cOCR->ocrNet.getError() > cOCR->targetError && cOCR->iterasi < cOCR->maxInterasi);
}