mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
ST: Support set context id while thread running. v5.0.72
This commit is contained in:
parent
9525511032
commit
dc20d5ddbc
12 changed files with 96 additions and 15 deletions
|
@ -62,10 +62,19 @@ const SrsContextId& SrsThreadContext::get_id()
|
|||
}
|
||||
|
||||
const SrsContextId& SrsThreadContext::set_id(const SrsContextId& v)
|
||||
{
|
||||
return srs_context_set_cid_of(srs_thread_self(), v);
|
||||
}
|
||||
|
||||
void SrsThreadContext::clear_cid()
|
||||
{
|
||||
}
|
||||
|
||||
const SrsContextId& srs_context_set_cid_of(srs_thread_t trd, const SrsContextId& v)
|
||||
{
|
||||
++_srs_pps_cids_set->sugar;
|
||||
|
||||
if (!srs_thread_self()) {
|
||||
if (!trd) {
|
||||
_srs_context_default = v;
|
||||
return v;
|
||||
}
|
||||
|
@ -78,16 +87,12 @@ const SrsContextId& SrsThreadContext::set_id(const SrsContextId& v)
|
|||
srs_assert(r0 == 0);
|
||||
}
|
||||
|
||||
int r0 = srs_thread_setspecific(_srs_context_key, cid);
|
||||
int r0 = srs_thread_setspecific2(trd, _srs_context_key, cid);
|
||||
srs_assert(r0 == 0);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
void SrsThreadContext::clear_cid()
|
||||
{
|
||||
}
|
||||
|
||||
impl_SrsContextRestore::impl_SrsContextRestore(SrsContextId cid)
|
||||
{
|
||||
cid_ = cid;
|
||||
|
|
|
@ -28,10 +28,13 @@ public:
|
|||
virtual SrsContextId generate_id();
|
||||
virtual const SrsContextId& get_id();
|
||||
virtual const SrsContextId& set_id(const SrsContextId& v);
|
||||
public:
|
||||
private:
|
||||
virtual void clear_cid();
|
||||
};
|
||||
|
||||
// Set the context id of specified thread, not self.
|
||||
extern const SrsContextId& srs_context_set_cid_of(srs_thread_t trd, const SrsContextId& v);
|
||||
|
||||
// The context restore stores the context and restore it when done.
|
||||
// Usage:
|
||||
// SrsContextRestore(_srs_context->get_id());
|
||||
|
|
|
@ -412,6 +412,11 @@ void *srs_thread_getspecific(int key)
|
|||
return st_thread_getspecific(key);
|
||||
}
|
||||
|
||||
int srs_thread_setspecific2(srs_thread_t thread, int key, void* value)
|
||||
{
|
||||
return st_thread_setspecific2((st_thread_t)thread, key, value);
|
||||
}
|
||||
|
||||
int srs_netfd_fileno(srs_netfd_t stfd)
|
||||
{
|
||||
return st_netfd_fileno((st_netfd_t)stfd);
|
||||
|
|
|
@ -74,6 +74,7 @@ extern int srs_mutex_unlock(srs_mutex_t mutex);
|
|||
|
||||
extern int srs_key_create(int* keyp, void (*destructor)(void*));
|
||||
extern int srs_thread_setspecific(int key, void* value);
|
||||
extern int srs_thread_setspecific2(srs_thread_t thread, int key, void* value);
|
||||
extern void* srs_thread_getspecific(int key);
|
||||
|
||||
extern int srs_netfd_fileno(srs_netfd_t stfd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue