target-arm: Report a valid L1Ip field in CTR_EL0 for CPU type "any"
[qemu.git] / include / qemu / rfifolock.h
blobb23ab538a6513abe12aa956e71bb8189ae543616
1 /*
2 * Recursive FIFO lock
4 * Copyright Red Hat, Inc. 2013
6 * Authors:
7 * Stefan Hajnoczi <stefanha@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 #ifndef QEMU_RFIFOLOCK_H
15 #define QEMU_RFIFOLOCK_H
17 #include "qemu/thread.h"
19 /* Recursive FIFO lock
21 * This lock provides more features than a plain mutex:
23 * 1. Fairness - enforces FIFO order.
24 * 2. Nesting - can be taken recursively.
25 * 3. Contention callback - optional, called when thread must wait.
27 * The recursive FIFO lock is heavyweight so prefer other synchronization
28 * primitives if you do not need its features.
30 typedef struct {
31 QemuMutex lock; /* protects all fields */
33 /* FIFO order */
34 unsigned int head; /* active ticket number */
35 unsigned int tail; /* waiting ticket number */
36 QemuCond cond; /* used to wait for our ticket number */
38 /* Nesting */
39 QemuThread owner_thread; /* thread that currently has ownership */
40 unsigned int nesting; /* amount of nesting levels */
42 /* Contention callback */
43 void (*cb)(void *); /* called when thread must wait, with ->lock
44 * held so it may not recursively lock/unlock
46 void *cb_opaque;
47 } RFifoLock;
49 void rfifolock_init(RFifoLock *r, void (*cb)(void *), void *opaque);
50 void rfifolock_destroy(RFifoLock *r);
51 void rfifolock_lock(RFifoLock *r);
52 void rfifolock_unlock(RFifoLock *r);
54 #endif /* QEMU_RFIFOLOCK_H */