mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
SmartPtr: Use shared ptr to manage GB objects. v6.0.126 (#4080)
The object relations:

Session manages SIP and Media object using shared resource or shared
ptr. Note that I actually use SrsExecutorCoroutine to delete the object
when each coroutine is done, because there is always a dedicate
coroutine for each object.
For SIP and Media object, they directly use the session by raw pointer,
it's safe because session always live longer than session and media
object.
---
Co-authored-by: Jacob Su <suzp1984@gmail.com>
This commit is contained in:
parent
1656391c67
commit
6834ec208d
15 changed files with 989 additions and 464 deletions
|
@ -33,7 +33,9 @@ public:
|
|||
ISrsResourceManager();
|
||||
virtual ~ISrsResourceManager();
|
||||
public:
|
||||
// Remove then free the specified connection.
|
||||
// Remove then free the specified connection. Note that the manager always free c resource,
|
||||
// in the same coroutine or another coroutine. Some manager may support add c to a map, it
|
||||
// should always free it even if it's in the map.
|
||||
virtual void remove(ISrsResource* c) = 0;
|
||||
};
|
||||
|
||||
|
@ -48,36 +50,5 @@ public:
|
|||
virtual std::string remote_ip() = 0;
|
||||
};
|
||||
|
||||
// Lazy-sweep resource, never sweep util all wrappers are freed.
|
||||
// See https://github.com/ossrs/srs/issues/3176#lazy-sweep
|
||||
class SrsLazyObject
|
||||
{
|
||||
private:
|
||||
// The reference count of resource, 0 is no wrapper and safe to sweep.
|
||||
int32_t gc_ref_;
|
||||
public:
|
||||
SrsLazyObject();
|
||||
virtual ~SrsLazyObject();
|
||||
public:
|
||||
// For wrapper to use this resource.
|
||||
virtual void gc_use();
|
||||
// For wrapper to dispose this resource.
|
||||
virtual void gc_dispose();
|
||||
// The current reference count of resource.
|
||||
virtual int32_t gc_ref();
|
||||
};
|
||||
|
||||
// The lazy-sweep GC, wait for a long time to dispose resource even when resource is disposable.
|
||||
// See https://github.com/ossrs/srs/issues/3176#lazy-sweep
|
||||
class ISrsLazyGc
|
||||
{
|
||||
public:
|
||||
ISrsLazyGc();
|
||||
virtual ~ISrsLazyGc();
|
||||
public:
|
||||
// Remove then free the specified resource.
|
||||
virtual void remove(SrsLazyObject* c) = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue