This is an automated email from the ASF dual-hosted git repository.

janc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git


The following commit(s) were added to refs/heads/master by this push:
     new 42e5a2816 porting/npl/linux: Handle EINTR from sem_timedwait
42e5a2816 is described below

commit 42e5a2816d0d3df397f69b63bf7420542e4cd7c2
Author: Deomid rojer Ryabkov <[email protected]>
AuthorDate: Mon Sep 2 22:42:41 2024 +0300

    porting/npl/linux: Handle EINTR from sem_timedwait
    
    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.
---
 porting/npl/linux/src/os_sem.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/porting/npl/linux/src/os_sem.c b/porting/npl/linux/src/os_sem.c
index e3434af5a..be43c6499 100644
--- a/porting/npl/linux/src/os_sem.c
+++ b/porting/npl/linux/src/os_sem.c
@@ -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;
         }
     }
 

Reply via email to