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:
Levi Neely 2026-03-07 16:23:48 +01:00 committed by GitHub
parent 18e9c8231c
commit 7a8aef3b50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 1 deletions

View File

@ -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);