libresman
changeset 18:711698580eb0
fixed visual studio build directories
fixed debug id problem with the thread pool
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 12 Feb 2014 06:53:30 +0200 |
parents | 43a9fe4a80ee |
children | ee117b67b3e5 |
files | examples/imgthumbs/src/thumbs.c libresman-static.vcproj src/threadpool.c |
diffstat | 3 files changed, 28 insertions(+), 14 deletions(-) [+] |
line diff
1.1 --- a/examples/imgthumbs/src/thumbs.c Tue Feb 11 18:48:24 2014 +0200 1.2 +++ b/examples/imgthumbs/src/thumbs.c Wed Feb 12 06:53:30 2014 +0200 1.3 @@ -9,7 +9,7 @@ 1.4 #include "thumbs.h" 1.5 #include "resman.h" 1.6 1.7 -#define DBG_SYNC 1.8 +#undef DBG_SYNC 1.9 1.10 #ifndef GL_COMPRESSED_RGB 1.11 #define GL_COMPRESSED_RGB 0x84ed 1.12 @@ -45,8 +45,7 @@ 1.13 1.14 while((dent = readdir(dir))) { 1.15 #ifdef DBG_SYNC 1.16 - int xsz, ysz; 1.17 - unsigned char *pixels; 1.18 + struct img_pixmap img; 1.19 #endif 1.20 struct thumbnail *node; 1.21 1.22 @@ -71,7 +70,9 @@ 1.23 #ifndef DBG_SYNC 1.24 resman_lookup(texman, node->fname, node); 1.25 #else 1.26 - if(!(pixels = img_load_pixels(node->fname, &xsz, &ysz, IMG_FMT_RGBA32))) { 1.27 + img_init(&img); 1.28 + if(img_load(&img, node->fname) == -1) { 1.29 + img_destroy(&img); 1.30 free(node->fname); 1.31 free(node); 1.32 continue; 1.33 @@ -79,14 +80,14 @@ 1.34 1.35 printf("loaded image: %s\n", node->fname); 1.36 1.37 + node->aspect = (float)img.width / (float)img.height; 1.38 + 1.39 glGenTextures(1, &node->tex); 1.40 glBindTexture(GL_TEXTURE_2D, node->tex); 1.41 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.42 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.43 - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, xsz, ysz, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels); 1.44 - img_free_pixels(pixels); 1.45 - 1.46 - node->aspect = (float)xsz / (float)ysz; 1.47 + glTexImage2D(GL_TEXTURE_2D, 0, img_glintfmt(&img), img.width, img.height, 0, img_glfmt(&img), img_gltype(&img), img.pixels); 1.48 + img_destroy(&img); 1.49 #endif 1.50 1.51 node->next = list->next;
2.1 --- a/libresman-static.vcproj Tue Feb 11 18:48:24 2014 +0200 2.2 +++ b/libresman-static.vcproj Wed Feb 12 06:53:30 2014 +0200 2.3 @@ -18,7 +18,7 @@ 2.4 <Configurations> 2.5 <Configuration 2.6 Name="Debug|Win32" 2.7 - OutputDirectory="$(SolutionDir)$(ConfigurationName)" 2.8 + OutputDirectory="$(SolutionDir)$(ConfigurationName)-static" 2.9 IntermediateDirectory="$(ConfigurationName)" 2.10 ConfigurationType="4" 2.11 CharacterSet="1" 2.12 @@ -80,7 +80,7 @@ 2.13 </Configuration> 2.14 <Configuration 2.15 Name="Release|Win32" 2.16 - OutputDirectory="$(SolutionDir)$(ConfigurationName)" 2.17 + OutputDirectory="$(SolutionDir)$(ConfigurationName)-static" 2.18 IntermediateDirectory="$(ConfigurationName)" 2.19 ConfigurationType="4" 2.20 CharacterSet="1"
3.1 --- a/src/threadpool.c Tue Feb 11 18:48:24 2014 +0200 3.2 +++ b/src/threadpool.c Wed Feb 12 06:53:30 2014 +0200 3.3 @@ -17,6 +17,9 @@ 3.4 pthread_mutex_t work_lock; 3.5 pthread_cond_t work_cond; 3.6 3.7 + int start; 3.8 + pthread_cond_t start_cond; 3.9 + 3.10 tpool_work_func work_func; 3.11 void *cls; 3.12 3.13 @@ -55,6 +58,9 @@ 3.14 return -1; 3.15 } 3.16 3.17 + /* this start condvar is pretty useless */ 3.18 + pthread_cond_init(&tpool->start_cond, 0); 3.19 + 3.20 for(i=0; i<num_threads; i++) { 3.21 if(pthread_create(tpool->workers + i, 0, thread_func, tpool) == -1) { 3.22 fprintf(stderr, "%s: failed to create thread %d\n", __FUNCTION__, i); 3.23 @@ -62,6 +68,8 @@ 3.24 return -1; 3.25 } 3.26 } 3.27 + tpool->start = 1; 3.28 + pthread_cond_broadcast(&tpool->start_cond); 3.29 return 0; 3.30 } 3.31 3.32 @@ -142,8 +150,15 @@ 3.33 struct thread_pool *tpool = tp; 3.34 pthread_t tid = pthread_self(); 3.35 3.36 + /* wait for the start signal :) */ 3.37 + pthread_mutex_lock(&tpool->work_lock); 3.38 + while(!tpool->start) { 3.39 + pthread_cond_wait(&tpool->start_cond, &tpool->work_lock); 3.40 + } 3.41 + pthread_mutex_unlock(&tpool->work_lock); 3.42 + 3.43 for(i=0; i<tpool->num_workers; i++) { 3.44 - if(tpool[i].workers[i] == tid) { 3.45 + if(pthread_equal(tpool->workers[i], tid)) { 3.46 tidx = i; 3.47 break; 3.48 } 3.49 @@ -157,13 +172,11 @@ 3.50 continue; /* spurious wakeup, go back to sleep */ 3.51 } 3.52 3.53 - printf("TPOOL: worker %d start job: %d\n", tidx, job->id); 3.54 - 3.55 job = tpool->work_list; 3.56 tpool->work_list = tpool->work_list->next; 3.57 3.58 + printf("TPOOL: worker %d start job: %d\n", tidx, job->id); 3.59 tpool->work_func(job->data, tpool->cls); 3.60 - 3.61 printf("TPOOL: worker %d completed job: %d\n", tidx, job->id); 3.62 free_node(job); 3.63 }