From edf2ad46f4c0f403b90d3058018a295baa9d0753 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Jun 2015 13:46:01 +0200 Subject: Replace semaphore with a mutex A mutex (in a shared memory segment) is the correct synchronisation primitive here. I had confused myself... --- libcrystfel/src/integration.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'libcrystfel/src/integration.c') diff --git a/libcrystfel/src/integration.c b/libcrystfel/src/integration.c index 336e99ed..16c27bbe 100644 --- a/libcrystfel/src/integration.c +++ b/libcrystfel/src/integration.c @@ -38,7 +38,6 @@ #include #include #include -#include #ifdef HAVE_CURSES_COLOR #include @@ -253,14 +252,14 @@ static void show_reference_profile(struct intcontext *ic, int i) static void show_peak_box(struct intcontext *ic, struct peak_box *bx, - sem_t *term_sem) + pthread_mutex_t *term_lock) { #ifdef HAVE_CURSES_COLOR int q; signed int h, k, l; double fs, ss; - if ( term_sem != NULL ) sem_wait(term_sem); + if ( term_lock != NULL ) pthread_mutex_lock(term_lock); initscr(); clear(); @@ -324,7 +323,7 @@ static void show_peak_box(struct intcontext *ic, struct peak_box *bx, getch(); endwin(); - if ( term_sem != NULL ) sem_post(term_sem); + if ( term_lock != NULL ) pthread_mutex_unlock(term_lock); #else STATUS("Not showing peak box because CrystFEL was compiled without " "ncurses.\n"); @@ -1171,7 +1170,7 @@ static int get_int_diag(struct intcontext *ic, Reflection *refl) static void integrate_prof2d_once(struct intcontext *ic, struct peak_box *bx, - sem_t *sem) + pthread_mutex_t *term_lock) { bx->intensity = fit_intensity(ic, bx); bx->sigma = calc_sigma(ic, bx); @@ -1201,7 +1200,9 @@ static void integrate_prof2d_once(struct intcontext *ic, struct peak_box *bx, set_redundancy(bx->refl, 0); } - if ( get_int_diag(ic, bx->refl) ) show_peak_box(ic, bx, sem); + if ( get_int_diag(ic, bx->refl) ) { + show_peak_box(ic, bx, term_lock); + } } else { @@ -1294,7 +1295,7 @@ static void integrate_prof2d(IntegrationMethod meth, Crystal *cr, struct image *image, IntDiag int_diag, signed int idh, signed int idk, signed int idl, double ir_inn, double ir_mid, double ir_out, - sem_t *term_sem, int **masks) + pthread_mutex_t *term_lock, int **masks) { RefList *list; UnitCell *cell; @@ -1338,7 +1339,7 @@ static void integrate_prof2d(IntegrationMethod meth, for ( i=0; ioffs_ss; set_detector_pos(refl, pfs, pss); - if ( get_int_diag(ic, refl) ) show_peak_box(ic, bx, term_sem); + if ( get_int_diag(ic, refl) ) show_peak_box(ic, bx, term_lock); if ( intensity < -5.0*sigma ) { ic->n_implausible++; @@ -1550,7 +1551,7 @@ static void integrate_rings(IntegrationMethod meth, Crystal *cr, struct image *image, IntDiag int_diag, signed int idh, signed int idk, signed int idl, double ir_inn, double ir_mid, double ir_out, - sem_t *term_sem, int **masks) + pthread_mutex_t *term_lock, int **masks) { RefList *list; Reflection *refl; @@ -1586,7 +1587,7 @@ static void integrate_rings(IntegrationMethod meth, refl != NULL; refl = next_refl(refl, iter) ) { - integrate_rings_once(refl, image, &ic, cell, term_sem); + integrate_rings_once(refl, image, &ic, cell, term_lock); } //refine_rigid_groups(&ic); @@ -1602,7 +1603,8 @@ void integrate_all_4(struct image *image, IntegrationMethod meth, PartialityModel pmodel, double push_res, double ir_inn, double ir_mid, double ir_out, IntDiag int_diag, - signed int idh, signed int idk, signed int idl, sem_t *sem) + signed int idh, signed int idk, signed int idl, + pthread_mutex_t *term_lock) { int i; int *masks[image->det->n_panels]; @@ -1642,14 +1644,14 @@ void integrate_all_4(struct image *image, IntegrationMethod meth, integrate_rings(meth, cr, image, int_diag, idh, idk, idl, ir_inn, ir_mid, ir_out, - sem, masks); + term_lock, masks); break; case INTEGRATION_PROF2D : integrate_prof2d(meth, cr, image, int_diag, idh, idk, idl, ir_inn, ir_mid, ir_out, - sem, masks); + term_lock, masks); break; default : -- cgit v1.2.3