2525#include " AlphaNumeric.h"
2626#include " FrameUtil.h"
2727#include " Logger.h"
28+ #include " TimeUtils.h"
2829#include " ZeDMD.h"
2930#include " komihash/komihash.h"
3031#include " pupdmd.h"
3132#include " serum-decode.h"
3233#include " serum.h"
33- #include " TimeUtils.h"
3434#include " sockpp/tcp_connector.h"
3535
3636namespace DMDUtil
@@ -150,7 +150,6 @@ DMD::DMD()
150150 }
151151 m_updateBufferQueuePosition.store (0 , std::memory_order_release);
152152 m_stopFlag.store (false , std::memory_order_release);
153- m_dmdFrameReady.store (false , std::memory_order_release);
154153 m_updateBuffered = std::make_shared<Update>();
155154
156155 m_pAlphaNumeric = new AlphaNumeric ();
@@ -477,7 +476,6 @@ void DMD::QueueUpdate(const std::shared_ptr<Update> dmdUpdate, bool buffered)
477476 memcpy (m_pUpdateBufferQueue[(++updateBufferQueuePosition) % DMDUTIL_FRAME_BUFFER_SIZE], dmdUpdate.get (),
478477 sizeof (Update));
479478 m_updateBufferQueuePosition.store (updateBufferQueuePosition, std::memory_order_release);
480- m_dmdFrameReady.store (true , std::memory_order_release);
481479
482480 Log (DMDUtil_LogLevel_DEBUG, " Queued Frame: position=%d, mode=%d, depth=%d" , updateBufferQueuePosition,
483481 dmdUpdate->mode , dmdUpdate->depth );
@@ -745,18 +743,23 @@ uint16_t DMD::GetNextBufferQueuePosition(uint16_t bufferPosition, const uint16_t
745743void DMD::DmdFrameThread ()
746744{
747745 char name[DMDUTIL_MAX_NAME_SIZE] = {0 };
746+ uint16_t bufferPosition = 0 ;
748747
749- (void )m_dmdFrameReady.load (std::memory_order_acquire);
750748 (void )m_stopFlag.load (std::memory_order_acquire);
751749
752750 while (true )
753751 {
754752 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
755- m_dmdCV.wait (
756- sl, [&]()
757- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
753+ m_dmdCV.wait (sl,
754+ [&]()
755+ {
756+ return m_stopFlag.load (std::memory_order_relaxed) ||
757+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
758+ });
758759 sl.unlock ();
759760
761+ bufferPosition = m_updateBufferQueuePosition.load (std::memory_order_relaxed);
762+
760763 if (strcmp (m_romName, name) != 0 )
761764 {
762765 strcpy (name, m_romName);
@@ -767,10 +770,6 @@ void DMD::DmdFrameThread()
767770
768771 std::this_thread::sleep_for (std::chrono::milliseconds (2 ));
769772
770- std::unique_lock<std::shared_mutex> ul (m_dmdSharedMutex);
771- m_dmdFrameReady.store (false , std::memory_order_release);
772- ul.unlock ();
773-
774773 if (m_stopFlag)
775774 {
776775 return ;
@@ -790,7 +789,6 @@ void DMD::ZeDMDThread()
790789 uint8_t indexBuffer[256 * 64 ] = {0 };
791790 uint8_t renderBuffer[256 * 64 * 3 ] = {0 };
792791
793- (void )m_dmdFrameReady.load (std::memory_order_acquire);
794792 (void )m_stopFlag.load (std::memory_order_acquire);
795793
796794 Config* const pConfig = Config::GetInstance ();
@@ -799,9 +797,12 @@ void DMD::ZeDMDThread()
799797 while (true )
800798 {
801799 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
802- m_dmdCV.wait (
803- sl, [&]()
804- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
800+ m_dmdCV.wait (sl,
801+ [&]()
802+ {
803+ return m_stopFlag.load (std::memory_order_relaxed) ||
804+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
805+ });
805806 sl.unlock ();
806807
807808 if (m_stopFlag.load (std::memory_order_acquire))
@@ -933,7 +934,9 @@ void DMD::ZeDMDThread()
933934
934935void DMD::SerumThread ()
935936{
936- if (Config::GetInstance ()->IsAltColor ())
937+ Config* const pConfig = Config::GetInstance ();
938+
939+ if (pConfig->IsAltColor ())
937940 {
938941 Serum_SetLogCallback (Serum_LogCallback, nullptr );
939942
@@ -945,12 +948,11 @@ void DMD::SerumThread()
945948 Update* lastDmdUpdate = nullptr ;
946949 uint8_t flags = 0 ;
947950
948- (void )m_dmdFrameReady.load (std::memory_order_acquire);
949951 (void )m_stopFlag.load (std::memory_order_acquire);
950952
951- Config* const pConfig = Config::GetInstance ();
952953 bool showNotColorizedFrames = pConfig->IsShowNotColorizedFrames ();
953954 bool dumpNotColorizedFrames = pConfig->IsDumpNotColorizedFrames ();
955+ if (pConfig->IsSerumPUPTriggers ()) Serum_EnablePupTrigers ();
954956
955957 while (true )
956958 {
@@ -979,9 +981,12 @@ void DMD::SerumThread()
979981 if (nextRotation == 0 )
980982 {
981983 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
982- m_dmdCV.wait (
983- sl, [&]()
984- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
984+ m_dmdCV.wait (sl,
985+ [&]()
986+ {
987+ return m_stopFlag.load (std::memory_order_relaxed) ||
988+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
989+ });
985990 sl.unlock ();
986991 }
987992
@@ -1227,7 +1232,6 @@ void DMD::PixelcadeDMDThread()
12271232 uint16_t * rgb565Data = new uint16_t [targetLength];
12281233 memset (rgb565Data, 0 , targetLength * sizeof (uint16_t ));
12291234
1230- (void )m_dmdFrameReady.load (std::memory_order_acquire);
12311235 (void )m_stopFlag.load (std::memory_order_acquire);
12321236
12331237 Config* const pConfig = Config::GetInstance ();
@@ -1236,9 +1240,12 @@ void DMD::PixelcadeDMDThread()
12361240 while (true )
12371241 {
12381242 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
1239- m_dmdCV.wait (
1240- sl, [&]()
1241- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
1243+ m_dmdCV.wait (sl,
1244+ [&]()
1245+ {
1246+ return m_stopFlag.load (std::memory_order_relaxed) ||
1247+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
1248+ });
12421249 sl.unlock ();
12431250 if (m_stopFlag.load (std::memory_order_acquire))
12441251 {
@@ -1411,15 +1418,17 @@ void DMD::LevelDMDThread()
14111418 uint16_t bufferPosition = 0 ;
14121419 uint8_t renderBuffer[256 * 64 ] = {0 };
14131420
1414- (void )m_dmdFrameReady.load (std::memory_order_acquire);
14151421 (void )m_stopFlag.load (std::memory_order_acquire);
14161422
14171423 while (true )
14181424 {
14191425 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
1420- m_dmdCV.wait (
1421- sl, [&]()
1422- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
1426+ m_dmdCV.wait (sl,
1427+ [&]()
1428+ {
1429+ return m_stopFlag.load (std::memory_order_relaxed) ||
1430+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
1431+ });
14231432 sl.unlock ();
14241433 if (m_stopFlag.load (std::memory_order_acquire))
14251434 {
@@ -1461,7 +1470,6 @@ void DMD::RGB24DMDThread()
14611470 uint8_t rgb24Data[256 * 64 * 3 ] = {0 };
14621471 uint8_t rgb24DataScaled[256 * 64 * 3 ] = {0 };
14631472
1464- (void )m_dmdFrameReady.load (std::memory_order_acquire);
14651473 (void )m_stopFlag.load (std::memory_order_acquire);
14661474
14671475 Config* const pConfig = Config::GetInstance ();
@@ -1470,9 +1478,12 @@ void DMD::RGB24DMDThread()
14701478 while (true )
14711479 {
14721480 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
1473- m_dmdCV.wait (
1474- sl, [&]()
1475- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
1481+ m_dmdCV.wait (sl,
1482+ [&]()
1483+ {
1484+ return m_stopFlag.load (std::memory_order_relaxed) ||
1485+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
1486+ });
14761487 sl.unlock ();
14771488 if (m_stopFlag.load (std::memory_order_acquire))
14781489 {
@@ -1622,15 +1633,17 @@ void DMD::ConsoleDMDThread()
16221633 uint16_t bufferPosition = 0 ;
16231634 uint8_t renderBuffer[256 * 64 ] = {0 };
16241635
1625- (void )m_dmdFrameReady.load (std::memory_order_acquire);
16261636 (void )m_stopFlag.load (std::memory_order_acquire);
16271637
16281638 while (true )
16291639 {
16301640 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
1631- m_dmdCV.wait (
1632- sl, [&]()
1633- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
1641+ m_dmdCV.wait (sl,
1642+ [&]()
1643+ {
1644+ return m_stopFlag.load (std::memory_order_relaxed) ||
1645+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
1646+ });
16341647 sl.unlock ();
16351648 if (m_stopFlag.load (std::memory_order_acquire))
16361649 {
@@ -1744,7 +1757,6 @@ void DMD::DumpDMDTxtThread()
17441757 FILE* f = nullptr ;
17451758 std::unordered_set<uint64_t > seenHashes;
17461759
1747- (void )m_dmdFrameReady.load (std::memory_order_acquire);
17481760 (void )m_stopFlag.load (std::memory_order_acquire);
17491761
17501762 Config* const pConfig = Config::GetInstance ();
@@ -1754,9 +1766,12 @@ void DMD::DumpDMDTxtThread()
17541766 while (true )
17551767 {
17561768 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
1757- m_dmdCV.wait (
1758- sl, [&]()
1759- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
1769+ m_dmdCV.wait (sl,
1770+ [&]()
1771+ {
1772+ return m_stopFlag.load (std::memory_order_relaxed) ||
1773+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
1774+ });
17601775 sl.unlock ();
17611776 if (m_stopFlag.load (std::memory_order_acquire))
17621777 {
@@ -1903,15 +1918,17 @@ void DMD::DumpDMDRawThread()
19031918 std::chrono::steady_clock::time_point start;
19041919 FILE* f = nullptr ;
19051920
1906- (void )m_dmdFrameReady.load (std::memory_order_acquire);
19071921 (void )m_stopFlag.load (std::memory_order_acquire);
19081922
19091923 while (true )
19101924 {
19111925 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
1912- m_dmdCV.wait (
1913- sl, [&]()
1914- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
1926+ m_dmdCV.wait (sl,
1927+ [&]()
1928+ {
1929+ return m_stopFlag.load (std::memory_order_relaxed) ||
1930+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
1931+ });
19151932 sl.unlock ();
19161933 if (m_stopFlag.load (std::memory_order_acquire))
19171934 {
@@ -1978,15 +1995,17 @@ void DMD::PupDMDThread()
19781995 uint8_t palette[192 ] = {0 };
19791996 char name[DMDUTIL_MAX_NAME_SIZE] = {0 };
19801997
1981- (void )m_dmdFrameReady.load (std::memory_order_acquire);
19821998 (void )m_stopFlag.load (std::memory_order_acquire);
19831999
19842000 while (true )
19852001 {
19862002 std::shared_lock<std::shared_mutex> sl (m_dmdSharedMutex);
1987- m_dmdCV.wait (
1988- sl, [&]()
1989- { return m_dmdFrameReady.load (std::memory_order_relaxed) || m_stopFlag.load (std::memory_order_relaxed); });
2003+ m_dmdCV.wait (sl,
2004+ [&]()
2005+ {
2006+ return m_stopFlag.load (std::memory_order_relaxed) ||
2007+ (m_updateBufferQueuePosition.load (std::memory_order_relaxed) != bufferPosition);
2008+ });
19902009 sl.unlock ();
19912010 if (m_stopFlag.load (std::memory_order_acquire))
19922011 {
0 commit comments