Patchwork [18/25] qemu-thread: add QemuSemaphore

login
register
mail settings
Submitter Paolo Bonzini
Date Oct. 31, 2012, 8:46 a.m.
Message ID <5090E55F.3090401@redhat.com>
Download mbox | patch
Permalink /patch/195771/
State New
Headers show

Comments

Paolo Bonzini - Oct. 31, 2012, 8:46 a.m.
Il 30/10/2012 19:48, Stefan Hajnoczi ha scritto:
>> +    if (rc < 0) {
>> +        error_exit(errno, __func__);
>> +    }
> 
> Forgot to handle EINTR?
> 
>> +    return 0;
>> +}
>> +
>> +void qemu_sem_wait(QemuSemaphore *sem)
>> +{
>> +    int rc;
>> +
>> +    rc = sem_wait(&sem->sem);
>> +    if (rc < 0) {
>> +        error_exit(errno, __func__);
>> +    }
> 
> EINTR

Right!

I'm squashing this:


Paolo

Patch

diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
index dea57d4..6a3d3a1 100644
--- a/qemu-thread-posix.c
+++ b/qemu-thread-posix.c
@@ -154,7 +154,9 @@  int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
 
     if (ms <= 0) {
         /* This is cheaper than sem_timedwait.  */
-        rc = sem_trywait(&sem->sem);
+        do {
+            rc = sem_trywait(&sem->sem);
+        } while (rc == -1 && errno == EINTR);
         if (rc == -1 && errno == EAGAIN) {
             return -1;
         }
@@ -168,7 +170,9 @@  int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
             ts.tv_sec++;
             ts.tv_nsec -= 1000000000;
         }
-        rc = sem_timedwait(&sem->sem, &ts);
+        do {
+            rc = sem_timedwait(&sem->sem, &ts);
+        } while (rc == -1 && errno == EINTR);
         if (rc == -1 && errno == ETIMEDOUT) {
             return -1;
         }
@@ -183,7 +187,9 @@  void qemu_sem_wait(QemuSemaphore *sem)
 {
     int rc;
 
-    rc = sem_wait(&sem->sem);
+    do {
+        rc = sem_wait(&sem->sem);
+    } while (rc == -1 && errno == EINTR);
     if (rc < 0) {
         error_exit(errno, __func__);
     }