Skip to content

Commit

Permalink
[devel] Fixed atomic setting of locked line in Verb
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Małecki committed Aug 12, 2024
1 parent 91f2c59 commit 30db78b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
16 changes: 14 additions & 2 deletions apps/verbose.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <iostream>
#if SRT_ENABLE_VERBOSE_LOCK
#include <mutex>
#include "atomic.h"
#endif

namespace Verbose
Expand All @@ -31,14 +32,18 @@ class Log
{
bool noeol = false;
#if SRT_ENABLE_VERBOSE_LOCK
bool lockline = false;
srt::sync::atomic<bool> lockline;
#endif

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

public:

Log() {}
Log(const Log& ) {}

Check warning

Code scanning / CodeQL

Inconsistent definition of copy constructor and assignment ('Rule of Two') Warning

No matching copy assignment operator in class Log. It is good practice to match a copy constructor with a copy assignment operator.


template <class V>
Log& operator<<(const V& arg)
{
Expand Down Expand Up @@ -80,7 +85,7 @@ inline void Print(Log& ) {}
template <typename Arg1, typename... Args>
inline void Print(Log& out, Arg1&& arg1, Args&&... args)
{
out << std::forward(arg1);
out << arg1;
Print(out, args...);
}

Expand All @@ -96,6 +101,13 @@ inline void Verb(Args&&... args)
Verbose::Print(log, args...);
}

template <typename... Args>
inline void Verror(Args&&... args)
{
Verbose::ErrLog log;
Verbose::Print(log, args...);
}


// Manipulator tags
static const Verbose::LogNoEol VerbNoEOL;
Expand Down
52 changes: 26 additions & 26 deletions testing/srt-test-live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ bool CheckMediaSpec(const string& prefix, const vector<string>& spec, string& w_
for (string& a: adrs)
w_outspec += a + ",";

Verb() << "NOTE: " << prefix << " specification set as: " << (w_outspec);
Verb("NOTE: ", prefix, " specification set as: ", (w_outspec));

return true;
}
Expand All @@ -294,20 +294,20 @@ extern "C" int SrtCheckGroupHook(void* , SRTSOCKET acpsock, int , const sockaddr
int type;
int size = sizeof type;
srt_getsockflag(acpsock, SRTO_GROUPCONNECT, &type, &size);
Verb() << "listener: @" << acpsock << " - accepting " << (type ? "GROUP" : "SINGLE") << VerbNoEOL;
Verb("listener: @", acpsock, " - accepting ", (type ? "GROUP" : "SINGLE"), VerbNoEOL);
if (type != 0)
{
SRT_GROUP_TYPE gt;
size = sizeof gt;
if (-1 != srt_getsockflag(acpsock, SRTO_GROUPTYPE, &gt, &size))
{
if (gt < Size(gtypes))
Verb() << " type=" << gtypes[gt] << VerbNoEOL;
Verb(" type=", gtypes[gt], VerbNoEOL);
else
Verb() << " type=" << int(gt) << VerbNoEOL;
Verb(" type=", int(gt), VerbNoEOL);
}
}
Verb() << " connection";
Verb(" connection");

return 0;
}
Expand All @@ -317,7 +317,7 @@ extern "C" int SrtUserPasswordHook(void* , SRTSOCKET acpsock, int hsv, const soc
{
if (hsv < 5)
{
Verb() << "SrtUserPasswordHook: HS version 4 doesn't support extended handshake";
Verb("SrtUserPasswordHook: HS version 4 doesn't support extended handshake");
return -1;
}

Expand Down Expand Up @@ -818,7 +818,7 @@ int main( int argc, char** argv )
return 0;
}

Verb() << "MEDIA CREATION FAILED: " << x.what() << " - exiting.";
Verb("MEDIA CREATION FAILED: ", x.what(), " - exiting.");

// Don't speak anything when no -v option.
// (the "requested interrupt" will be printed anyway)
Expand Down Expand Up @@ -847,10 +847,10 @@ int main( int argc, char** argv )

if (transmit_use_sourcetime && src->uri.type() != UriParser::SRT)
{
Verb() << "WARNING: -st option is effective only if the target type is SRT";
Verb("WARNING: -st option is effective only if the target type is SRT");
}

Verb() << "STARTING TRANSMISSION: '" << source_spec << "' --> '" << target_spec << "'";
Verb("STARTING TRANSMISSION: '", source_spec, "' --> '", target_spec, "'");

// After the time has been spent in the creation
// (including waiting for connection)
Expand All @@ -876,41 +876,41 @@ int main( int argc, char** argv )
{
if (stoptime == 0 && timeout != -1 )
{
Verb() << "[." << VerbNoEOL;
Verb("[.", VerbNoEOL);
alarm(timeout);
}
else
{
alarm(0);
}
Verb() << " << ... " << VerbNoEOL;
Verb(", ... ", VerbNoEOL);
g_interrupt_reason = "reading";
const MediaPacket& data = src->Read(chunk);
Verb() << " << " << data.payload.size() << " -> " << VerbNoEOL;
Verb(", ", data.payload.size(), " -> ", VerbNoEOL);
if ( data.payload.empty() && src->End() )
{
Verb() << "EOS";
Verb("EOS");
break;
}
g_interrupt_reason = "writing";
tar->Write(data);
if (stoptime == 0 && timeout != -1 )
{
Verb() << ".] " << VerbNoEOL;
Verb(".] ", VerbNoEOL);
alarm(0);
}

if ( tar->Broken() )
{
Verb() << " OUTPUT broken";
Verb(" OUTPUT broken");
break;
}

Verb() << "sent";
Verb("sent");

if (::transmit_int_state)
{
Verror() << "\n (interrupted on request)";
Verror("\n (interrupted on request)");
break;
}

Expand All @@ -922,7 +922,7 @@ int main( int argc, char** argv )
int remain = int(stoptime - final_delay - elapsed);
if (remain < 0)
{
Verror() << "\n (interrupted on timeout: elapsed " << elapsed << "s) - waiting " << final_delay << "s for cleanup";
Verror("\n (interrupted on timeout: elapsed ", elapsed, "s) - waiting ", final_delay, "s for cleanup");
this_thread::sleep_for(chrono::seconds(final_delay));
break;
}
Expand All @@ -934,42 +934,42 @@ int main( int argc, char** argv )

if (!skip_flushing)
{
Verror() << "(DEBUG) EOF when reading file. Looping until the sending bufer depletes.\n";
Verror("(DEBUG) EOF when reading file. Looping until the sending bufer depletes.\n");
for (;;)
{
size_t still = tar->Still();
if (still == 0)
{
Verror() << "(DEBUG) DEPLETED. Done.\n";
Verror("(DEBUG) DEPLETED. Done.\n");
break;
}

Verror() << "(DEBUG)... still " << still << " bytes (sleep 1s)\n";
Verror("(DEBUG)... still ", still, " bytes (sleep 1s)\n");
this_thread::sleep_for(chrono::seconds(1));
}
}
} catch (std::exception& x) { // Catches TransmissionError and AlarmExit

if (stoptime != 0 && ::timer_state)
{
Verror() << "Exit on timeout.";
Verror("Exit on timeout.");
}
else if (::transmit_int_state)
{
Verror() << "Exit on interrupt.";
Verror("Exit on interrupt.");
// Do nothing.
}
else
{
Verror() << "STD EXCEPTION: " << x.what();
Verror("STD EXCEPTION: ", x.what());
}

if ( crashonx )
throw;

if (final_delay > 0)
{
Verror() << "Waiting " << final_delay << "s for possible cleanup...";
Verror("Waiting ", final_delay, "s for possible cleanup...");
this_thread::sleep_for(chrono::seconds(final_delay));
}
if (stoptime != 0 && ::timer_state)
Expand All @@ -979,7 +979,7 @@ int main( int argc, char** argv )

} catch (...) {

Verror() << "UNKNOWN type of EXCEPTION";
Verror("UNKNOWN type of EXCEPTION");
if ( crashonx )
throw;

Expand Down
4 changes: 2 additions & 2 deletions testing/srt-test-multiplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,15 @@ void Stall()
++i_next;
if (i->has_quit)
{
Verb() << "Found QUIT mediumpair: " << i->name << " - removing from base";
Verb("Found QUIT mediumpair: ", i->name, " - removing from base");
i->Stop();
g_media_base.media.erase(i);
}
}

if (g_media_base.media.empty())
{
Verb() << "All media have quit. Marking exit.";
Verb("All media have quit. Marking exit.");
break;
}
}
Expand Down

0 comments on commit 30db78b

Please sign in to comment.