libresman
diff src/resman.c @ 12:84f55eab27cb
ok now it sortof works, probably something is failing in the done callback mechanism
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 08 Feb 2014 04:21:08 +0200 |
parents | bebc065a941f |
children | a42888d26839 |
line diff
1.1 --- a/src/resman.c Fri Feb 07 07:50:02 2014 +0200 1.2 +++ b/src/resman.c Sat Feb 08 04:21:08 2014 +0200 1.3 @@ -132,8 +132,10 @@ 1.4 for(i=0; i<num_res; i++) { 1.5 struct resource *res = rman->res[i]; 1.6 1.7 + printf("locking mutex %d\n", res->id); 1.8 pthread_mutex_lock(&res->done_lock); 1.9 if(!res->done_pending) { 1.10 + printf(" unlocking mutex %d\n", res->id); 1.11 pthread_mutex_unlock(&res->done_lock); 1.12 continue; 1.13 } 1.14 @@ -141,6 +143,7 @@ 1.15 /* so a done callback *is* pending... */ 1.16 res->done_pending = 0; 1.17 rman->done_func(i, rman->done_func_cls); 1.18 + printf(" unlocking mutex %d\n", res->id); 1.19 pthread_mutex_unlock(&res->done_lock); 1.20 } 1.21 return 0; 1.22 @@ -203,6 +206,8 @@ 1.23 assert(res->name); 1.24 res->data = data; 1.25 1.26 + pthread_mutex_init(&res->done_lock, 0); 1.27 + 1.28 if(!(tmparr = dynarr_push(rman->res, &res))) { 1.29 free(res); 1.30 return -1; 1.31 @@ -223,7 +228,10 @@ 1.32 struct resman *rman = cls; 1.33 1.34 res->result = rman->load_func(res->name, res->id, rman->load_func_cls); 1.35 + 1.36 + printf("locking mutex %d\n", res->id); 1.37 pthread_mutex_lock(&res->done_lock); 1.38 res->done_pending = 1; 1.39 + printf(" unlocking mutex %d\n", res->id); 1.40 pthread_mutex_unlock(&res->done_lock); 1.41 }