Fix pcl-5xn.1: replace pthread_cond_wait with timedwait in pstatus_wait (#353)
Replace indefinite pthread_cond_wait() calls in pstatus_wait() with pthread_cond_timedwait() using a 5-second timeout computed via clock_gettime(CLOCK_REALTIME). On timeout, the while loop re-evaluates the wait condition, preventing indefinite hang when the state machine stalls. Ref GH #292. Co-authored-by: Levi Neely <lkn@darkstar.example.net>
This commit is contained in:
parent
18e9c8231c
commit
7a8aef3b50
|
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
#include "pfile.h"
|
#include "pfile.h"
|
||||||
#include "pfstasks.h"
|
#include "pfstasks.h"
|
||||||
|
|
@ -266,10 +267,13 @@ void pstatus_set(uint32_t statusid, uint32_t status) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void pstatus_wait(uint32_t statusid, uint32_t status) {
|
void pstatus_wait(uint32_t statusid, uint32_t status) {
|
||||||
|
struct timespec ts;
|
||||||
pthread_mutex_lock(&status_internal_mutex);
|
pthread_mutex_lock(&status_internal_mutex);
|
||||||
while ((statuses[statusid] & status) == 0 && psync_do_run) {
|
while ((statuses[statusid] & status) == 0 && psync_do_run) {
|
||||||
status_waiters++;
|
status_waiters++;
|
||||||
pthread_cond_wait(&statuscond, &status_internal_mutex);
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
|
ts.tv_sec += 5;
|
||||||
|
pthread_cond_timedwait(&statuscond, &status_internal_mutex, &ts);
|
||||||
status_waiters--;
|
status_waiters--;
|
||||||
}
|
}
|
||||||
pthread_mutex_unlock(&status_internal_mutex);
|
pthread_mutex_unlock(&status_internal_mutex);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue