Skip to content

Commit

Permalink
cppcheck: Replace several obsolete usleep calls with nanosleep.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxdude42 committed Oct 2, 2020
1 parent 5ff0f80 commit 8cc709e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
3 changes: 2 additions & 1 deletion mythplugins/mythmusic/mythmusic/avfdecoder.cpp
Expand Up @@ -507,7 +507,8 @@ void avfDecoder::run()
if (buffered < 1000)
break;
// wait
usleep((buffered - 1000) * 1000);
const struct timespec ns {0, (buffered - 1000) * 1000000};
nanosleep(&ns, nullptr);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion mythplugins/mythmusic/mythmusic/editmetadata.cpp
Expand Up @@ -1356,7 +1356,8 @@ void EditAlbumartDialog::doCopyImageToTag(const AlbumArtImage *image)
while (copyThread->isRunning())
{
qApp->processEvents();
usleep(1000);
const struct timespec onems {0, 1000000};
nanosleep(&onems, nullptr);
}

strList = copyThread->getResult();
Expand Down
6 changes: 4 additions & 2 deletions mythplugins/mythmusic/mythmusic/importmusic.cpp
Expand Up @@ -483,7 +483,8 @@ bool ImportMusicDialog::copyFile(const QString &src, const QString &dst)

while (!copy->isFinished())
{
usleep(500);
const struct timespec halfms {0, 500000};
nanosleep(&halfms, nullptr);
QCoreApplication::processEvents();
}

Expand Down Expand Up @@ -522,7 +523,8 @@ void ImportMusicDialog::startScan()

while (!scanner->isFinished())
{
usleep(500);
const struct timespec halfms {0, 500000};
nanosleep(&halfms, nullptr);
QCoreApplication::processEvents();
}

Expand Down
Expand Up @@ -66,7 +66,8 @@ void AlarmNotifyThread::run()
}
}

usleep(999999);
const struct timespec onesec {1, 0};
nanosleep(&onesec, nullptr);
}

RunEpilog();
Expand Down
8 changes: 5 additions & 3 deletions mythtv/libs/libmythtv/DVD/mythdvdbuffer.cpp
Expand Up @@ -500,8 +500,9 @@ void MythDVDBuffer::WaitForPlayer(void)
int count = 0;
while (m_playerWait && count++ < 200)
{
const struct timespec tenms {0, 10000000};
m_rwLock.unlock();
usleep(10000);
nanosleep(&tenms, nullptr);
m_rwLock.lockForWrite();
}

Expand All @@ -522,6 +523,7 @@ int MythDVDBuffer::SafeRead(void *Buffer, uint Size)
int offset = 0;
bool reprocessing = false;
bool waiting = false;
const struct timespec tenms {0, 10000000};

if (m_gotStop)
{
Expand Down Expand Up @@ -996,7 +998,7 @@ int MythDVDBuffer::SafeRead(void *Buffer, uint Size)
// pause a little as the dvdnav VM will continue to return
// this event until it has been skipped
m_rwLock.unlock();
usleep(10000);
nanosleep(&tenms, nullptr);
m_rwLock.lockForWrite();

// when scanning the file or exiting playback, skip immediately
Expand Down Expand Up @@ -1052,7 +1054,7 @@ int MythDVDBuffer::SafeRead(void *Buffer, uint Size)
{
m_dvdWaiting = true;
m_rwLock.unlock();
usleep(10000);
nanosleep(&tenms, nullptr);
m_rwLock.lockForWrite();
}

Expand Down

0 comments on commit 8cc709e

Please sign in to comment.