mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Add SrsAutoFreeH to release ptr with hooks. (#2880). v4.0.226
This commit is contained in:
parent
73d0ce1cee
commit
3881c4c77e
3 changed files with 18 additions and 6 deletions
|
@ -8,7 +8,9 @@ The changelog for SRS.
|
||||||
|
|
||||||
## SRS 4.0 Changelog
|
## SRS 4.0 Changelog
|
||||||
|
|
||||||
* v4.0, 2022-01-14, Support api_port to specify the WebRTC API port. v4.0.224
|
* v4.0, 2022-01-13, For [#2880](https://github.com/ossrs/srs/pull/2880): Add SrsAutoFreeH to release ptr with hooks. (#2880). v4.0.226
|
||||||
|
* v4.0, 2022-01-13, Support api_port to specify the WebRTC API port. v4.0.226
|
||||||
|
* v4.0, 2022-01-13, Support api_port to specify the WebRTC API port. v4.0.224
|
||||||
* v4.0, 2022-01-13, Merge [#2873](https://github.com/ossrs/srs/pull/2873): LiveSource: Refine fetch for external exposed interface. (#2873). v4.0.223
|
* v4.0, 2022-01-13, Merge [#2873](https://github.com/ossrs/srs/pull/2873): LiveSource: Refine fetch for external exposed interface. (#2873). v4.0.223
|
||||||
* v4.0, 2022-01-13, Add conf/lighthouse.conf for LightHouse. v4.0.222
|
* v4.0, 2022-01-13, Add conf/lighthouse.conf for LightHouse. v4.0.222
|
||||||
* v4.0, 2022-01-12, Refine the running homepage. v4.0.221
|
* v4.0, 2022-01-12, Refine the running homepage. v4.0.221
|
||||||
|
|
|
@ -30,13 +30,16 @@
|
||||||
// where the char* pstr = new char[size].
|
// where the char* pstr = new char[size].
|
||||||
// To delete object.
|
// To delete object.
|
||||||
#define SrsAutoFree(className, instance) \
|
#define SrsAutoFree(className, instance) \
|
||||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false)
|
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false, NULL)
|
||||||
// To delete array.
|
// To delete array.
|
||||||
#define SrsAutoFreeA(className, instance) \
|
#define SrsAutoFreeA(className, instance) \
|
||||||
impl_SrsAutoFree<className> _auto_free_array_##instance(&instance, true, false)
|
impl_SrsAutoFree<className> _auto_free_array_##instance(&instance, true, false, NULL)
|
||||||
// Use free instead of delete.
|
// Use free instead of delete.
|
||||||
#define SrsAutoFreeF(className, instance) \
|
#define SrsAutoFreeF(className, instance) \
|
||||||
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, true)
|
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, true, NULL)
|
||||||
|
// Use hook instead of delete.
|
||||||
|
#define SrsAutoFreeH(className, instance, hook) \
|
||||||
|
impl_SrsAutoFree<className> _auto_free_##instance(&instance, false, false, hook)
|
||||||
// The template implementation.
|
// The template implementation.
|
||||||
template<class T>
|
template<class T>
|
||||||
class impl_SrsAutoFree
|
class impl_SrsAutoFree
|
||||||
|
@ -45,11 +48,16 @@ private:
|
||||||
T** ptr;
|
T** ptr;
|
||||||
bool is_array;
|
bool is_array;
|
||||||
bool _use_free;
|
bool _use_free;
|
||||||
|
void (*_hook)(T*);
|
||||||
public:
|
public:
|
||||||
impl_SrsAutoFree(T** p, bool array, bool use_free) {
|
// If use_free, use free(void*) to release the p.
|
||||||
|
// If specified hook, use hook(p) to release it.
|
||||||
|
// Use delete to release p, or delete[] if p is an array.
|
||||||
|
impl_SrsAutoFree(T** p, bool array, bool use_free, void (*hook)(T*)) {
|
||||||
ptr = p;
|
ptr = p;
|
||||||
is_array = array;
|
is_array = array;
|
||||||
_use_free = use_free;
|
_use_free = use_free;
|
||||||
|
_hook = hook;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~impl_SrsAutoFree() {
|
virtual ~impl_SrsAutoFree() {
|
||||||
|
@ -59,6 +67,8 @@ public:
|
||||||
|
|
||||||
if (_use_free) {
|
if (_use_free) {
|
||||||
free(*ptr);
|
free(*ptr);
|
||||||
|
} else if (_hook) {
|
||||||
|
_hook(*ptr);
|
||||||
} else {
|
} else {
|
||||||
if (is_array) {
|
if (is_array) {
|
||||||
delete[] *ptr;
|
delete[] *ptr;
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
#define VERSION_MAJOR 4
|
#define VERSION_MAJOR 4
|
||||||
#define VERSION_MINOR 0
|
#define VERSION_MINOR 0
|
||||||
#define VERSION_REVISION 225
|
#define VERSION_REVISION 226
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue