File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 3
3
4
4
#include <inttypes.h>
5
5
#include <stdbool.h>
6
+ #include <errno.h>
7
+ #include "qemu/atomic.h"
6
8
7
9
typedef struct QemuMutex QemuMutex ;
8
10
typedef struct QemuCond QemuCond ;
@@ -62,4 +64,33 @@ struct Notifier;
62
64
void qemu_thread_atexit_add (struct Notifier * notifier );
63
65
void qemu_thread_atexit_remove (struct Notifier * notifier );
64
66
67
+ typedef struct QemuSpin {
68
+ int value ;
69
+ } QemuSpin ;
70
+
71
+ static inline void qemu_spin_init (QemuSpin * spin )
72
+ {
73
+ spin -> value = 0 ;
74
+ }
75
+
76
+ static inline void qemu_spin_lock (QemuSpin * spin )
77
+ {
78
+ do {
79
+ while (atomic_read (& spin -> value ));
80
+ } while (atomic_xchg (& spin -> value , true));
81
+ }
82
+
83
+ static inline int qemu_spin_trylock (QemuSpin * spin )
84
+ {
85
+ if (atomic_read (& spin -> value ) || atomic_xchg (& spin -> value , true)) {
86
+ return - EBUSY ;
87
+ }
88
+ return 0 ;
89
+ }
90
+
91
+ static inline void qemu_spin_unlock (QemuSpin * spin )
92
+ {
93
+ atomic_mb_set (& spin -> value , 0 );
94
+ }
95
+
65
96
#endif
You can’t perform that action at this time.
0 commit comments