Skip to content

Commit dc20d5d

Browse files
committed
ST: Support set context id while thread running. v5.0.72
1 parent 9525511 commit dc20d5d

File tree

12 files changed

+96
-15
lines changed

12 files changed

+96
-15
lines changed

trunk/3rdparty/st-srs/key.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ int st_key_getlimit(void)
7979
int st_thread_setspecific(int key, void *value)
8080
{
8181
_st_thread_t *me = _ST_CURRENT_THREAD();
82-
82+
return st_thread_setspecific2(me, key, value);
83+
}
84+
85+
86+
int st_thread_setspecific2(_st_thread_t *me, int key, void *value)
87+
{
8388
if (key < 0 || key >= key_max) {
8489
errno = EINVAL;
8590
return -1;

trunk/3rdparty/st-srs/public.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ extern int st_sendmsg(st_netfd_t fd, const struct msghdr *msg, int flags, st_uti
156156

157157
extern st_netfd_t st_open(const char *path, int oflags, mode_t mode);
158158

159+
extern int st_thread_setspecific2(st_thread_t thread, int key, void *value);
160+
159161
#ifdef DEBUG
160162
extern void _st_show_thread_stack(st_thread_t thread, const char *messg);
161163
extern void _st_iterate_threads(void);

trunk/3rdparty/st-srs/sched.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,6 @@ _st_thread_t *st_thread_self(void)
689689
return _ST_CURRENT_THREAD();
690690
}
691691

692-
693692
#ifdef DEBUG
694693
/* ARGSUSED */
695694
void _st_show_thread_stack(_st_thread_t *thread, const char *messg)

trunk/doc/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The changelog for SRS.
77

88
## SRS 5.0 Changelog
99

10+
* v5.0, 2022-10-02, ST: Support set context id while thread running. v5.0.72
1011
* v5.0, 2022-09-30, RTC: Refine SDP to support GB28181 SSRC spec. v5.0.71
1112
* v5.0, 2022-09-30, GB28181: Refine HTTP parser to support SIP. v5.0.70
1213
* v5.0, 2022-09-30, Kernel: Support lazy sweeping simple GC. v5.0.69

trunk/src/app/srs_app_st.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,12 @@ srs_error_t SrsDummyCoroutine::pull()
6666

6767
const SrsContextId& SrsDummyCoroutine::cid()
6868
{
69-
return _srs_context->get_id();
69+
return cid_;
70+
}
71+
72+
void SrsDummyCoroutine::set_cid(const SrsContextId& cid)
73+
{
74+
cid_ = cid;
7075
}
7176

7277
SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h)
@@ -114,6 +119,11 @@ const SrsContextId& SrsSTCoroutine::cid()
114119
return impl_->cid();
115120
}
116121

122+
void SrsSTCoroutine::set_cid(const SrsContextId& cid)
123+
{
124+
impl_->set_cid(cid);
125+
}
126+
117127
SrsFastCoroutine::SrsFastCoroutine(string n, ISrsCoroutineHandler* h)
118128
{
119129
// TODO: FIXME: Reduce duplicated code.
@@ -257,6 +267,12 @@ const SrsContextId& SrsFastCoroutine::cid()
257267
return cid_;
258268
}
259269

270+
void SrsFastCoroutine::set_cid(const SrsContextId& cid)
271+
{
272+
cid_ = cid;
273+
srs_context_set_cid_of(trd, cid);
274+
}
275+
260276
srs_error_t SrsFastCoroutine::cycle()
261277
{
262278
if (_srs_context) {

trunk/src/app/srs_app_st.hpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ class SrsCoroutine : public ISrsStartable
7676
// @return a copy of error, which should be freed by user.
7777
// NULL if not terminated and user should pull again.
7878
virtual srs_error_t pull() = 0;
79+
// Get and set the context id of coroutine.
7980
virtual const SrsContextId& cid() = 0;
81+
virtual void set_cid(const SrsContextId& cid) = 0;
8082
};
8183

8284
// An empty coroutine, user can default to this object before create any real coroutine.
8385
// @see https://github.com/ossrs/srs/pull/908
8486
class SrsDummyCoroutine : public SrsCoroutine
8587
{
88+
private:
89+
SrsContextId cid_;
8690
public:
8791
SrsDummyCoroutine();
8892
virtual ~SrsDummyCoroutine();
@@ -92,6 +96,7 @@ class SrsDummyCoroutine : public SrsCoroutine
9296
virtual void interrupt();
9397
virtual srs_error_t pull();
9498
virtual const SrsContextId& cid();
99+
virtual void set_cid(const SrsContextId& cid);
95100
};
96101

97102
// A ST-coroutine is a lightweight thread, just like the goroutine.
@@ -138,8 +143,9 @@ class SrsSTCoroutine : public SrsCoroutine
138143
// @remark Return ERROR_THREAD_TERMINATED when thread terminated normally without error.
139144
// @remark Return ERROR_THREAD_INTERRUPED when thread is interrupted.
140145
virtual srs_error_t pull();
141-
// Get the context id of thread.
146+
// Get and set the context id of thread.
142147
virtual const SrsContextId& cid();
148+
virtual void set_cid(const SrsContextId& cid);
143149
};
144150

145151
// High performance coroutine.
@@ -180,6 +186,7 @@ class SrsFastCoroutine
180186
return srs_error_copy(trd_err);
181187
}
182188
const SrsContextId& cid();
189+
virtual void set_cid(const SrsContextId& cid);
183190
private:
184191
srs_error_t cycle();
185192
static void* pfn(void* arg);

trunk/src/core/srs_core_version5.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 5
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 71
12+
#define VERSION_REVISION 72
1313

1414
#endif

trunk/src/protocol/srs_protocol_log.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,19 @@ const SrsContextId& SrsThreadContext::get_id()
6262
}
6363

6464
const SrsContextId& SrsThreadContext::set_id(const SrsContextId& v)
65+
{
66+
return srs_context_set_cid_of(srs_thread_self(), v);
67+
}
68+
69+
void SrsThreadContext::clear_cid()
70+
{
71+
}
72+
73+
const SrsContextId& srs_context_set_cid_of(srs_thread_t trd, const SrsContextId& v)
6574
{
6675
++_srs_pps_cids_set->sugar;
6776

68-
if (!srs_thread_self()) {
77+
if (!trd) {
6978
_srs_context_default = v;
7079
return v;
7180
}
@@ -78,16 +87,12 @@ const SrsContextId& SrsThreadContext::set_id(const SrsContextId& v)
7887
srs_assert(r0 == 0);
7988
}
8089

81-
int r0 = srs_thread_setspecific(_srs_context_key, cid);
90+
int r0 = srs_thread_setspecific2(trd, _srs_context_key, cid);
8291
srs_assert(r0 == 0);
8392

8493
return v;
8594
}
8695

87-
void SrsThreadContext::clear_cid()
88-
{
89-
}
90-
9196
impl_SrsContextRestore::impl_SrsContextRestore(SrsContextId cid)
9297
{
9398
cid_ = cid;

trunk/src/protocol/srs_protocol_log.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ class SrsThreadContext : public ISrsContext
2828
virtual SrsContextId generate_id();
2929
virtual const SrsContextId& get_id();
3030
virtual const SrsContextId& set_id(const SrsContextId& v);
31-
public:
31+
private:
3232
virtual void clear_cid();
3333
};
3434

35+
// Set the context id of specified thread, not self.
36+
extern const SrsContextId& srs_context_set_cid_of(srs_thread_t trd, const SrsContextId& v);
37+
3538
// The context restore stores the context and restore it when done.
3639
// Usage:
3740
// SrsContextRestore(_srs_context->get_id());

trunk/src/protocol/srs_protocol_st.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,11 @@ void *srs_thread_getspecific(int key)
412412
return st_thread_getspecific(key);
413413
}
414414

415+
int srs_thread_setspecific2(srs_thread_t thread, int key, void* value)
416+
{
417+
return st_thread_setspecific2((st_thread_t)thread, key, value);
418+
}
419+
415420
int srs_netfd_fileno(srs_netfd_t stfd)
416421
{
417422
return st_netfd_fileno((st_netfd_t)stfd);

0 commit comments

Comments
 (0)