~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to util/qemu-thread-posix.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 *
12
12
 */
13
13
#include "qemu/osdep.h"
14
 
#ifdef __linux__
15
 
#include <sys/syscall.h>
16
 
#include <linux/futex.h>
17
 
#endif
18
14
#include "qemu/thread.h"
19
15
#include "qemu/atomic.h"
20
16
#include "qemu/notify.h"
294
290
}
295
291
 
296
292
#ifdef __linux__
297
 
#define futex(...)              syscall(__NR_futex, __VA_ARGS__)
298
 
 
299
 
static inline void futex_wake(QemuEvent *ev, int n)
300
 
{
301
 
    futex(ev, FUTEX_WAKE, n, NULL, NULL, 0);
302
 
}
303
 
 
304
 
static inline void futex_wait(QemuEvent *ev, unsigned val)
305
 
{
306
 
    while (futex(ev, FUTEX_WAIT, (int) val, NULL, NULL, 0)) {
307
 
        switch (errno) {
308
 
        case EWOULDBLOCK:
309
 
            return;
310
 
        case EINTR:
311
 
            break; /* get out of switch and retry */
312
 
        default:
313
 
            abort();
314
 
        }
315
 
    }
316
 
}
 
293
#include "qemu/futex.h"
317
294
#else
318
 
static inline void futex_wake(QemuEvent *ev, int n)
 
295
static inline void qemu_futex_wake(QemuEvent *ev, int n)
319
296
{
320
297
    pthread_mutex_lock(&ev->lock);
321
298
    if (n == 1) {
326
303
    pthread_mutex_unlock(&ev->lock);
327
304
}
328
305
 
329
 
static inline void futex_wait(QemuEvent *ev, unsigned val)
 
306
static inline void qemu_futex_wait(QemuEvent *ev, unsigned val)
330
307
{
331
308
    pthread_mutex_lock(&ev->lock);
332
309
    if (ev->value == val) {
338
315
 
339
316
/* Valid transitions:
340
317
 * - free->set, when setting the event
341
 
 * - busy->set, when setting the event, followed by futex_wake
 
318
 * - busy->set, when setting the event, followed by qemu_futex_wake
342
319
 * - set->free, when resetting the event
343
320
 * - free->busy, when waiting
344
321
 *
381
358
    if (atomic_read(&ev->value) != EV_SET) {
382
359
        if (atomic_xchg(&ev->value, EV_SET) == EV_BUSY) {
383
360
            /* There were waiters, wake them up.  */
384
 
            futex_wake(ev, INT_MAX);
 
361
            qemu_futex_wake(ev, INT_MAX);
385
362
        }
386
363
    }
387
364
}
419
396
                return;
420
397
            }
421
398
        }
422
 
        futex_wait(ev, EV_BUSY);
 
399
        qemu_futex_wait(ev, EV_BUSY);
423
400
    }
424
401
}
425
402