1
0
Fork 0
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:
winlin 2022-10-02 10:05:01 +08:00
parent 9525511032
commit dc20d5ddbc
12 changed files with 96 additions and 15 deletions

View file

@ -133,7 +133,7 @@ VOID TEST(AppCoroutineTest, Dummy)
if (true) {
SrsContextId v = dc.cid();
EXPECT_FALSE(v.empty());
EXPECT_TRUE(v.empty());
srs_error_t err = dc.pull();
EXPECT_TRUE(err != srs_success);
@ -150,7 +150,7 @@ VOID TEST(AppCoroutineTest, Dummy)
dc.stop();
SrsContextId v = dc.cid();
EXPECT_FALSE(v.empty());
EXPECT_TRUE(v.empty());
srs_error_t err = dc.pull();
EXPECT_TRUE(err != srs_success);
@ -167,7 +167,7 @@ VOID TEST(AppCoroutineTest, Dummy)
dc.interrupt();
SrsContextId v = dc.cid();
EXPECT_FALSE(v.empty());
EXPECT_TRUE(v.empty());
srs_error_t err = dc.pull();
EXPECT_TRUE(err != srs_success);
@ -205,6 +205,8 @@ public:
srs_error_t r0 = srs_success;
srs_cond_signal(running);
// The cid should be generated if empty.
cid = _srs_context->get_id();
while (!quit && (r0 = trd->pull()) == srs_success && err == srs_success) {
@ -213,6 +215,9 @@ public:
srs_cond_signal(exited);
// The cid might be updated.
cid = _srs_context->get_id();
if (err != srs_success) {
srs_freep(r0);
return err;
@ -222,6 +227,38 @@ public:
}
};
VOID TEST(AppCoroutineTest, SetCidOfCoroutine)
{
srs_error_t err = srs_success;
MockCoroutineHandler ch;
SrsSTCoroutine sc("test", &ch);
ch.trd = ≻
EXPECT_TRUE(sc.cid().empty());
// Start coroutine, which will create the cid.
HELPER_ASSERT_SUCCESS(sc.start());
HELPER_ASSERT_SUCCESS(sc.pull());
srs_cond_timedwait(ch.running, 100 * SRS_UTIME_MILLISECONDS);
EXPECT_TRUE(!sc.cid().empty());
EXPECT_TRUE(!ch.cid.empty());
// Should be a new cid.
SrsContextId cid = _srs_context->generate_id();
EXPECT_TRUE(sc.cid().compare(cid) != 0);
EXPECT_TRUE(ch.cid.compare(cid) != 0);
// Set the cid and stop the coroutine.
sc.set_cid(cid);
sc.stop();
// Now the cid should be the new one.
srs_cond_timedwait(ch.exited, 100 * SRS_UTIME_MILLISECONDS);
EXPECT_TRUE(sc.cid().compare(cid) == 0);
EXPECT_TRUE(ch.cid.compare(cid) == 0);
}
VOID TEST(AppCoroutineTest, StartStop)
{
if (true) {