X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_resource_factory.c;h=0813755f06328e47a657f07dd711b8e4b10031ca;hp=c3ff6f5ff2eeaa5d85ad4b721c335b550504e57b;hb=517336efe27e1f8e58e36352478a6d9ffdcdf378;hpb=3bd8d6a6081a83d468b23425c7659893c82aeafb diff --git a/php_http_resource_factory.c b/php_http_resource_factory.c index c3ff6f5..0813755 100644 --- a/php_http_resource_factory.c +++ b/php_http_resource_factory.c @@ -6,14 +6,11 @@ | modification, are permitted provided that the conditions mentioned | | in the accompanying LICENSE file are met. | +--------------------------------------------------------------------+ - | Copyright (c) 2004-2010, Michael Wallner | + | Copyright (c) 2004-2011, Michael Wallner | +--------------------------------------------------------------------+ */ -/* $Id:$ */ - -#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)) { @@ -27,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; + } } }