libresman

changeset 14:2fcd1fbb0d18

buggy piece of shit
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 10 Feb 2014 12:11:02 +0200
parents a42888d26839
children 2b8281a146af
files examples/imgthumbs/src/thumbs.c src/resman.c
diffstat 2 files changed, 37 insertions(+), 5 deletions(-) [+]
line diff
     1.1 --- a/examples/imgthumbs/src/thumbs.c	Sat Feb 08 07:41:39 2014 +0200
     1.2 +++ b/examples/imgthumbs/src/thumbs.c	Mon Feb 10 12:11:02 2014 +0200
     1.3 @@ -14,6 +14,7 @@
     1.4  #endif
     1.5  
     1.6  struct resman *texman;
     1.7 +struct thumbnail *dbg;
     1.8  
     1.9  static int load_res_texture(const char *fname, int id, void *cls);
    1.10  static int done_res_texture(int id, void *cls);
    1.11 @@ -26,6 +27,7 @@
    1.12  	struct dirent *dent;
    1.13  	/* allocate dummy head node */
    1.14  	struct thumbnail *list = calloc(1, sizeof *list);
    1.15 +	dbg = list;
    1.16  
    1.17  	/*unsigned int intfmt = GL_COMPRESSED_RGB;
    1.18  	if(!strstr((char*)glGetString(GL_EXTENSIONS), "GL_ARB_texture_compression")) {
    1.19 @@ -88,6 +90,7 @@
    1.20  
    1.21  		node->next = list->next;
    1.22  		node->prev = list;
    1.23 +		list->next = node;
    1.24  	}
    1.25  	closedir(dir);
    1.26  
    1.27 @@ -122,7 +125,7 @@
    1.28  	float view_aspect;
    1.29  
    1.30  	glGetIntegerv(GL_VIEWPORT, vp);
    1.31 -	view_aspect = (float)(vp[2] - vp[0]) / (vp[3] - vp[1]);
    1.32 +	view_aspect = (float)(vp[2] - vp[0]) / (float)(vp[3] - vp[1]);
    1.33  
    1.34  	glMatrixMode(GL_PROJECTION);
    1.35  	glPushMatrix();
    1.36 @@ -133,6 +136,7 @@
    1.37  
    1.38  	thumbs = thumbs->next;	/* skip dummy node */
    1.39  	while(thumbs) {
    1.40 +		printf("drawing thumb: %s\n", thumbs->fname);
    1.41  		glPushMatrix();
    1.42  		glTranslatef(x, y, 0);
    1.43  
    1.44 @@ -252,6 +256,8 @@
    1.45  {
    1.46  	struct thumbnail *thumb = resman_get_res_data(texman, id);
    1.47  
    1.48 +	printf("deleting thumb %d: %s\n", id, thumb->fname);
    1.49 +
    1.50  	if(thumb) {
    1.51  		if(thumb->tex) {
    1.52  			glDeleteTextures(1, &thumb->tex);
     2.1 --- a/src/resman.c	Sat Feb 08 07:41:39 2014 +0200
     2.2 +++ b/src/resman.c	Mon Feb 10 12:11:02 2014 +0200
     2.3 @@ -14,6 +14,7 @@
     2.4  	int result;	/* last callback-reported success/fail code */
     2.5  
     2.6  	int done_pending;
     2.7 +	int delete_pending;
     2.8  	pthread_mutex_t done_lock;
     2.9  };
    2.10  
    2.11 @@ -56,9 +57,16 @@
    2.12  
    2.13  int resman_init(struct resman *rman)
    2.14  {
    2.15 +	const char *env;
    2.16 +	int num_threads = TPOOL_AUTO;
    2.17 +
    2.18  	memset(rman, 0, sizeof *rman);
    2.19  
    2.20 -	if(!(rman->tpool = tpool_create(TPOOL_AUTO))) {
    2.21 +	if((env = getenv("RESMAN_THREADS"))) {
    2.22 +		num_threads = atoi(env);
    2.23 +	}
    2.24 +
    2.25 +	if(!(rman->tpool = tpool_create(num_threads))) {
    2.26  		return -1;
    2.27  	}
    2.28  	tpool_set_work_func(rman->tpool, work_func, rman);
    2.29 @@ -131,11 +139,27 @@
    2.30  {
    2.31  	int i, num_res;
    2.32  
    2.33 +	/* first check all the resources to see if any is pending deletion */
    2.34 +	num_res = dynarr_size(rman->res);
    2.35 +	for(i=0; i<num_res; i++) {
    2.36 +		struct resource *res = rman->res[i];
    2.37 +		if(!res) {
    2.38 +			continue;
    2.39 +		}
    2.40 +
    2.41 +		if(res->delete_pending) {
    2.42 +			if(rman->destroy_func) {
    2.43 +				rman->destroy_func(i, rman->destroy_func_cls);
    2.44 +			}
    2.45 +			remove_resource(rman, i);
    2.46 +		}
    2.47 +	}
    2.48 +
    2.49 +
    2.50  	if(!rman->done_func) {
    2.51  		return 0;	/* no done callback; there's no point in checking anything */
    2.52  	}
    2.53  
    2.54 -	num_res = dynarr_size(rman->res);
    2.55  	for(i=0; i<num_res; i++) {
    2.56  		struct resource *res = rman->res[i];
    2.57  		if(!res) {
    2.58 @@ -278,8 +302,10 @@
    2.59  
    2.60  	res->result = rman->load_func(res->name, res->id, rman->load_func_cls);
    2.61  	if(res->result == -1 && !rman->done_func) {
    2.62 -		/* if there's no done function and we got an error, remove the resource now */
    2.63 -		remove_resource(rman, res->id);
    2.64 +		/* if there's no done function and we got an error, mark this
    2.65 +		 * resource for deletion in the caller context
    2.66 +		 */
    2.67 +		res->delete_pending = 1;
    2.68  		return;
    2.69  	}
    2.70