+--------------------------------------------------------------------+
*/
-#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))
{
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;
+ }
}
}