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

« back to all changes in this revision

Viewing changes to include/qemu/thread.h

  • 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:
8
8
typedef struct QemuCond QemuCond;
9
9
typedef struct QemuSemaphore QemuSemaphore;
10
10
typedef struct QemuEvent QemuEvent;
 
11
typedef struct QemuLockCnt QemuLockCnt;
11
12
typedef struct QemuThread QemuThread;
12
13
 
13
14
#ifdef _WIN32
98
99
    __sync_lock_release(&spin->value);
99
100
}
100
101
 
 
102
struct QemuLockCnt {
 
103
#ifndef CONFIG_LINUX
 
104
    QemuMutex mutex;
 
105
#endif
 
106
    unsigned count;
 
107
};
 
108
 
 
109
/**
 
110
 * qemu_lockcnt_init: initialize a QemuLockcnt
 
111
 * @lockcnt: the lockcnt to initialize
 
112
 *
 
113
 * Initialize lockcnt's counter to zero and prepare its mutex
 
114
 * for usage.
 
115
 */
 
116
void qemu_lockcnt_init(QemuLockCnt *lockcnt);
 
117
 
 
118
/**
 
119
 * qemu_lockcnt_destroy: destroy a QemuLockcnt
 
120
 * @lockcnt: the lockcnt to destruct
 
121
 *
 
122
 * Destroy lockcnt's mutex.
 
123
 */
 
124
void qemu_lockcnt_destroy(QemuLockCnt *lockcnt);
 
125
 
 
126
/**
 
127
 * qemu_lockcnt_inc: increment a QemuLockCnt's counter
 
128
 * @lockcnt: the lockcnt to operate on
 
129
 *
 
130
 * If the lockcnt's count is zero, wait for critical sections
 
131
 * to finish and increment lockcnt's count to 1.  If the count
 
132
 * is not zero, just increment it.
 
133
 *
 
134
 * Because this function can wait on the mutex, it must not be
 
135
 * called while the lockcnt's mutex is held by the current thread.
 
136
 * For the same reason, qemu_lockcnt_inc can also contribute to
 
137
 * AB-BA deadlocks.  This is a sample deadlock scenario:
 
138
 *
 
139
 *            thread 1                      thread 2
 
140
 *            -------------------------------------------------------
 
141
 *            qemu_lockcnt_lock(&lc1);
 
142
 *                                          qemu_lockcnt_lock(&lc2);
 
143
 *            qemu_lockcnt_inc(&lc2);
 
144
 *                                          qemu_lockcnt_inc(&lc1);
 
145
 */
 
146
void qemu_lockcnt_inc(QemuLockCnt *lockcnt);
 
147
 
 
148
/**
 
149
 * qemu_lockcnt_dec: decrement a QemuLockCnt's counter
 
150
 * @lockcnt: the lockcnt to operate on
 
151
 */
 
152
void qemu_lockcnt_dec(QemuLockCnt *lockcnt);
 
153
 
 
154
/**
 
155
 * qemu_lockcnt_dec_and_lock: decrement a QemuLockCnt's counter and
 
156
 * possibly lock it.
 
157
 * @lockcnt: the lockcnt to operate on
 
158
 *
 
159
 * Decrement lockcnt's count.  If the new count is zero, lock
 
160
 * the mutex and return true.  Otherwise, return false.
 
161
 */
 
162
bool qemu_lockcnt_dec_and_lock(QemuLockCnt *lockcnt);
 
163
 
 
164
/**
 
165
 * qemu_lockcnt_dec_if_lock: possibly decrement a QemuLockCnt's counter and
 
166
 * lock it.
 
167
 * @lockcnt: the lockcnt to operate on
 
168
 *
 
169
 * If the count is 1, decrement the count to zero, lock
 
170
 * the mutex and return true.  Otherwise, return false.
 
171
 */
 
172
bool qemu_lockcnt_dec_if_lock(QemuLockCnt *lockcnt);
 
173
 
 
174
/**
 
175
 * qemu_lockcnt_lock: lock a QemuLockCnt's mutex.
 
176
 * @lockcnt: the lockcnt to operate on
 
177
 *
 
178
 * Remember that concurrent visits are not blocked unless the count is
 
179
 * also zero.  You can use qemu_lockcnt_count to check for this inside a
 
180
 * critical section.
 
181
 */
 
182
void qemu_lockcnt_lock(QemuLockCnt *lockcnt);
 
183
 
 
184
/**
 
185
 * qemu_lockcnt_unlock: release a QemuLockCnt's mutex.
 
186
 * @lockcnt: the lockcnt to operate on.
 
187
 */
 
188
void qemu_lockcnt_unlock(QemuLockCnt *lockcnt);
 
189
 
 
190
/**
 
191
 * qemu_lockcnt_inc_and_unlock: combined unlock/increment on a QemuLockCnt.
 
192
 * @lockcnt: the lockcnt to operate on.
 
193
 *
 
194
 * This is the same as
 
195
 *
 
196
 *     qemu_lockcnt_unlock(lockcnt);
 
197
 *     qemu_lockcnt_inc(lockcnt);
 
198
 *
 
199
 * but more efficient.
 
200
 */
 
201
void qemu_lockcnt_inc_and_unlock(QemuLockCnt *lockcnt);
 
202
 
 
203
/**
 
204
 * qemu_lockcnt_count: query a LockCnt's count.
 
205
 * @lockcnt: the lockcnt to query.
 
206
 *
 
207
 * Note that the count can change at any time.  Still, while the
 
208
 * lockcnt is locked, one can usefully check whether the count
 
209
 * is non-zero.
 
210
 */
 
211
unsigned qemu_lockcnt_count(QemuLockCnt *lockcnt);
 
212
 
101
213
#endif