mirror of
https://github.com/ossrs/srs.git
synced 2025-11-23 19:34:05 +08:00
Init ST after daemon started.
This commit is contained in:
@@ -78,14 +78,10 @@ extern std::string _srs_reload_id;
|
||||
extern SrsRtcBlackhole *_srs_blackhole;
|
||||
extern SrsDtlsCertificate *_srs_rtc_dtls_certificate;
|
||||
|
||||
bool _srs_global_initialized = false;
|
||||
srs_error_t srs_global_initialize()
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// Root global objects.
|
||||
_srs_log = new SrsFileLog();
|
||||
_srs_context = new SrsThreadContext();
|
||||
_srs_config = new SrsConfig();
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// Initialize the global kbps statistics variables
|
||||
if ((err = srs_global_kbps_initialize()) != srs_success) {
|
||||
@@ -140,6 +136,9 @@ srs_error_t srs_global_initialize()
|
||||
SrsRand rand;
|
||||
_srs_reload_id = rand.gen_str(7);
|
||||
|
||||
// Global initialization done
|
||||
_srs_global_initialized = true;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,10 +96,10 @@ srs_error_t do_main(int argc, char **argv, char **envp)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Initialize global and thread-local variables.
|
||||
if ((err = srs_global_initialize()) != srs_success) {
|
||||
return srs_error_wrap(err, "global init");
|
||||
}
|
||||
// Root global objects, should be created before any other global objects.
|
||||
_srs_log = new SrsFileLog();
|
||||
_srs_context = new SrsThreadContext();
|
||||
_srs_config = new SrsConfig();
|
||||
|
||||
// For background context id.
|
||||
_srs_context->set_id(_srs_context->generate_id());
|
||||
@@ -451,6 +451,14 @@ srs_error_t run_srs_server()
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// Initialize global and thread-local variables.
|
||||
if ((err = srs_global_initialize()) != srs_success) {
|
||||
return srs_error_wrap(err, "global init");
|
||||
}
|
||||
|
||||
// For primordial thread, share the default cid.
|
||||
_srs_context->set_id(_srs_context->get_id());
|
||||
|
||||
_srs_server = new SrsServer();
|
||||
|
||||
// Do some system initialize.
|
||||
|
||||
@@ -46,8 +46,14 @@ void _srs_context_destructor(void *arg)
|
||||
srs_freep(cid);
|
||||
}
|
||||
|
||||
extern bool _srs_global_initialized;
|
||||
|
||||
const SrsContextId &SrsThreadContext::get_id()
|
||||
{
|
||||
if (!_srs_global_initialized) {
|
||||
return _srs_context_default;
|
||||
}
|
||||
|
||||
++_srs_pps_cids_get->sugar_;
|
||||
|
||||
if (!srs_thread_self()) {
|
||||
@@ -71,8 +77,14 @@ void SrsThreadContext::clear_cid()
|
||||
{
|
||||
}
|
||||
|
||||
extern bool _srs_global_initialized;
|
||||
const SrsContextId &srs_context_set_cid_of(srs_thread_t trd, const SrsContextId &v)
|
||||
{
|
||||
if (!_srs_global_initialized) {
|
||||
_srs_context_default = v;
|
||||
return v;
|
||||
}
|
||||
|
||||
++_srs_pps_cids_set->sugar_;
|
||||
|
||||
if (!trd) {
|
||||
|
||||
Reference in New Issue
Block a user