@@ -205,7 +205,7 @@ static SEXP_t *__SEAP_cmd_sync_handler (SEXP_t *res, void *arg)
205
205
h -> args = res ;
206
206
(void ) pthread_mutex_lock (& h -> mtx );
207
207
h -> signaled = 1 ;
208
- (void ) pthread_cond_signal (& h -> cond );
208
+ (void ) pthread_cond_broadcast (& h -> cond );
209
209
(void ) pthread_mutex_unlock (& h -> mtx );
210
210
211
211
return (NULL );
@@ -322,9 +322,6 @@ SEXP_t *SEAP_cmd_exec (SEAP_CTX_t *ctx,
322
322
h .args = NULL ;
323
323
h .signaled = 0 ;
324
324
325
- if (pthread_mutex_lock (& (h .mtx )) != 0 )
326
- abort ();
327
-
328
325
rec = SEAP_cmdrec_new ();
329
326
rec -> code = cmdptr -> id ;
330
327
rec -> func = & __SEAP_cmd_sync_handler ;
@@ -377,8 +374,6 @@ SEXP_t *SEAP_cmd_exec (SEAP_CTX_t *ctx,
377
374
timeout.tv_nsec = 0;
378
375
*/
379
376
for (;;) {
380
- pthread_mutex_unlock (& h .mtx );
381
-
382
377
if (SEAP_packet_recv (ctx , sd , & packet_rcv ) != 0 ) {
383
378
dD ("FAIL: ctx=%p, sd=%d, errno=%u, %s." , ctx , sd , errno , strerror (errno ));
384
379
SEAP_packet_free (packet );
@@ -407,21 +402,23 @@ SEXP_t *SEAP_cmd_exec (SEAP_CTX_t *ctx,
407
402
}
408
403
409
404
/* Morbo: THIS IS NOT HOW SYCHNRONIZATION WORKS! */
410
- if (h .signaled )
405
+ if (h .signaled ) {
406
+ h .signaled = 0 ;
411
407
break ;
408
+ }
412
409
}
413
410
} else {
414
411
/*
415
412
* Someone else does receiving of events for us.
416
413
* Just wait for the condition to be signaled.
417
414
*/
418
- if ( pthread_cond_wait ( & h .cond , & h . mtx ) != 0 ) {
419
- /*
420
- * Fatal error - don't know how to handle
421
- * this so let's just call abort()...
422
- */
423
- abort () ;
424
- }
415
+ pthread_mutex_lock ( & h .mtx );
416
+ while (! h . signaled ) {
417
+ pthread_cond_wait ( & h . cond , & h . mtx );
418
+ }
419
+ // This might not be needed, but still
420
+ h . signaled = 0 ;
421
+ pthread_mutex_unlock ( & h . mtx );
425
422
}
426
423
427
424
dD ("cond return: h.args=%p" , h .args );
@@ -436,7 +433,6 @@ SEXP_t *SEAP_cmd_exec (SEAP_CTX_t *ctx,
436
433
/*
437
434
* SEAP_cmdtbl_del(dsc->cmd_w_table, rec);
438
435
*/
439
- pthread_mutex_unlock (& (h .mtx ));
440
436
pthread_cond_destroy (& (h .cond ));
441
437
pthread_mutex_destroy (& (h .mtx ));
442
438
SEAP_packet_free (packet );
0 commit comments