# HG changeset patch # User John Tsiombikas # Date 1391826068 -7200 # Node ID 84f55eab27cb3fd8c854e37db6ae101e84c25dae # Parent bebc065a941fdc808ed732bc7e56c547c6282bf2 ok now it sortof works, probably something is failing in the done callback mechanism diff -r bebc065a941f -r 84f55eab27cb examples/imgthumbs/src/thumbs.c --- a/examples/imgthumbs/src/thumbs.c Fri Feb 07 07:50:02 2014 +0200 +++ b/examples/imgthumbs/src/thumbs.c Sat Feb 08 04:21:08 2014 +0200 @@ -67,7 +67,7 @@ node->aspect = 1.0;/*(float)xsz / (float)ysz;*/ - resman_lookup(texman, node->fname, 0); + resman_lookup(texman, node->fname, node); /*if(!(pixels = img_load_pixels(node->fname, &xsz, &ysz, IMG_FMT_RGBA32))) { free(node->fname); @@ -131,11 +131,6 @@ glMatrixMode(GL_MODELVIEW); while(thumbs) { - if(!thumbs->tex) { - thumbs = thumbs->next; - continue; - } - glPushMatrix(); glTranslatef(x, y, 0); @@ -149,28 +144,34 @@ glTexCoord2f(0, 1); glVertex2f(0, 1); glEnd(); - if(thumbs->aspect >= 1.0) { - glTranslatef(0, 0.5 - 0.5 / thumbs->aspect, 0); - glScalef(1, 1.0 / thumbs->aspect, 1); - } else { - glTranslatef(0.5 - thumbs->aspect / 2.0, 0, 0); - glScalef(thumbs->aspect, 1, 1); + if(thumbs->tex) { + if(thumbs->aspect >= 1.0) { + glTranslatef(0, 0.5 - 0.5 / thumbs->aspect, 0); + glScalef(1, 1.0 / thumbs->aspect, 1); + } else { + glTranslatef(0.5 - thumbs->aspect / 2.0, 0, 0); + glScalef(thumbs->aspect, 1, 1); + } + + if(glIsTexture(thumbs->tex)) { + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, thumbs->tex); + + glBegin(GL_QUADS); + glColor3f(1, 1, 1); + glTexCoord2f(0, 0); glVertex2f(0, 0); + glTexCoord2f(1, 0); glVertex2f(1, 0); + glTexCoord2f(1, 1); glVertex2f(1, 1); + glTexCoord2f(0, 1); glVertex2f(0, 1); + glEnd(); + } else { + fprintf(stderr, "invalid texture: %u\n", thumbs->tex); + } + + glPopMatrix(); + glDisable(GL_TEXTURE_2D); } - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, thumbs->tex); - - glBegin(GL_QUADS); - glColor3f(1, 1, 1); - glTexCoord2f(0, 0); glVertex2f(0, 0); - glTexCoord2f(1, 0); glVertex2f(1, 0); - glTexCoord2f(1, 1); glVertex2f(1, 1); - glTexCoord2f(0, 1); glVertex2f(0, 1); - glEnd(); - - glPopMatrix(); - glDisable(GL_TEXTURE_2D); - thumbs->layout_pos[0] = x; thumbs->layout_pos[1] = y; thumbs->layout_size[0] = thumb_sz; @@ -192,8 +193,7 @@ static int load_res_texture(const char *fname, int id, void *cls) { - struct resman *rman = cls; - struct thumbnail *rdata = resman_get_res_data(rman, id); + struct thumbnail *rdata = resman_get_res_data(texman, id); assert(rdata); if(!rdata->img) { @@ -202,7 +202,7 @@ } } - if(!img_load(rdata->img, fname) == -1) { + if(img_load(rdata->img, fname) == -1) { img_free(rdata->img); return -1; } @@ -210,21 +210,20 @@ /* set the resource's data to the loaded image, so that we can use * it in the done callback */ - resman_set_res_data(rman, id, rdata); + resman_set_res_data(texman, id, rdata); return 0; } static int done_res_texture(int id, void *cls) { struct thumbnail *rdata; - struct resman *rman = cls; - rdata = resman_get_res_data(rman, id); + rdata = resman_get_res_data(texman, id); - if(resman_get_res_result(rman, id) != 0 || !rdata) { - fprintf(stderr, "failed to load resource %d (%s)\n", id, resman_get_res_name(rman, id)); + if(resman_get_res_result(texman, id) != 0 || !rdata) { + fprintf(stderr, "failed to load resource %d (%s)\n", id, resman_get_res_name(texman, id)); } else { - printf("done loading resource %d (%s)\n", id, resman_get_res_name(rman, id)); + printf("done loading resource %d (%s)\n", id, resman_get_res_name(texman, id)); } if(!rdata->tex) { @@ -241,8 +240,7 @@ static void free_res_texture(int id, void *cls) { - struct resman *rman = cls; - struct thumbnail *rdata = resman_get_res_data(rman, id); + struct thumbnail *rdata = resman_get_res_data(texman, id); if(rdata) { if(rdata->tex) { diff -r bebc065a941f -r 84f55eab27cb src/resman.c --- a/src/resman.c Fri Feb 07 07:50:02 2014 +0200 +++ b/src/resman.c Sat Feb 08 04:21:08 2014 +0200 @@ -132,8 +132,10 @@ for(i=0; ires[i]; + printf("locking mutex %d\n", res->id); pthread_mutex_lock(&res->done_lock); if(!res->done_pending) { + printf(" unlocking mutex %d\n", res->id); pthread_mutex_unlock(&res->done_lock); continue; } @@ -141,6 +143,7 @@ /* so a done callback *is* pending... */ res->done_pending = 0; rman->done_func(i, rman->done_func_cls); + printf(" unlocking mutex %d\n", res->id); pthread_mutex_unlock(&res->done_lock); } return 0; @@ -203,6 +206,8 @@ assert(res->name); res->data = data; + pthread_mutex_init(&res->done_lock, 0); + if(!(tmparr = dynarr_push(rman->res, &res))) { free(res); return -1; @@ -223,7 +228,10 @@ struct resman *rman = cls; res->result = rman->load_func(res->name, res->id, rman->load_func_cls); + + printf("locking mutex %d\n", res->id); pthread_mutex_lock(&res->done_lock); res->done_pending = 1; + printf(" unlocking mutex %d\n", res->id); pthread_mutex_unlock(&res->done_lock); } diff -r bebc065a941f -r 84f55eab27cb src/threadpool.c --- a/src/threadpool.c Fri Feb 07 07:50:02 2014 +0200 +++ b/src/threadpool.c Sat Feb 08 04:21:08 2014 +0200 @@ -122,8 +122,10 @@ tpool->work_list_tail->next = node; tpool->work_list_tail = node; } + pthread_mutex_unlock(&tpool->work_lock); - pthread_mutex_unlock(&tpool->work_lock); + /* wakeup all threads, there's work to do */ + pthread_cond_broadcast(&tpool->work_cond); return 0; }