Browse Source

now asset is by itself hashable...and the leaking issue seems to be fixed.

release0.1.5
Georg Hopp 12 years ago
parent
commit
3289d758c9
  1. 2
      include/asset.h
  2. 25
      src/asset/asset.c
  3. 16
      src/asset/pool.c
  4. 15
      src/hash/delete.c

2
include/asset.h

@ -32,6 +32,8 @@
CLASS(Asset) { CLASS(Asset) {
unsigned long hash;
char fname[2048]; char fname[2048];
char etag[200]; char etag[200];
char mtime[200]; char mtime[200];

25
src/asset/asset.c

@ -39,8 +39,11 @@
#include "class.h" #include "class.h"
#include "asset.h" #include "asset.h"
#include "hash.h"
#include "utils/mime_type.h" #include "utils/mime_type.h"
#include "utils/hash.h"
static static
int int
@ -58,6 +61,10 @@ assetCtor(void * _this, va_list * params)
strncpy(this->fname, fname, 2047); strncpy(this->fname, fname, 2047);
this->fname[2048] = '\0'; this->fname[2048] = '\0';
this->hash = sdbm(
(unsigned char *)this->fname,
this->nfname);
if (-1 == access(this->fname, O_RDONLY)) { if (-1 == access(this->fname, O_RDONLY)) {
return -1; return -1;
} else { } else {
@ -110,7 +117,23 @@ static void assetDtor(void * _this) {
} }
} }
static
unsigned long
assetGetHash(void * _this)
{
Asset this = _this;
return this->hash;
}
static
void
assetHandleDouble(void * _this, void * _doub)
{
}
INIT_IFACE(Class, assetCtor, assetDtor, NULL); INIT_IFACE(Class, assetCtor, assetDtor, NULL);
CREATE_CLASS(Asset, NULL, IFACE(Class));
INIT_IFACE(Hashable, assetGetHash, assetHandleDouble);
CREATE_CLASS(Asset, NULL, IFACE(Class), IFACE(Hashable));
// vim: set ts=4 sw=4: // vim: set ts=4 sw=4:

16
src/asset/pool.c

@ -36,9 +36,7 @@ inline
void void
freeAsset(const void * _node) freeAsset(const void * _node)
{ {
Asset node = (Asset)_node;
delete(node);
delete(_node);
} }
Asset Asset
@ -54,9 +52,7 @@ assetPoolGet(const char * path, size_t npath)
if (NULL == asset) { if (NULL == asset) {
asset = new(Asset, path, npath); asset = new(Asset, path, npath);
hashAdd(asset_pool,
new(HashValue, path, npath, asset, sizeof(Asset)));
hashAdd(asset_pool, asset);
} else { } else {
asset->ref_count++; asset->ref_count++;
} }
@ -68,8 +64,11 @@ size_t
assetPoolRelease(Asset asset) assetPoolRelease(Asset asset)
{ {
if (asset->ref_count <= 1) { if (asset->ref_count <= 1) {
hashDelete(asset_pool, asset->fname, asset->nfname);
delete(asset);
hashDelete( asset_pool, asset->fname, asset->nfname);
if (NULL != asset) {
delete(asset);
}
return 0; return 0;
} else { } else {
@ -83,6 +82,7 @@ void
assetPoolCleanup(void) assetPoolCleanup(void)
{ {
hashEach(asset_pool, freeAsset); hashEach(asset_pool, freeAsset);
delete(asset_pool);
} }
// vim: set ts=4 sw=4: // vim: set ts=4 sw=4:

15
src/hash/delete.c

@ -37,10 +37,19 @@ hashDeleteComp(const void * a, const void * b)
void * void *
hashDelete(Hash this, const char * search, size_t nsearch) hashDelete(Hash this, const char * search, size_t nsearch)
{ {
unsigned long hash = sdbm((const unsigned char *)search, nsearch);
void * found = tdelete(&hash, &(this->root), hashDeleteComp);
unsigned long hash = sdbm((const unsigned char *)search, nsearch);
void ** _found = tfind(&hash, &(this->root), hashDeleteComp);
void * found;
return (NULL != found)? *(void**)found : NULL;
if (NULL != _found) {
found = *_found;
} else {
found = NULL;
}
tdelete(&hash, &(this->root), hashDeleteComp);
return (NULL != found)? found : NULL;
} }
// vim: set ts=4 sw=4: // vim: set ts=4 sw=4:
Loading…
Cancel
Save