X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_resource_factory.c;h=0813755f06328e47a657f07dd711b8e4b10031ca;hp=390d882c155425753396a0b912d44b830aa899f9;hb=517336efe27e1f8e58e36352478a6d9ffdcdf378;hpb=8d05291f42b3b42159b3fe91492aa4862f3d4405 diff --git a/php_http_resource_factory.c b/php_http_resource_factory.c index 390d882..0813755 100644 --- a/php_http_resource_factory.c +++ b/php_http_resource_factory.c @@ -10,8 +10,7 @@ +--------------------------------------------------------------------+ */ -#include "php_http.h" -#include "php_http_resource_factory.h" +#include "php_http_api.h" PHP_HTTP_API php_http_resource_factory_t *php_http_resource_factory_init(php_http_resource_factory_t *f, php_http_resource_factory_ops_t *fops, void *data, void (*dtor)(void *data)) { @@ -25,21 +24,35 @@ PHP_HTTP_API php_http_resource_factory_t *php_http_resource_factory_init(php_htt f->data = data; f->dtor = dtor; + f->refcount = 1; + return f; } +PHP_HTTP_API unsigned php_http_resource_factory_addref(php_http_resource_factory_t *rf) +{ + return ++rf->refcount; +} + PHP_HTTP_API void php_http_resource_factory_dtor(php_http_resource_factory_t *f) { - if (f->dtor) { - f->dtor(f->data); + --f->refcount; + + if (!f->refcount) { + if (f->dtor) { + f->dtor(f->data); + } } } + PHP_HTTP_API void php_http_resource_factory_free(php_http_resource_factory_t **f) { if (*f) { php_http_resource_factory_dtor(*f); - efree(*f); - *f = NULL; + if (!(*f)->refcount) { + efree(*f); + *f = NULL; + } } }