Skip to content

Commit

Permalink
[core] Minor changes to C++11 and posix sync (#1379)
Browse files Browse the repository at this point in the history
* Consolidated the contents of sync.cpp under one namespace.
* Removed superfluous conditionals.
  • Loading branch information
ethouris committed Aug 11, 2020
1 parent 06d3c75 commit 19f8b80
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 37 deletions.
Empty file modified srtcore/epoll.h 100755 → 100644
Empty file.
68 changes: 34 additions & 34 deletions srtcore/sync.cpp
@@ -1,4 +1,4 @@
/*
/*
* SRT - Secure, Reliable, Transport
* Copyright (c) 2019 Haivision Systems Inc.
*
Expand All @@ -23,8 +23,12 @@ namespace srt_logging
}
using namespace srt_logging;

namespace srt
{
namespace sync
{

std::string srt::sync::FormatTime(const steady_clock::time_point& timestamp)
std::string FormatTime(const steady_clock::time_point& timestamp)
{
if (is_zero(timestamp))
{
Expand Down Expand Up @@ -52,7 +56,7 @@ std::string srt::sync::FormatTime(const steady_clock::time_point& timestamp)
return out.str();
}

std::string srt::sync::FormatTimeSys(const steady_clock::time_point& timestamp)
std::string FormatTimeSys(const steady_clock::time_point& timestamp)
{
const time_t now_s = ::time(NULL); // get current time in seconds
const steady_clock::time_point now_timestamp = steady_clock::now();
Expand All @@ -70,6 +74,33 @@ std::string srt::sync::FormatTimeSys(const steady_clock::time_point& timestamp)
}


#ifdef ENABLE_STDCXX_SYNC
bool StartThread(CThread& th, ThreadFunc&& f, void* args, const char* name)
#else
bool StartThread(CThread& th, void* (*f) (void*), void* args, const char* name)
#endif
{
ThreadName tn(name);
try
{
#if HAVE_FULL_CXX11 || defined(ENABLE_STDCXX_SYNC)
th = CThread(f, args);
#else
// No move semantics in C++03, therefore using a dedicated function
th.create_thread(f, args);
#endif
}
catch (const CThreadException& e)
{
HLOGC(mglog.Debug, log << name << ": failed to start thread. " << e.what());
return false;
}
return true;
}

} // namespace sync
} // namespace srt

////////////////////////////////////////////////////////////////////////////////
//
// CEvent class
Expand Down Expand Up @@ -239,34 +270,3 @@ bool srt::sync::CGlobEvent::waitForEvent()
return g_Sync.lock_wait_for(milliseconds_from(10));
}


namespace srt {
namespace sync {

#ifdef ENABLE_STDCXX_SYNC
bool StartThread(CThread& th, ThreadFunc&& f, void* args, const char* name)
#else
bool StartThread(CThread& th, void* (*f) (void*), void* args, const char* name)
#endif
{
ThreadName tn(name);
try
{
#if HAVE_FULL_CXX11 || defined(ENABLE_STDCXX_SYNC)
th = CThread(f, args);
#else
// No move semantics in C++03, therefore using a dedicated function
th.create_thread(f, args);
#endif
}
catch (const CThreadException& e)
{
HLOGC(mglog.Debug, log << name << ": failed to start thread. " << e.what());
return false;
}
return true;
}

} // namespace sync
} // namespace srt

3 changes: 0 additions & 3 deletions srtcore/sync_cxx11.cpp
Expand Up @@ -14,8 +14,6 @@
#include "srt_compat.h"
#include "common.h"

#ifdef ENABLE_STDCXX_SYNC

////////////////////////////////////////////////////////////////////////////////
//
// SyncCond (based on stl chrono C++11)
Expand Down Expand Up @@ -76,4 +74,3 @@ CUDTException& srt::sync::GetThreadLocalError()
return s_thErr;
}

#endif // ENABLE_STDCXX_SYNC
Empty file modified srtcore/utilities.h 100755 → 100644
Empty file.

0 comments on commit 19f8b80

Please sign in to comment.