Skip to content

Commit

Permalink
[core] Placed ThreadName class inside srt namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
maxsharabayko committed Aug 31, 2021
1 parent 409a40d commit 5e75c32
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 19 deletions.
18 changes: 9 additions & 9 deletions apps/srt-tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,25 +223,25 @@ class Engine
Engine(Tunnel* p, Medium* m1, Medium* m2, const std::string& nid)
:
#ifdef HAVE_FULL_CXX11
media {m1, m2},
media {m1, m2},
#endif
parent_tunnel(p), nameid(nid)
parent_tunnel(p), nameid(nid)
{
#ifndef HAVE_FULL_CXX11
// MSVC is not exactly C++11 compliant and complains around
// initialization of an array.
// Leaving this method of initialization for clarity and
// possibly more preferred performance.
media[0] = m1;
media[1] = m2;
// MSVC is not exactly C++11 compliant and complains around
// initialization of an array.
// Leaving this method of initialization for clarity and
// possibly more preferred performance.
media[0] = m1;
media[1] = m2;
#endif
}

void Start()
{
Verb() << "START: " << media[DIR_IN]->uri() << " --> " << media[DIR_OUT]->uri();
std::string thrn = media[DIR_IN]->id() + ">" + media[DIR_OUT]->id();
ThreadName tn(thrn.c_str());
srt::ThreadName tn(thrn.c_str());

thr = thread([this]() { Worker(); });
}
Expand Down
4 changes: 4 additions & 0 deletions srtcore/threadname.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ written by
#include "common.h"
#include "sync.h"

namespace srt {

class ThreadName
{

Expand Down Expand Up @@ -217,4 +219,6 @@ class ThreadName
}
};

} // namespace srt

#endif
2 changes: 2 additions & 0 deletions test/test_threadname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "gtest/gtest.h"
#include "threadname.h"

using namespace srt;

TEST(ThreadName, GetSet)
{
std::string name("getset");
Expand Down
10 changes: 5 additions & 5 deletions testing/srt-test-multiplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ struct MediumPair
applog.Note() << sout.str();
}
}
catch (Source::ReadEOF& x)
catch (const Source::ReadEOF&)
{
applog.Note() << "EOS - closing media for loop: " << name;
src->Close();
tar->Close();
applog.Note() << "CLOSED: " << name;
}
catch (std::runtime_error& x)
catch (const std::runtime_error& x)
{
applog.Note() << "INTERRUPTED: " << x.what();
src->Close();
Expand Down Expand Up @@ -196,7 +196,7 @@ class MediaBase
med.name = name;

// Ok, got this, so we can start transmission.
ThreadName tn(thread_name.c_str());
srt::ThreadName tn(thread_name.c_str());

med.runner = thread( [&med]() { med.TransmissionLoop(); });
return med;
Expand Down Expand Up @@ -577,7 +577,7 @@ int main( int argc, char** argv )

SrtModel m(up.host(), iport, up.parameters());

ThreadName::set("main");
srt::ThreadName::set("main");

// Note: for input, there must be an exactly defined
// number of sources. The loop rolls up to all these sources.
Expand Down Expand Up @@ -615,7 +615,7 @@ int main( int argc, char** argv )
break;
}

ThreadName::set("main");
srt::ThreadName::set("main");
}

applog.Note() << "All local stream definitions covered. Waiting for interrupt/broken all connections.";
Expand Down
4 changes: 2 additions & 2 deletions testing/srt-test-relay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ SrtMainLoop::SrtMainLoop(const string& srt_uri, bool input_echoback, const strin

void SrtMainLoop::InputRunner()
{
ThreadName::set("InputRN");
srt::ThreadName::set("InputRN");
// An extra thread with a loop that reads from the external input
// and writes into the SRT medium. When echoback mode is used,
// this thread isn't started at all and instead the SRT reading
Expand Down Expand Up @@ -438,7 +438,7 @@ void SrtMainLoop::run()

std::ostringstream tns;
tns << "Input:" << this;
ThreadName tn(tns.str().c_str());
srt::ThreadName tn(tns.str().c_str());
m_input_thr = thread([this] {
try {
InputRunner();
Expand Down
4 changes: 2 additions & 2 deletions testing/testactivemedia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

void SourceMedium::Runner()
{
ThreadName::set("SourceRN");
srt::ThreadName::set("SourceRN");

Verb() << VerbLock << "Starting SourceMedium: " << this;
for (;;)
Expand Down Expand Up @@ -63,7 +63,7 @@ MediaPacket SourceMedium::Extract()

void TargetMedium::Runner()
{
ThreadName::set("TargetRN");
srt::ThreadName::set("TargetRN");
auto on_return_set = OnReturnSet(running, false);
Verb() << VerbLock << "Starting TargetMedium: " << this;
for (;;)
Expand Down
2 changes: 1 addition & 1 deletion testing/testactivemedia.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Medium
running = true;
std::ostringstream tns;
tns << typeid(*this).name() << ":" << this;
ThreadName tn(tns.str().c_str());
srt::ThreadName tn(tns.str().c_str());
thr = thread( [this] { RunnerBase(); } );
}

Expand Down

0 comments on commit 5e75c32

Please sign in to comment.