Skip to content

Commit

Permalink
porting/npl/linux: Handle EINTR from sem_timedwait
Browse files Browse the repository at this point in the history
It's been observed that `sem_timedwait()` can return `EINTR` even if `sigaction()` specified `SA_RESTART`.

Not sure what the deal with that is but handling it is simple enough.
  • Loading branch information
rojer committed Sep 6, 2024
1 parent f8d6061 commit 1709b23
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions porting/npl/linux/src/os_sem.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ ble_npl_sem_pend(struct ble_npl_sem *sem, uint32_t timeout)
wait.tv_sec += timeout / 1000;
wait.tv_nsec += (timeout % 1000) * 1000000;

err = sem_timedwait(&sem->lock, &wait);
if (err && errno == ETIMEDOUT) {
return BLE_NPL_TIMEOUT;
while ((err = sem_timedwait(&sem->lock, &wait)) != 0) {
switch (errno) {
case EINTR:
continue;
case ETIMEDOUT:
return BLE_NPL_TIMEOUT;
}
break;
}
}

Expand Down

0 comments on commit 1709b23

Please sign in to comment.