Skip to content
Snippets Groups Projects
Commit 68a9abcb authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

[ #45992 ] Remove unnecessary locks

parent 727dbc99
No related branches found
No related tags found
No related merge requests found
...@@ -80,16 +80,16 @@ bool VideoRenderer::renderToBitmap() ...@@ -80,16 +80,16 @@ bool VideoRenderer::renderToBitmap()
} }
if (!shmLock()) { if (!shmLock()) {
return false; return true;
} }
// wait for a new buffer // wait for a new buffer
while (m_BufferGen == m_pShmArea->m_BufferGen) { while (m_BufferGen == m_pShmArea->m_BufferGen) {
shmUnlock(); shmUnlock();
const struct timespec timeout = createTimeout();
if(!VideoModel::instance()->startStopMutex()->tryLock()) if(!VideoModel::instance()->startStopMutex()->tryLock())
return false; return false;
int err = sem_timedwait(&m_pShmArea->notification, &timeout); int err = sem_trywait(&m_pShmArea->notification);
VideoModel::instance()->startStopMutex()->unlock(); VideoModel::instance()->startStopMutex()->unlock();
// Useful for debugging // Useful for debugging
// switch (errno ) { // switch (errno ) {
...@@ -115,11 +115,11 @@ bool VideoRenderer::renderToBitmap() ...@@ -115,11 +115,11 @@ bool VideoRenderer::renderToBitmap()
// break; // break;
// } // }
if (err < 0) { if (err < 0) {
return false; return errno == EAGAIN;
} }
if (!shmLock()) { if (!shmLock()) {
return false; return true;
} }
} }
...@@ -208,7 +208,7 @@ bool VideoRenderer::resizeShm() ...@@ -208,7 +208,7 @@ bool VideoRenderer::resizeShm()
m_ShmAreaLen = new_size; m_ShmAreaLen = new_size;
if (!shmLock()) if (!shmLock())
return false; return true;
} }
return true; return true;
} }
...@@ -217,14 +217,7 @@ bool VideoRenderer::resizeShm() ...@@ -217,14 +217,7 @@ bool VideoRenderer::resizeShm()
bool VideoRenderer::shmLock() bool VideoRenderer::shmLock()
{ {
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
const timespec timeout = createTimeout(); return sem_trywait(&m_pShmArea->mutex) >= 0;
/* We need an upper limit on how long we'll wait to avoid locking the whole GUI */
if (sem_timedwait(&m_pShmArea->mutex, &timeout) < 0) {
if (errno == ETIMEDOUT)
qDebug() << "Timed out before shm lock was acquired";
return false;
}
return true;
#else #else
return false; return false;
#endif #endif
...@@ -236,20 +229,6 @@ void VideoRenderer::shmUnlock() ...@@ -236,20 +229,6 @@ void VideoRenderer::shmUnlock()
sem_post(&m_pShmArea->mutex); sem_post(&m_pShmArea->mutex);
} }
///Create a SHM timeout
timespec VideoRenderer::createTimeout()
{
#ifdef Q_OS_LINUX
timespec timeout = {0, 0};
if (clock_gettime(CLOCK_REALTIME, &timeout) == -1)
qDebug() << "clock_gettime";
timeout.tv_sec += TIMEOUT_SEC;
return timeout;
#else
return {0,0};
#endif
}
/***************************************************************************** /*****************************************************************************
* * * *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment