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

Fix #908, use empty coroutine to avoid NULL pointer.

This commit is contained in:
winlin 2017-06-04 19:13:56 +08:00
parent 0e9e1792fe
commit 9ca36970aa
17 changed files with 115 additions and 41 deletions

View file

@ -67,6 +67,39 @@ public:
virtual int cycle() = 0;
};
/**
* The corotine object.
*/
class SrsCoroutine
{
public:
SrsCoroutine();
virtual ~SrsCoroutine();
public:
virtual int start() = 0;
virtual void stop() = 0;
virtual void interrupt() = 0;
virtual int pull() = 0;
virtual int 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
{
public:
SrsDummyCoroutine();
virtual ~SrsDummyCoroutine();
public:
virtual int start();
virtual void stop();
virtual void interrupt();
virtual int pull();
virtual int cid();
};
/**
* A ST-coroutine is a lightweight thread, just like the goroutine.
* But the goroutine maybe run on different thread, while ST-coroutine only
@ -81,7 +114,7 @@ public:
* @remark We always create joinable thread, so we must join it or memory leak,
* Please read https://github.com/ossrs/srs/issues/78
*/
class SrsCoroutine
class SrsSTCoroutine : public SrsCoroutine
{
private:
std::string name;
@ -97,8 +130,8 @@ private:
public:
// Create a thread with name n and handler h.
// @remark User can specify a cid for thread to use, or we will allocate a new one.
SrsCoroutine(const std::string& n, ISrsCoroutineHandler* h, int cid = 0);
virtual ~SrsCoroutine();
SrsSTCoroutine(const std::string& n, ISrsCoroutineHandler* h, int cid = 0);
virtual ~SrsSTCoroutine();
public:
/**
* Start the thread.