Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[apps] Fixed verbose linkage difference. #3002

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 3 additions & 10 deletions apps/verbose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
*/

#include "verbose.hpp"
#include "sync.h" // srt::sync

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

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 requested.
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
Loading