qemu-thread-posix.c (16ef9d0252318d7e32e445fd7474af55dbaab7db) | qemu-thread-posix.c (67cc32ebfd8c0ee3fcdb26780a8991baf5eb1d45) |
---|---|
1/* 2 * Wrappers around mutex/cond/thread functions 3 * 4 * Copyright Red Hat, Inc. 2009 5 * 6 * Author: 7 * Marcelo Tosatti <mtosatti@redhat.com> 8 * --- 284 unchanged lines hidden (view full) --- 293 294static inline void futex_wake(QemuEvent *ev, int n) 295{ 296 futex(ev, FUTEX_WAKE, n, NULL, NULL, 0); 297} 298 299static inline void futex_wait(QemuEvent *ev, unsigned val) 300{ | 1/* 2 * Wrappers around mutex/cond/thread functions 3 * 4 * Copyright Red Hat, Inc. 2009 5 * 6 * Author: 7 * Marcelo Tosatti <mtosatti@redhat.com> 8 * --- 284 unchanged lines hidden (view full) --- 293 294static inline void futex_wake(QemuEvent *ev, int n) 295{ 296 futex(ev, FUTEX_WAKE, n, NULL, NULL, 0); 297} 298 299static inline void futex_wait(QemuEvent *ev, unsigned val) 300{ |
301 while (futex(ev, FUTEX_WAIT, (int) val, NULL, NULL, 0)) { 302 switch (errno) { 303 case EWOULDBLOCK: 304 return; 305 case EINTR: 306 break; /* get out of switch and retry */ 307 default: 308 abort(); 309 } 310 } | 301 futex(ev, FUTEX_WAIT, (int) val, NULL, NULL, 0); |
311} 312#else 313static inline void futex_wake(QemuEvent *ev, int n) 314{ 315 pthread_mutex_lock(&ev->lock); 316 if (n == 1) { 317 pthread_cond_signal(&ev->cond); 318 } else { --- 74 unchanged lines hidden (view full) --- 393 unsigned value; 394 395 value = atomic_mb_read(&ev->value); 396 if (value != EV_SET) { 397 if (value == EV_FREE) { 398 /* 399 * Leave the event reset and tell qemu_event_set that there 400 * are waiters. No need to retry, because there cannot be | 302} 303#else 304static inline void futex_wake(QemuEvent *ev, int n) 305{ 306 pthread_mutex_lock(&ev->lock); 307 if (n == 1) { 308 pthread_cond_signal(&ev->cond); 309 } else { --- 74 unchanged lines hidden (view full) --- 384 unsigned value; 385 386 value = atomic_mb_read(&ev->value); 387 if (value != EV_SET) { 388 if (value == EV_FREE) { 389 /* 390 * Leave the event reset and tell qemu_event_set that there 391 * are waiters. No need to retry, because there cannot be |
401 * a concurent busy->free transition. After the CAS, the | 392 * a concurrent busy->free transition. After the CAS, the |
402 * event will be either set or busy. 403 */ 404 if (atomic_cmpxchg(&ev->value, EV_FREE, EV_BUSY) == EV_SET) { 405 return; 406 } 407 } 408 futex_wait(ev, EV_BUSY); 409 } --- 109 unchanged lines hidden --- | 393 * event will be either set or busy. 394 */ 395 if (atomic_cmpxchg(&ev->value, EV_FREE, EV_BUSY) == EV_SET) { 396 return; 397 } 398 } 399 futex_wait(ev, EV_BUSY); 400 } --- 109 unchanged lines hidden --- |