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
|
@ -66,7 +66,12 @@ srs_error_t SrsDummyCoroutine::pull()
|
|||
|
||||
const SrsContextId& SrsDummyCoroutine::cid()
|
||||
{
|
||||
return _srs_context->get_id();
|
||||
return cid_;
|
||||
}
|
||||
|
||||
void SrsDummyCoroutine::set_cid(const SrsContextId& cid)
|
||||
{
|
||||
cid_ = cid;
|
||||
}
|
||||
|
||||
SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h)
|
||||
|
@ -114,6 +119,11 @@ const SrsContextId& SrsSTCoroutine::cid()
|
|||
return impl_->cid();
|
||||
}
|
||||
|
||||
void SrsSTCoroutine::set_cid(const SrsContextId& cid)
|
||||
{
|
||||
impl_->set_cid(cid);
|
||||
}
|
||||
|
||||
SrsFastCoroutine::SrsFastCoroutine(string n, ISrsCoroutineHandler* h)
|
||||
{
|
||||
// TODO: FIXME: Reduce duplicated code.
|
||||
|
@ -257,6 +267,12 @@ const SrsContextId& SrsFastCoroutine::cid()
|
|||
return cid_;
|
||||
}
|
||||
|
||||
void SrsFastCoroutine::set_cid(const SrsContextId& cid)
|
||||
{
|
||||
cid_ = cid;
|
||||
srs_context_set_cid_of(trd, cid);
|
||||
}
|
||||
|
||||
srs_error_t SrsFastCoroutine::cycle()
|
||||
{
|
||||
if (_srs_context) {
|
||||
|
|
|
@ -76,13 +76,17 @@ public:
|
|||
// @return a copy of error, which should be freed by user.
|
||||
// NULL if not terminated and user should pull again.
|
||||
virtual srs_error_t pull() = 0;
|
||||
// Get and set the context id of coroutine.
|
||||
virtual const SrsContextId& cid() = 0;
|
||||
virtual void set_cid(const SrsContextId& cid) = 0;
|
||||
};
|
||||
|
||||
// An empty coroutine, user can default to this object before create any real coroutine.
|
||||
// @see https://github.com/ossrs/srs/pull/908
|
||||
class SrsDummyCoroutine : public SrsCoroutine
|
||||
{
|
||||
private:
|
||||
SrsContextId cid_;
|
||||
public:
|
||||
SrsDummyCoroutine();
|
||||
virtual ~SrsDummyCoroutine();
|
||||
|
@ -92,6 +96,7 @@ public:
|
|||
virtual void interrupt();
|
||||
virtual srs_error_t pull();
|
||||
virtual const SrsContextId& cid();
|
||||
virtual void set_cid(const SrsContextId& cid);
|
||||
};
|
||||
|
||||
// A ST-coroutine is a lightweight thread, just like the goroutine.
|
||||
|
@ -138,8 +143,9 @@ public:
|
|||
// @remark Return ERROR_THREAD_TERMINATED when thread terminated normally without error.
|
||||
// @remark Return ERROR_THREAD_INTERRUPED when thread is interrupted.
|
||||
virtual srs_error_t pull();
|
||||
// Get the context id of thread.
|
||||
// Get and set the context id of thread.
|
||||
virtual const SrsContextId& cid();
|
||||
virtual void set_cid(const SrsContextId& cid);
|
||||
};
|
||||
|
||||
// High performance coroutine.
|
||||
|
@ -180,6 +186,7 @@ public:
|
|||
return srs_error_copy(trd_err);
|
||||
}
|
||||
const SrsContextId& cid();
|
||||
virtual void set_cid(const SrsContextId& cid);
|
||||
private:
|
||||
srs_error_t cycle();
|
||||
static void* pfn(void* arg);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue