# HG changeset patch # User John Tsiombikas # Date 1392027062 -7200 # Node ID 2fcd1fbb0d1879df8767955fe92cecb0937d4dd9 # Parent a42888d26839d867473908f49dac6a3da0eff435 buggy piece of shit diff -r a42888d26839 -r 2fcd1fbb0d18 examples/imgthumbs/src/thumbs.c --- a/examples/imgthumbs/src/thumbs.c Sat Feb 08 07:41:39 2014 +0200 +++ b/examples/imgthumbs/src/thumbs.c Mon Feb 10 12:11:02 2014 +0200 @@ -14,6 +14,7 @@ #endif struct resman *texman; +struct thumbnail *dbg; static int load_res_texture(const char *fname, int id, void *cls); static int done_res_texture(int id, void *cls); @@ -26,6 +27,7 @@ struct dirent *dent; /* allocate dummy head node */ struct thumbnail *list = calloc(1, sizeof *list); + dbg = list; /*unsigned int intfmt = GL_COMPRESSED_RGB; if(!strstr((char*)glGetString(GL_EXTENSIONS), "GL_ARB_texture_compression")) { @@ -88,6 +90,7 @@ node->next = list->next; node->prev = list; + list->next = node; } closedir(dir); @@ -122,7 +125,7 @@ float view_aspect; glGetIntegerv(GL_VIEWPORT, vp); - view_aspect = (float)(vp[2] - vp[0]) / (vp[3] - vp[1]); + view_aspect = (float)(vp[2] - vp[0]) / (float)(vp[3] - vp[1]); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -133,6 +136,7 @@ thumbs = thumbs->next; /* skip dummy node */ while(thumbs) { + printf("drawing thumb: %s\n", thumbs->fname); glPushMatrix(); glTranslatef(x, y, 0); @@ -252,6 +256,8 @@ { struct thumbnail *thumb = resman_get_res_data(texman, id); + printf("deleting thumb %d: %s\n", id, thumb->fname); + if(thumb) { if(thumb->tex) { glDeleteTextures(1, &thumb->tex); diff -r a42888d26839 -r 2fcd1fbb0d18 src/resman.c --- a/src/resman.c Sat Feb 08 07:41:39 2014 +0200 +++ b/src/resman.c Mon Feb 10 12:11:02 2014 +0200 @@ -14,6 +14,7 @@ int result; /* last callback-reported success/fail code */ int done_pending; + int delete_pending; pthread_mutex_t done_lock; }; @@ -56,9 +57,16 @@ int resman_init(struct resman *rman) { + const char *env; + int num_threads = TPOOL_AUTO; + memset(rman, 0, sizeof *rman); - if(!(rman->tpool = tpool_create(TPOOL_AUTO))) { + if((env = getenv("RESMAN_THREADS"))) { + num_threads = atoi(env); + } + + if(!(rman->tpool = tpool_create(num_threads))) { return -1; } tpool_set_work_func(rman->tpool, work_func, rman); @@ -131,11 +139,27 @@ { int i, num_res; + /* first check all the resources to see if any is pending deletion */ + num_res = dynarr_size(rman->res); + for(i=0; ires[i]; + if(!res) { + continue; + } + + if(res->delete_pending) { + if(rman->destroy_func) { + rman->destroy_func(i, rman->destroy_func_cls); + } + remove_resource(rman, i); + } + } + + if(!rman->done_func) { return 0; /* no done callback; there's no point in checking anything */ } - num_res = dynarr_size(rman->res); for(i=0; ires[i]; if(!res) { @@ -278,8 +302,10 @@ res->result = rman->load_func(res->name, res->id, rman->load_func_cls); if(res->result == -1 && !rman->done_func) { - /* if there's no done function and we got an error, remove the resource now */ - remove_resource(rman, res->id); + /* if there's no done function and we got an error, mark this + * resource for deletion in the caller context + */ + res->delete_pending = 1; return; }