diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index b21d2cd24..9950b4fc2 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -817,7 +817,7 @@ srs_error_t SrsServer::initialize_st() } // set current log id. - _srs_context->generate_id(); + _srs_context->set_id(_srs_context->generate_id()); // check asprocess. bool asprocess = _srs_config->get_asprocess(); diff --git a/trunk/src/app/srs_app_st.cpp b/trunk/src/app/srs_app_st.cpp index 2df8ddbf8..5fc7fe528 100755 --- a/trunk/src/app/srs_app_st.cpp +++ b/trunk/src/app/srs_app_st.cpp @@ -197,11 +197,10 @@ SrsContextId SrsSTCoroutine::cid() srs_error_t SrsSTCoroutine::cycle() { if (_srs_context) { - if (!cid_.empty()) { - _srs_context->set_id(cid_); - } else { + if (cid_.empty()) { cid_ = _srs_context->generate_id(); } + _srs_context->set_id(cid_); } srs_error_t err = handler->cycle(); diff --git a/trunk/src/kernel/srs_kernel_log.hpp b/trunk/src/kernel/srs_kernel_log.hpp index ed7c6d75b..dbf149cf2 100644 --- a/trunk/src/kernel/srs_kernel_log.hpp +++ b/trunk/src/kernel/srs_kernel_log.hpp @@ -80,21 +80,22 @@ public: // The logic context, for example, a RTMP connection, or RTC Session, etc. // We can grep the context id to identify the logic unit, for debugging. // For example: -// _srs_context->generate_id(); // Generate a new context id. -// _srs_context->get_id(); // Get current context id. -// int old_id = _srs_context->set_id("1000"); // Change the context id. +// SrsContextId cid = _srs_context->get_id(); // Get current context id. +// SrsContextId new_cid = _srs_context->generate_id(); // Generate a new context id. +// SrsContextId old_cid = _srs_context->set_id(new_cid); // Change the context id. class ISrsContext { public: ISrsContext(); virtual ~ISrsContext(); public: - // Generate the id for current context. + // Generate a new context id. + // @remark We do not set to current thread, user should do this. virtual SrsContextId generate_id() = 0; - // Get the generated id of current context. + // Get the context id of current thread. virtual SrsContextId get_id() = 0; - // Set the id of current context. - // @return the previous id value; 0 if no context. + // Set the context id of current thread. + // @return the previous context id. virtual SrsContextId set_id(SrsContextId v) = 0; }; diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index e9d6e51be..6ec4d01f7 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -213,7 +213,7 @@ srs_error_t do_main(int argc, char** argv) int main(int argc, char** argv) { // For background context id. - _srs_context->generate_id(); + _srs_context->set_id(_srs_context->generate_id()); srs_error_t err = do_main(argc, argv); diff --git a/trunk/src/protocol/srs_service_log.cpp b/trunk/src/protocol/srs_service_log.cpp index 437dc672b..3d711343b 100644 --- a/trunk/src/protocol/srs_service_log.cpp +++ b/trunk/src/protocol/srs_service_log.cpp @@ -46,7 +46,6 @@ SrsThreadContext::~SrsThreadContext() SrsContextId SrsThreadContext::generate_id() { SrsContextId cid = SrsContextId(srs_random_str(8)); - cache[srs_thread_self()] = cid; return cid; } diff --git a/trunk/src/protocol/srs_service_st.cpp b/trunk/src/protocol/srs_service_st.cpp index f33167882..f2fbf20e5 100644 --- a/trunk/src/protocol/srs_service_st.cpp +++ b/trunk/src/protocol/srs_service_st.cpp @@ -70,7 +70,7 @@ srs_error_t srs_st_init() return srs_error_new(ERROR_ST_SET_EPOLL, "st enable st failed, current is %s", st_get_eventsys_name()); } - // Before ST init, we might have already inited the background cid. + // Before ST init, we might have already initialized the background cid. SrsContextId cid = _srs_context->get_id(); if (cid.empty()) { cid = _srs_context->generate_id();