diff --git a/trunk/Dockerfile.builds b/trunk/Dockerfile.builds index 65e71df1a..5a4e9205b 100644 --- a/trunk/Dockerfile.builds +++ b/trunk/Dockerfile.builds @@ -63,10 +63,10 @@ RUN cd /srs/trunk && ./configure --jobs=2 --srt=on && make -j2 ######################################################## FROM ossrs/srs:ubuntu16 AS ubuntu16-cross-armv7 COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --cross-build --cc=arm-linux-gnueabihf-gcc --cxx=arm-linux-gnueabihf-g++ \ +RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --cross-build --cc=arm-linux-gnueabihf-gcc --cxx=arm-linux-gnueabihf-g++ \ --ar=arm-linux-gnueabihf-ar --ld=arm-linux-gnueabihf-ld --randlib=arm-linux-gnueabihf-randlib && make -j2 FROM ossrs/srs:ubuntu16 AS ubuntu16-cross-aarch64 COPY . /srs -RUN cd /srs/trunk && ./configure --jobs=2 --cross-build --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ \ +RUN cd /srs/trunk && ./configure --jobs=2 --srt=off --cross-build --cc=aarch64-linux-gnu-gcc --cxx=aarch64-linux-gnu-g++ \ --ar=aarch64-linux-gnu-ar --ld=aarch64-linux-gnu-ld --randlib=aarch64-linux-gnu-randlib && make -j2 diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 7ab9e8fec..8358975f3 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -4,7 +4,7 @@ help=no # feature options SRS_HDS=NO -SRS_SRT=NO +SRS_SRT=YES SRS_RTC=YES SRS_CXX11=YES SRS_CXX14=NO diff --git a/trunk/configure b/trunk/configure index 5be1d5f3e..86cf95eed 100755 --- a/trunk/configure +++ b/trunk/configure @@ -199,7 +199,7 @@ MODULE_ID="CORE" MODULE_DEPENDS=() ModuleLibIncs=(${SRS_OBJS_DIR}) MODULE_FILES=("srs_core" "srs_core_version5" "srs_core_autofree" "srs_core_performance" - "srs_core_time" "srs_core_platform" "srs_core_lock") + "srs_core_time" "srs_core_platform") CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh CORE_OBJS="${MODULE_OBJS[@]}" # diff --git a/trunk/src/app/srs_app_log.cpp b/trunk/src/app/srs_app_log.cpp index 38c10c4ff..764a41aec 100644 --- a/trunk/src/app/srs_app_log.cpp +++ b/trunk/src/app/srs_app_log.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include // the max size of a line of log. #define LOG_MAX_SIZE 8192 @@ -37,7 +37,7 @@ SrsFileLog::SrsFileLog() log_to_file_tank = false; utc = false; - pthread_mutex_init(&mutex_, NULL); + mutex_ = new SrsMutex(); } SrsFileLog::~SrsFileLog() @@ -53,7 +53,7 @@ SrsFileLog::~SrsFileLog() _srs_config->unsubscribe(this); } - pthread_mutex_destroy(&mutex_); + srs_freep(mutex_); } srs_error_t SrsFileLog::initialize() @@ -84,95 +84,95 @@ void SrsFileLog::reopen() void SrsFileLog::verbose(const char* tag, SrsContextId context_id, const char* fmt, ...) { - SrsScopeLock sl(&mutex_); + SrsAutoLock sl(mutex_); if (level > SrsLogLevelVerbose) { return; } - + int size = 0; if (!srs_log_header(log_data, LOG_MAX_SIZE, utc, false, tag, context_id, "Verb", &size)) { return; } - + va_list ap; va_start(ap, fmt); // we reserved 1 bytes for the new line. size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); va_end(ap); - + write_log(fd, log_data, size, SrsLogLevelVerbose); } void SrsFileLog::info(const char* tag, SrsContextId context_id, const char* fmt, ...) { - SrsScopeLock sl(&mutex_); + SrsAutoLock sl(mutex_); if (level > SrsLogLevelInfo) { return; } - + int size = 0; if (!srs_log_header(log_data, LOG_MAX_SIZE, utc, false, tag, context_id, "Debug", &size)) { return; } - + va_list ap; va_start(ap, fmt); // we reserved 1 bytes for the new line. size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); va_end(ap); - + write_log(fd, log_data, size, SrsLogLevelInfo); } void SrsFileLog::trace(const char* tag, SrsContextId context_id, const char* fmt, ...) { - SrsScopeLock sl(&mutex_); + SrsAutoLock sl(mutex_); if (level > SrsLogLevelTrace) { return; } - + int size = 0; if (!srs_log_header(log_data, LOG_MAX_SIZE, utc, false, tag, context_id, "Trace", &size)) { return; } - + va_list ap; va_start(ap, fmt); // we reserved 1 bytes for the new line. size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); va_end(ap); - + write_log(fd, log_data, size, SrsLogLevelTrace); } void SrsFileLog::warn(const char* tag, SrsContextId context_id, const char* fmt, ...) { - SrsScopeLock sl(&mutex_); + SrsAutoLock sl(mutex_); if (level > SrsLogLevelWarn) { return; } - + int size = 0; if (!srs_log_header(log_data, LOG_MAX_SIZE, utc, true, tag, context_id, "Warn", &size)) { return; } - + va_list ap; va_start(ap, fmt); // we reserved 1 bytes for the new line. size += vsnprintf(log_data + size, LOG_MAX_SIZE - size, fmt, ap); va_end(ap); - + write_log(fd, log_data, size, SrsLogLevelWarn); } void SrsFileLog::error(const char* tag, SrsContextId context_id, const char* fmt, ...) { - SrsScopeLock sl(&mutex_); + SrsAutoLock sl(mutex_); if (level > SrsLogLevelError) { return; diff --git a/trunk/src/app/srs_app_log.hpp b/trunk/src/app/srs_app_log.hpp index fc0cbcccd..aefd91e26 100644 --- a/trunk/src/app/srs_app_log.hpp +++ b/trunk/src/app/srs_app_log.hpp @@ -15,6 +15,8 @@ #include #include +class SrsMutex; + // For log TAGs. #define TAG_MAIN "MAIN" #define TAG_MAYBE "MAYBE" @@ -41,7 +43,7 @@ private: bool utc; // TODO: FIXME: use macro define like SRS_MULTI_THREAD_LOG to switch enable log mutex or not. // Mutex for multithread log. - pthread_mutex_t mutex_; + SrsMutex* mutex_; public: SrsFileLog(); virtual ~SrsFileLog(); diff --git a/trunk/src/app/srs_app_threads.cpp b/trunk/src/app/srs_app_threads.cpp index 594da7918..e9c699913 100644 --- a/trunk/src/app/srs_app_threads.cpp +++ b/trunk/src/app/srs_app_threads.cpp @@ -26,6 +26,7 @@ #include #endif +#include #include using namespace std; @@ -427,3 +428,38 @@ srs_error_t srs_thread_initialize() return err; } +SrsMutex::SrsMutex() +{ + int rc = pthread_mutex_init(&mutex_, NULL); + srs_assert(!rc); +} + +SrsMutex::~SrsMutex() +{ + int rc = pthread_mutex_destroy(&mutex_); + srs_assert(!rc); +} + +void SrsMutex::lock() +{ + int rc = pthread_mutex_lock(&mutex_); + srs_assert(!rc); +} + +void SrsMutex::unlock() +{ + int rc = pthread_mutex_unlock(&mutex_); + srs_assert(!rc); +} + +SrsAutoLock::SrsAutoLock(SrsMutex* mutex) +{ + mutex_ = mutex; + mutex_->lock(); +} + +SrsAutoLock::~SrsAutoLock() +{ + mutex_->unlock(); +} + diff --git a/trunk/src/app/srs_app_threads.hpp b/trunk/src/app/srs_app_threads.hpp index 7d5338c48..0f57b4ddd 100644 --- a/trunk/src/app/srs_app_threads.hpp +++ b/trunk/src/app/srs_app_threads.hpp @@ -11,6 +11,8 @@ #include +#include + // Protect server in high load. class SrsCircuitBreaker : public ISrsFastTimer { @@ -49,5 +51,28 @@ extern SrsCircuitBreaker* _srs_circuit_breaker; // Initialize global or thread-local variables. extern srs_error_t srs_thread_initialize(); +// Wrapper for mutex. +class SrsMutex +{ +private: + pthread_mutex_t mutex_; +public: + SrsMutex(); + ~SrsMutex(); +public: + void lock(); + void unlock(); +}; + +// Lock the mutex when enter current scope, and unlock it when out. +class SrsAutoLock +{ +private: + SrsMutex* mutex_; +public: + SrsAutoLock(SrsMutex* mutex); + ~SrsAutoLock(); +}; + #endif diff --git a/trunk/src/core/srs_core_lock.cpp b/trunk/src/core/srs_core_lock.cpp deleted file mode 100644 index a2da00e24..000000000 --- a/trunk/src/core/srs_core_lock.cpp +++ /dev/null @@ -1,8 +0,0 @@ -// -// Copyright (c) 2013-2021 The SRS Authors -// -// SPDX-License-Identifier: MIT or MulanPSL-2.0 -// - -#include - diff --git a/trunk/src/core/srs_core_lock.hpp b/trunk/src/core/srs_core_lock.hpp deleted file mode 100644 index 3eb1c1d3c..000000000 --- a/trunk/src/core/srs_core_lock.hpp +++ /dev/null @@ -1,57 +0,0 @@ -// -// Copyright (c) 2013-2021 The SRS Authors -// -// SPDX-License-Identifier: MIT or MulanPSL-2.0 -// - -#ifndef SRS_CORE_LOCK_HPP -#define SRS_CORE_LOCK_HPP - -#include - -#include - -#include - -class SrsScopeLock -{ -private: - pthread_mutex_t* mutex_; - bool locked_; - -public: - explicit SrsScopeLock(pthread_mutex_t* mutex) - { - mutex_ = mutex; - locked_ = false; - - lock(); - } - - ~SrsScopeLock() - { - unlock(); - } - - void lock() - { - if (locked_) { - return; - } - - locked_ = true; - pthread_mutex_lock(mutex_); - } - - void unlock() - { - if (! locked_) { - return; - } - - locked_ = false; - pthread_mutex_unlock(mutex_); - } -}; - -#endif