Skip to content

Commit

Permalink
Threads-Hybrid: Add TODO as be thread-local
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Apr 26, 2021
1 parent babe8e6 commit 7dbac15
Show file tree
Hide file tree
Showing 16 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ extern std::string srs_config_bool2switch(std::string sbool);
extern srs_error_t srs_config_transform_vhost(SrsConfDirective* root);
extern srs_error_t srs_config_transform_vhost2(SrsConfDirective* root);

// @global config object.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsConfig* _srs_config;

// The config directive.
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_gb28181.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ class SrsGb28181StreamChannel

};

// Global singleton instance.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsGb28181Manger* _srs_gb28181;

//gb28181 module management, management of all RTMP multiplexers,
Expand Down
1 change: 1 addition & 0 deletions trunk/src/app/srs_app_rtc_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ class ISrsRtcHijacker
virtual srs_error_t on_start_consume(SrsRtcConnection* session, SrsRtcPlayStream* player, SrsRequest* req, SrsRtcConsumer* consumer) = 0;
};

// TODO: FIXME: It should be thread-local or thread-safe.
extern ISrsRtcHijacker* _srs_rtc_hijacker;

#endif
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_rtc_dtls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class SrsDtlsCertificate
bool is_ecdsa();
};

// @global config object.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsDtlsCertificate* _srs_rtc_dtls_certificate;

// @remark: play the role of DTLS_CLIENT, will send handshake
Expand Down
6 changes: 2 additions & 4 deletions trunk/src/app/srs_app_rtc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ srs_error_t SrsRtcServer::initialize()
_srs_hybrid->timer()->subscribe(5 * SRS_UTIME_SECONDS, this);

// Initialize the black hole.
// TODO: FIXME: It should be thread-local or thread-safe.
if ((err = _srs_blackhole->initialize()) != srs_success) {
return srs_error_wrap(err, "black hole");
}
Expand Down Expand Up @@ -733,10 +734,6 @@ srs_error_t RtcServerAdapter::initialize()
{
srs_error_t err = srs_success;

if ((err = _srs_rtc_dtls_certificate->initialize()) != srs_success) {
return srs_error_wrap(err, "rtc dtls certificate initialize");
}

if ((err = rtc->initialize()) != srs_success) {
return srs_error_wrap(err, "rtc server initialize");
}
Expand All @@ -752,6 +749,7 @@ srs_error_t RtcServerAdapter::run()
return srs_error_wrap(err, "listen udp");
}

// TODO: FIXME: It should be thread-local or thread-safe.
if ((err = _srs_rtc_manager->start()) != srs_success) {
return srs_error_wrap(err, "start manager");
}
Expand Down
3 changes: 2 additions & 1 deletion trunk/src/app/srs_app_rtc_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class SrsRtcBlackhole
void sendto(void* data, int len);
};

// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsRtcBlackhole* _srs_blackhole;

// The handler for RTC server to call.
Expand Down Expand Up @@ -144,7 +145,7 @@ class RtcServerAdapter : public ISrsHybridServer
virtual void stop();
};

// Manager for RTC connections.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsResourceManager* _srs_rtc_manager;

#endif
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_rtc_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class SrsRtcStreamManager
virtual SrsRtcStream* fetch(SrsRequest* r);
};

// Global singleton instance.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsRtcStreamManager* _srs_rtc_sources;

// A publish stream interface, for source to callback with.
Expand Down
9 changes: 7 additions & 2 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ srs_error_t SrsServer::initialize(ISrsServerCycle* ch)
// instead, subscribe handler in initialize method.
srs_assert(_srs_config);
_srs_config->subscribe(this);


// TODO: FIXME: It should be thread-local or thread-safe.
handler = ch;
if(handler && (err = handler->initialize()) != srs_success){
return srs_error_wrap(err, "handler initialize");
Expand Down Expand Up @@ -946,7 +947,6 @@ srs_error_t SrsServer::ingest()
{
srs_error_t err = srs_success;

// TODO: FIXME: Should move from hybrid to api threads.
if ((err = ingester->start()) != srs_success) {
return srs_error_wrap(err, "ingest start");
}
Expand Down Expand Up @@ -1675,14 +1675,17 @@ srs_error_t SrsServerAdapter::run()
return srs_error_wrap(err, "server initialize");
}

// TODO: FIXME: It should be thread-local or thread-safe.
if ((err = srs->initialize_st()) != srs_success) {
return srs_error_wrap(err, "initialize st");
}

// TODO: FIXME: It should be thread-local or thread-safe.
if ((err = srs->acquire_pid_file()) != srs_success) {
return srs_error_wrap(err, "acquire pid file");
}

// TODO: FIXME: It should be thread-local or thread-safe.
if ((err = srs->initialize_signal()) != srs_success) {
return srs_error_wrap(err, "initialize signal");
}
Expand All @@ -1691,10 +1694,12 @@ srs_error_t SrsServerAdapter::run()
return srs_error_wrap(err, "listen");
}

// TODO: FIXME: It should be thread-local or thread-safe.
if ((err = srs->register_signal()) != srs_success) {
return srs_error_wrap(err, "register signal");
}

// TODO: FIXME: It should be thread-local or thread-safe.
if ((err = srs->ingest()) != srs_success) {
return srs_error_wrap(err, "ingest");
}
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ srs_error_t SrsMetaCache::update_vsh(SrsSharedPtrMessage* msg)
return vformat->on_video(msg);
}

SrsSourceManager* _srs_sources = new SrsSourceManager();
__thread SrsSourceManager* _srs_sources = NULL;

SrsSourceManager::SrsSourceManager()
{
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class SrsSourceManager : public ISrsHourGlass
};

// Global singleton instance.
extern SrsSourceManager* _srs_sources;
extern __thread SrsSourceManager* _srs_sources;

// For two sources to bridge with each other.
class ISrsSourceBridger
Expand Down
10 changes: 9 additions & 1 deletion trunk/src/app/srs_app_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <srs_kernel_utility.hpp>
#include <srs_app_utility.hpp>
#include <srs_app_hybrid.hpp>
#include <srs_app_source.hpp>

#include <unistd.h>

Expand Down Expand Up @@ -509,16 +510,23 @@ srs_error_t SrsThreadPool::setup()
// Create the hybrid RTMP/HTTP/RTC server.
_srs_hybrid = new SrsHybridServer();

// Create the source manager for server.
_srs_sources = new SrsSourceManager();

return err;
}

srs_error_t SrsThreadPool::initialize()
{
srs_error_t err = srs_success;

// Initialize global shared SRTP once.
// Initialize global shared thread-safe objects once.
srs_assert(srtp_init() == 0);

if ((err = _srs_rtc_dtls_certificate->initialize()) != srs_success) {
return srs_error_wrap(err, "rtc dtls certificate initialize");
}

// Initialize the master primordial thread.
SrsThreadEntry* entry = (SrsThreadEntry*)entry_;
#ifndef SRS_OSX
Expand Down
10 changes: 5 additions & 5 deletions trunk/src/app/srs_app_threads.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class SrsThreadPool
static void* start(void* arg);
};

// The global thread pool.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsThreadPool* _srs_thread_pool;

// Async file writer, it's thread safe.
Expand Down Expand Up @@ -426,7 +426,7 @@ class SrsAsyncLogManager
srs_error_t do_start();
};

// The global async log manager.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsAsyncLogManager* _srs_async_log;

// The async SRTP codec.
Expand Down Expand Up @@ -527,7 +527,7 @@ class SrsAsyncSRTPManager
virtual srs_error_t consume(SrsThreadEntry* entry, int* nn_consumed);
};

// The global async SRTP manager.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsAsyncSRTPManager* _srs_async_srtp;

// A thread-safe UDP listener.
Expand Down Expand Up @@ -608,7 +608,7 @@ class SrsAsyncRecvManager
bool consume_by_tunnel(SrsUdpMuxSocket* skt);
};

// The global async RECV manager.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsAsyncRecvManager* _srs_async_recv;

// The async UDP packet.
Expand Down Expand Up @@ -651,7 +651,7 @@ class SrsAsyncSendManager
srs_error_t do_start();
};

// The global async SEND manager.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsAsyncSendManager* _srs_async_send;

#endif
2 changes: 1 addition & 1 deletion trunk/src/kernel/srs_kernel_kbps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class SrsWallClock
virtual srs_utime_t now();
};

// The global clock.
// TODO: FIXME: It should be thread-local or thread-safe.
extern SrsWallClock* _srs_clock;

#endif
4 changes: 2 additions & 2 deletions trunk/src/kernel/srs_kernel_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ class ISrsContext
virtual const SrsContextId& set_id(const SrsContextId& v) = 0;
};

// @global User must provides a log object
// TODO: FIXME: It should be thread-local or thread-safe.
extern ISrsLog* _srs_log;

// @global User must implements the LogContext and define a global instance.
// TODO: FIXME: It should be thread-local or thread-safe.
extern ISrsContext* _srs_context;

// Log style.
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/kernel/srs_kernel_rtc_rtp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,13 @@ class SrsRtpFUAPayload2 : public ISrsRtpPayloader
virtual ISrsRtpPayloader* copy();
};

// TODO: FIXME: It should be thread-local or thread-safe.
// For RTP packets cache.
extern SrsRtpObjectCacheManager<SrsRtpPacket2>* _srs_rtp_cache;
extern SrsRtpObjectCacheManager<SrsRtpRawPayload>* _srs_rtp_raw_cache;
extern SrsRtpObjectCacheManager<SrsRtpFUAPayload2>* _srs_rtp_fua_cache;

// TODO: FIXME: It should be thread-local or thread-safe.
// For shared message cache, with payload.
extern SrsRtpObjectCacheManager<SrsSharedPtrMessage>* _srs_rtp_msg_cache_buffers;
// For shared message cache, without payload.
Expand Down
1 change: 1 addition & 0 deletions trunk/src/main/srs_main_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ SrsConfig* _srs_config = new SrsConfig();
// @global version of srs, which can grep keyword "XCORE"
extern const char* _srs_version;

// TODO: FIXME: It should be thread-local or thread-safe.
// @global main SRS server, for debugging
SrsServer* _srs_server = NULL;

Expand Down

0 comments on commit 7dbac15

Please sign in to comment.