Skip to content

Commit

Permalink
[apps] Fixed verbose linkage difference.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Aug 8, 2024
1 parent b8a2822 commit e9f9d32
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 23 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,6 @@ if (ENABLE_APPS)
# srt-multiplex temporarily blocked
#srt_add_application(srt-multiplex ${VIRTUAL_srtsupport})
srt_add_application(srt-tunnel ${VIRTUAL_srtsupport})
target_compile_definitions(srt-tunnel PUBLIC -DSRT_ENABLE_VERBOSE_LOCK)
endif()

if (ENABLE_TESTING)
Expand Down Expand Up @@ -1421,7 +1420,6 @@ if (ENABLE_APPS)

srt_add_testprogram(srt-test-relay)
srt_make_application(srt-test-relay)
target_compile_definitions(srt-test-relay PUBLIC -DSRT_ENABLE_VERBOSE_LOCK)

srt_add_testprogram(srt-test-multiplex)
srt_make_application(srt-test-multiplex)
Expand Down
11 changes: 2 additions & 9 deletions apps/verbose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
*/

#include "verbose.hpp"
#include <mutex>

namespace Verbose
{
bool on = false;
std::ostream* cverb = &std::cerr;
#if SRT_ENABLE_VERBOSE_LOCK
std::mutex vlock;
#endif

Log& Log::operator<<(LogNoEol)
{
Expand All @@ -28,27 +27,24 @@ namespace Verbose
return *this;
}

#if SRT_ENABLE_VERBOSE_LOCK
Log& Log::operator<<(LogLock)
{
lockline = true;
return *this;
}
#endif

Log::~Log()
{
if (on && !noeol)
{
#if SRT_ENABLE_VERBOSE_LOCK
if (lockline)
{
// Lock explicitly, as requested, and wait for the opportunity.
vlock.lock();
}
else if (vlock.try_lock())
{
// Successfully locked, so unlock immediately, locking wasn't requeted.
// Successfully locked, so unlock immediately, locking wasn't required.
vlock.unlock();
}
else
Expand All @@ -62,15 +58,12 @@ namespace Verbose
vlock.lock();
vlock.unlock();
}
#endif
(*cverb) << std::endl;
#if SRT_ENABLE_VERBOSE_LOCK

// If lockline is set, the lock was requested and WAS DONE, so unlock.
// Otherwise locking WAS NOT DONE.
if (lockline)
vlock.unlock();
#endif
}
}
}
13 changes: 1 addition & 12 deletions apps/verbose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#define INC_SRT_VERBOSE_HPP

#include <iostream>
#if SRT_ENABLE_VERBOSE_LOCK
#include <mutex>
#endif

namespace Verbose
{
Expand All @@ -23,19 +20,15 @@ extern bool on;
extern std::ostream* cverb;

struct LogNoEol { LogNoEol() {} };
#if SRT_ENABLE_VERBOSE_LOCK
struct LogLock { LogLock() {} };
#endif

class Log
{
bool noeol = false;
#if SRT_ENABLE_VERBOSE_LOCK
bool lockline = false;
#endif

// Disallow creating dynamic objects
void* operator new(size_t);
void* operator new(size_t) = delete;

public:

Expand All @@ -50,9 +43,7 @@ class Log
}

Log& operator<<(LogNoEol);
#if SRT_ENABLE_VERBOSE_LOCK
Log& operator<<(LogLock);
#endif
~Log();
};

Expand Down Expand Up @@ -99,8 +90,6 @@ inline void Verb(Args&&... args)

// Manipulator tags
static const Verbose::LogNoEol VerbNoEOL;
#if SRT_ENABLE_VERBOSE_LOCK
static const Verbose::LogLock VerbLock;
#endif

#endif

0 comments on commit e9f9d32

Please sign in to comment.