1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

ST: Allow set the default stack size

This commit is contained in:
winlin 2020-10-22 17:06:36 +08:00
parent a14f26971b
commit 97880f6bb7
3 changed files with 21 additions and 2 deletions

View file

@ -82,6 +82,9 @@ srs_error_t SrsRecvThread::start()
srs_freep(trd); srs_freep(trd);
trd = new SrsSTCoroutine("recv", this, _parent_cid); trd = new SrsSTCoroutine("recv", this, _parent_cid);
//change stack size to 256K, fix crash when call some 3rd-part api.
((SrsSTCoroutine*)trd)->set_stack_size(1 << 18);
if ((err = trd->start()) != srs_success) { if ((err = trd->start()) != srs_success) {
return srs_error_wrap(err, "recv thread"); return srs_error_wrap(err, "recv thread");

View file

@ -83,11 +83,15 @@ _ST_THREAD_CREATE_PFN _pfn_st_thread_create = (_ST_THREAD_CREATE_PFN)st_thread_c
SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h) SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h)
{ {
// TODO: FIXME: Reduce duplicated code.
name = n; name = n;
handler = h; handler = h;
trd = NULL; trd = NULL;
trd_err = srs_success; trd_err = srs_success;
started = interrupted = disposed = cycle_done = false; started = interrupted = disposed = cycle_done = false;
// 0 use default, default is 64K.
stack_size = 0;
} }
SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h, SrsContextId cid) SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h, SrsContextId cid)
@ -98,6 +102,9 @@ SrsSTCoroutine::SrsSTCoroutine(string n, ISrsCoroutineHandler* h, SrsContextId c
trd = NULL; trd = NULL;
trd_err = srs_success; trd_err = srs_success;
started = interrupted = disposed = cycle_done = false; started = interrupted = disposed = cycle_done = false;
// 0 use default, default is 64K.
stack_size = 0;
} }
SrsSTCoroutine::~SrsSTCoroutine() SrsSTCoroutine::~SrsSTCoroutine()
@ -107,6 +114,11 @@ SrsSTCoroutine::~SrsSTCoroutine()
srs_freep(trd_err); srs_freep(trd_err);
} }
void SrsSTCoroutine::set_stack_size(int v)
{
stack_size = v;
}
srs_error_t SrsSTCoroutine::start() srs_error_t SrsSTCoroutine::start()
{ {
srs_error_t err = srs_success; srs_error_t err = srs_success;
@ -124,8 +136,8 @@ srs_error_t SrsSTCoroutine::start()
return err; return err;
} }
if ((trd = (srs_thread_t)_pfn_st_thread_create(pfn, this, 1, 0)) == NULL) { if ((trd = (srs_thread_t)_pfn_st_thread_create(pfn, this, 1, stack_size)) == NULL) {
err = srs_error_new(ERROR_ST_CREATE_CYCLE_THREAD, "create failed"); err = srs_error_new(ERROR_ST_CREATE_CYCLE_THREAD, "create failed");
srs_freep(trd_err); srs_freep(trd_err);

View file

@ -119,6 +119,7 @@ class SrsSTCoroutine : public SrsCoroutine
{ {
private: private:
std::string name; std::string name;
int stack_size;
ISrsCoroutineHandler* handler; ISrsCoroutineHandler* handler;
private: private:
srs_thread_t trd; srs_thread_t trd;
@ -136,6 +137,9 @@ public:
SrsSTCoroutine(std::string n, ISrsCoroutineHandler* h); SrsSTCoroutine(std::string n, ISrsCoroutineHandler* h);
SrsSTCoroutine(std::string n, ISrsCoroutineHandler* h, SrsContextId cid); SrsSTCoroutine(std::string n, ISrsCoroutineHandler* h, SrsContextId cid);
virtual ~SrsSTCoroutine(); virtual ~SrsSTCoroutine();
public:
// Set the stack size of coroutine, default to 0(64KB).
void set_stack_size(int v);
public: public:
// Start the thread. // Start the thread.
// @remark Should never start it when stopped or terminated. // @remark Should never start it when stopped or terminated.