Skip to content

Commit

Permalink
[core] Fix Solaris build. (#2115)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlsantiago0 committed Sep 8, 2021
1 parent 34ba951 commit b147d5e
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 41 deletions.
11 changes: 8 additions & 3 deletions CMakeLists.txt
Expand Up @@ -40,8 +40,9 @@ set_if(BSD ${SYSNAME_LC} MATCHES "bsd$")
set_if(MICROSOFT WIN32 AND (NOT MINGW AND NOT CYGWIN))
set_if(GNU ${CMAKE_SYSTEM_NAME} MATCHES "GNU")
set_if(ANDROID ${SYSNAME_LC} MATCHES "android")
set_if(POSIX LINUX OR DARWIN OR BSD OR ANDROID OR (CYGWIN AND CYGWIN_USE_POSIX))
set_if(SYMLINKABLE LINUX OR DARWIN OR BSD OR CYGWIN OR GNU)
set_if(SUNOS "${SYSNAME_LC}" MATCHES "sunos")
set_if(POSIX LINUX OR DARWIN OR BSD OR SUNOS OR ANDROID OR (CYGWIN AND CYGWIN_USE_POSIX))
set_if(SYMLINKABLE LINUX OR DARWIN OR BSD OR SUNOS OR CYGWIN OR GNU)

# Not sure what to do in case of compiling by MSVC.
# This will make installdir in C:\Program Files\SRT then
Expand Down Expand Up @@ -282,8 +283,9 @@ if (DEFINED HAVE_INET_PTON)
add_definitions(-DHAVE_INET_PTON=1)
endif()

# Defines HAVE_PTHREAD_GETNAME_* and HAVE_PTHREAD_SETNAME_*
include(FindPThreadGetSetName)
FindPThreadGetSetName() # Defines HAVE_PTHREAD_GETNAME_* and HAVE_PTHREAD_SETNAME_*
FindPThreadGetSetName()

if (ENABLE_MONOTONIC_CLOCK)
if (NOT ENABLE_MONOTONIC_CLOCK_DEFAULT)
Expand Down Expand Up @@ -617,6 +619,9 @@ elseif(CYGWIN)
elseif(GNU)
add_definitions(-DGNU=1)
message(STATUS "DETECTED SYSTEM: GNU; GNU=1" )
elseif(SUNOS)
add_definitions(-DSUNOS=1)
message(STATUS "DETECTED SYSTEM: SunOS|Solaris; SUNOS=1" )
else()
message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}")
endif()
Expand Down
22 changes: 11 additions & 11 deletions apps/srt-tunnel.cpp
Expand Up @@ -94,7 +94,7 @@ class Medium
bool m_eof = false;
bool m_broken = false;

mutex access; // For closing
std::mutex access; // For closing

template <class DerivedMedium, class SocketType>
static Medium* CreateAcceptor(DerivedMedium* self, const sockaddr_any& sa, SocketType sock, size_t chunk)
Expand Down Expand Up @@ -287,7 +287,7 @@ class Tunnel
std::unique_ptr<Medium> med_acp, med_clr;
Engine acp_to_clr, clr_to_acp;
volatile bool running = true;
mutex access;
std::mutex access;

public:

Expand Down Expand Up @@ -324,7 +324,7 @@ class Tunnel

/*
{
lock_guard<mutex> lk(access);
lock_guard<std::mutex> lk(access);
if (acp_to_clr.stat() == -1 && clr_to_acp.stat() == -1)
{
Verb() << "Tunnel: Both engine decommissioned, will stop the tunnel.";
Expand Down Expand Up @@ -438,7 +438,7 @@ class SrtMedium: public Medium
void CloseSrt()
{
Verb() << "Closing SRT socket for " << uri();
lock_guard<mutex> lk(access);
lock_guard<std::mutex> lk(access);
if (m_socket == SRT_ERROR)
return;
srt_close(m_socket);
Expand Down Expand Up @@ -528,7 +528,7 @@ class TcpMedium: public Medium
void CloseTcp()
{
Verb() << "Closing TCP socket for " << uri();
lock_guard<mutex> lk(access);
lock_guard<std::mutex> lk(access);
if (m_socket == -1)
return;
tcp_close(m_socket);
Expand Down Expand Up @@ -954,20 +954,20 @@ std::unique_ptr<Medium> Medium::Create(const std::string& url, size_t chunk, Med
struct Tunnelbox
{
list<unique_ptr<Tunnel>> tunnels;
mutex access;
std::mutex access;
condition_variable decom_ready;
bool main_running = true;
thread thr;

void signal_decommission()
{
lock_guard<mutex> lk(access);
lock_guard<std::mutex> lk(access);
decom_ready.notify_one();
}

void install(std::unique_ptr<Medium>&& acp, std::unique_ptr<Medium>&& clr)
{
lock_guard<mutex> lk(access);
lock_guard<std::mutex> lk(access);
Verb() << "Tunnelbox: Starting tunnel: " << acp->uri() << " <-> " << clr->uri();

tunnels.emplace_back(new Tunnel(this, move(acp), move(clr)));
Expand All @@ -992,7 +992,7 @@ struct Tunnelbox

void CleanupWorker()
{
unique_lock<mutex> lk(access);
unique_lock<std::mutex> lk(access);

while (main_running)
{
Expand Down Expand Up @@ -1027,7 +1027,7 @@ void Tunnel::Stop()
if (!running)
return; // already stopped

lock_guard<mutex> lk(access);
lock_guard<std::mutex> lk(access);

// Ok, you are the first to make the tunnel
// not running and inform the tunnelbox.
Expand All @@ -1037,7 +1037,7 @@ void Tunnel::Stop()

bool Tunnel::decommission_if_dead(bool forced)
{
lock_guard<mutex> lk(access);
lock_guard<std::mutex> lk(access);
if (running && !forced)
return false; // working, not to be decommissioned

Expand Down
5 changes: 4 additions & 1 deletion apps/transmitmedia.cpp
Expand Up @@ -22,9 +22,12 @@
#if !defined(_WIN32)
#include <sys/ioctl.h>
#else
#include <fcntl.h>
#include <fcntl.h>
#include <io.h>
#endif
#if defined(SUNOS)
#include <sys/filio.h>
#endif

#include "netinet_any.h"
#include "apputil.hpp"
Expand Down
2 changes: 1 addition & 1 deletion srtcore/common.cpp
Expand Up @@ -98,7 +98,7 @@ const char* CUDTException::getErrorMessage() const ATR_NOTHROW
return srt::strerror_get_message(m_iMajor, m_iMinor);
}

string CUDTException::getErrorString() const
std::string CUDTException::getErrorString() const
{
return getErrorMessage();
}
Expand Down
3 changes: 2 additions & 1 deletion srtcore/epoll.cpp
Expand Up @@ -149,7 +149,8 @@ ENOMEM: There was insufficient memory to create the kernel object.
if (localid < 0)
throw CUDTException(MJ_SETUP, MN_NONE, errno);
#else
// on Solaris, use /dev/poll
// TODO: Solaris, use port_getn()
// https://docs.oracle.com/cd/E86824_01/html/E54766/port-get-3c.html
// on Windows, select
#endif

Expand Down
8 changes: 4 additions & 4 deletions srtcore/list.cpp
Expand Up @@ -100,13 +100,13 @@ void CSndLossList::traceState() const
int pos = m_iHead;
while (pos != SRT_SEQNO_NONE)
{
::cout << pos << ":[" << m_caSeq[pos].seqstart;
std::cout << pos << ":[" << m_caSeq[pos].seqstart;
if (m_caSeq[pos].seqend != SRT_SEQNO_NONE)
::cout << ", " << m_caSeq[pos].seqend;
::cout << "], ";
std::cout << ", " << m_caSeq[pos].seqend;
std::cout << "], ";
pos = m_caSeq[pos].inext;
}
::cout << "\n";
std::cout << "\n";
}

int CSndLossList::insert(int32_t seqno1, int32_t seqno2)
Expand Down
2 changes: 1 addition & 1 deletion srtcore/srt_compat.c
Expand Up @@ -23,7 +23,7 @@ written by
#include <string.h>
#include <stdio.h>
#include <errno.h>
#if defined(__unix__) && !defined(BSD)
#if defined(__unix__) && !defined(BSD) && !defined(SUNOS)
#include <features.h>
#endif

Expand Down
22 changes: 11 additions & 11 deletions srtcore/sync.h
Expand Up @@ -60,7 +60,6 @@ namespace srt
{
namespace sync
{
using namespace std;

///////////////////////////////////////////////////////////////////////////////
//
Expand All @@ -71,7 +70,7 @@ using namespace std;
#if ENABLE_STDCXX_SYNC

template <class Clock>
using Duration = chrono::duration<Clock>;
using Duration = std::chrono::duration<Clock>;

#else

Expand Down Expand Up @@ -130,13 +129,13 @@ class Duration

#if ENABLE_STDCXX_SYNC

using steady_clock = chrono::steady_clock;
using steady_clock = std::chrono::steady_clock;

template <class Clock, class Duration = typename Clock::duration>
using time_point = chrono::time_point<Clock, Duration>;
using time_point = std::chrono::time_point<Clock, Duration>;

template <class Clock>
using TimePoint = chrono::time_point<Clock>;
using TimePoint = std::chrono::time_point<Clock>;

template <class Clock, class Duration = typename Clock::duration>
inline bool is_zero(const time_point<Clock, Duration> &tp)
Expand Down Expand Up @@ -212,8 +211,8 @@ class TimePoint
inline void operator-=(const Duration<Clock>& rhs) { m_timestamp -= rhs.count(); }

public: //
static inline ATR_CONSTEXPR TimePoint min() { return TimePoint(numeric_limits<uint64_t>::min()); }
static inline ATR_CONSTEXPR TimePoint max() { return TimePoint(numeric_limits<uint64_t>::max()); }
static inline ATR_CONSTEXPR TimePoint min() { return TimePoint(std::numeric_limits<uint64_t>::min()); }
static inline ATR_CONSTEXPR TimePoint max() { return TimePoint(std::numeric_limits<uint64_t>::max()); }

public:
Duration<Clock> time_since_epoch() const;
Expand Down Expand Up @@ -311,9 +310,9 @@ inline bool is_zero(const TimePoint<steady_clock>& t)
///////////////////////////////////////////////////////////////////////////////

#if ENABLE_STDCXX_SYNC
using Mutex = mutex;
using UniqueLock = unique_lock<mutex>;
using ScopedLock = lock_guard<mutex>;
using Mutex = std::mutex;
using UniqueLock = std::unique_lock<std::mutex>;
using ScopedLock = std::lock_guard<std::mutex>;
#else
/// Mutex is a class wrapper, that should mimic the std::chrono::mutex class.
/// At the moment the extra function ref() is temporally added to allow calls
Expand Down Expand Up @@ -471,7 +470,7 @@ class Condition

private:
#if ENABLE_STDCXX_SYNC
condition_variable m_cv;
std::condition_variable m_cv;
#else
pthread_cond_t m_cv;
#endif
Expand Down Expand Up @@ -742,6 +741,7 @@ class CGlobEvent
#ifdef ENABLE_STDCXX_SYNC
typedef std::system_error CThreadException;
using CThread = std::thread;
namespace this_thread = std::this_thread;
#else // pthreads wrapper version
typedef ::CUDTException CThreadException;

Expand Down
4 changes: 2 additions & 2 deletions srtcore/sync_cxx11.cpp
Expand Up @@ -68,12 +68,12 @@ void srt::sync::Condition::wait(UniqueLock& lock)
bool srt::sync::Condition::wait_for(UniqueLock& lock, const steady_clock::duration& rel_time)
{
// Another possible implementation is wait_until(steady_clock::now() + timeout);
return m_cv.wait_for(lock, rel_time) != cv_status::timeout;
return m_cv.wait_for(lock, rel_time) != std::cv_status::timeout;
}

bool srt::sync::Condition::wait_until(UniqueLock& lock, const steady_clock::time_point& timeout_time)
{
return m_cv.wait_until(lock, timeout_time) != cv_status::timeout;
return m_cv.wait_until(lock, timeout_time) != std::cv_status::timeout;
}

void srt::sync::Condition::notify_one()
Expand Down
40 changes: 40 additions & 0 deletions srtcore/utilities.h
Expand Up @@ -140,6 +140,46 @@ written by
# define le64toh(x) letoh64(x)
#endif

#elif defined(SUNOS)

// SunOS/Solaris

#include <sys/byteorder.h>
#include <sys/isa_defs.h>

#define __LITTLE_ENDIAN 1234
#define __BIG_ENDIAN 4321

# if defined(_BIG_ENDIAN)
#define __BYTE_ORDER __BIG_ENDIAN
#define be64toh(x) (x)
#define be32toh(x) (x)
#define be16toh(x) (x)
#define le16toh(x) ((uint16_t)BSWAP_16(x))
#define le32toh(x) BSWAP_32(x)
#define le64toh(x) BSWAP_64(x)
#define htobe16(x) (x)
#define htole16(x) ((uint16_t)BSWAP_16(x))
#define htobe32(x) (x)
#define htole32(x) BSWAP_32(x)
#define htobe64(x) (x)
#define htole64(x) BSWAP_64(x)
# else
#define __BYTE_ORDER __LITTLE_ENDIAN
#define be64toh(x) BSWAP_64(x)
#define be32toh(x) ntohl(x)
#define be16toh(x) ntohs(x)
#define le16toh(x) (x)
#define le32toh(x) (x)
#define le64toh(x) (x)
#define htobe16(x) htons(x)
#define htole16(x) (x)
#define htobe32(x) htonl(x)
#define htole32(x) (x)
#define htobe64(x) BSWAP_64(x)
#define htole64(x) (x)
# endif

#elif defined(__WINDOWS__)

# include <winsock2.h>
Expand Down
6 changes: 3 additions & 3 deletions testing/testactivemedia.cpp
Expand Up @@ -16,15 +16,15 @@ void SourceMedium::Runner()
}
LOGP(applog.Debug, "SourceMedium(", typeid(*med).name(), "): [", input.payload.size(), "] MEDIUM -> BUFFER. signal(", &ready, ")");

lock_guard<mutex> g(buffer_lock);
lock_guard<std::mutex> g(buffer_lock);
buffer.push_back(input);
ready.notify_one();
}
}

MediaPacket SourceMedium::Extract()
{
unique_lock<mutex> g(buffer_lock);
unique_lock<std::mutex> g(buffer_lock);
for (;;)
{
if (::transmit_int_state)
Expand Down Expand Up @@ -70,7 +70,7 @@ void TargetMedium::Runner()
{
MediaPacket val;
{
unique_lock<mutex> lg(buffer_lock);
unique_lock<std::mutex> lg(buffer_lock);
if (buffer.empty())
{
if (!running)
Expand Down
6 changes: 3 additions & 3 deletions testing/testactivemedia.hpp
Expand Up @@ -150,7 +150,7 @@ struct TargetMedium: Medium<Target>
bool Schedule(const MediaPacket& data)
{
LOGP(applog.Debug, "TargetMedium::Schedule LOCK ... ");
lock_guard<mutex> lg(buffer_lock);
lock_guard<std::mutex> lg(buffer_lock);
LOGP(applog.Debug, "TargetMedium::Schedule LOCKED - checking: running=", running, " interrupt=", ::transmit_int_state);
if (!running || ::transmit_int_state)
{
Expand All @@ -166,13 +166,13 @@ struct TargetMedium: Medium<Target>

void Clear()
{
lock_guard<mutex> lg(buffer_lock);
lock_guard<std::mutex> lg(buffer_lock);
buffer.clear();
}

void Interrupt()
{
lock_guard<mutex> lg(buffer_lock);
lock_guard<std::mutex> lg(buffer_lock);
running = false;
ready.notify_one();
}
Expand Down

0 comments on commit b147d5e

Please sign in to comment.