Skip to content

Commit 45d51a5

Browse files
committed
fixed rotations and scenes
1 parent e16a161 commit 45d51a5

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

src/DMD.cpp

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -882,39 +882,19 @@ void DMD::SerumThread()
882882

883883
while (true)
884884
{
885-
auto systemNow = std::chrono::system_clock::now();
886-
auto nextWakeTime = systemNow + std::chrono::hours(24); // Default: far in the future
887-
888-
if (nextRotation > 0)
885+
if (nextRotation == 0 && sceneCurrentFrame >= sceneFrameCount)
889886
{
890-
auto rotationTime = std::chrono::system_clock::time_point(std::chrono::milliseconds(nextRotation));
891-
if (rotationTime > systemNow) nextWakeTime = std::min(nextWakeTime, rotationTime);
887+
std::shared_lock<std::shared_mutex> sl(m_dmdSharedMutex);
888+
m_dmdCV.wait(
889+
sl, [&]()
890+
{ return m_dmdFrameReady.load(std::memory_order_relaxed) || m_stopFlag.load(std::memory_order_relaxed); });
891+
sl.unlock();
892892
}
893-
894-
if (sceneCurrentFrame < sceneFrameCount && nextSceneFrame > 0)
893+
else
895894
{
896-
auto sceneTime = std::chrono::system_clock::time_point(std::chrono::milliseconds(nextSceneFrame));
897-
if (sceneTime > systemNow) nextWakeTime = std::min(nextWakeTime, sceneTime);
895+
std::this_thread::sleep_for(std::chrono::milliseconds(2));
898896
}
899897

900-
std::shared_lock<std::shared_mutex> sl(m_dmdSharedMutex);
901-
// Wait until either:
902-
// - m_dmdFrameReady/m_stopFlag is set (via notify_all), OR
903-
// - The timeout (nextRotation/nextSceneFrame) is reached
904-
m_dmdCV.wait_until(sl, nextWakeTime,
905-
[&]()
906-
{
907-
uint32_t now = std::chrono::duration_cast<std::chrono::milliseconds>(
908-
std::chrono::system_clock::now().time_since_epoch())
909-
.count();
910-
911-
return m_dmdFrameReady.load(std::memory_order_relaxed) ||
912-
m_stopFlag.load(std::memory_order_relaxed) ||
913-
(nextRotation > 0 && nextRotation <= now) ||
914-
(sceneCurrentFrame < sceneFrameCount && nextSceneFrame <= now);
915-
});
916-
sl.unlock();
917-
918898
if (m_stopFlag.load(std::memory_order_acquire))
919899
{
920900
if (m_pSerum)

0 commit comments

Comments
 (0)