Skip to content

Commit

Permalink
fix(core): Fixed Sleep method to run for more than a second.
Browse files Browse the repository at this point in the history
  • Loading branch information
na2axl committed Apr 8, 2024
1 parent f8db952 commit 57e9015
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Core/Thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,19 @@ namespace SparkyStudios::Audio::Amplitude::Thread

void Sleep(AmInt32 milliseconds)
{
// usleep(milliseconds * 1000);
struct timespec req = { 0 };
req.tv_sec = 0;
req.tv_nsec = milliseconds * 1000000L;

if (milliseconds < 1000)
{
req.tv_sec = 0;
req.tv_nsec = milliseconds * 1000000L;
}
else
{
req.tv_sec = std::floor(milliseconds / 1000);
req.tv_nsec = (milliseconds % 1000) * 1000000L;
}

nanosleep(&req, nullptr);
}

Expand Down

0 comments on commit 57e9015

Please sign in to comment.