98
99
__sync_lock_release(&spin->value);
110
* qemu_lockcnt_init: initialize a QemuLockcnt
111
* @lockcnt: the lockcnt to initialize
113
* Initialize lockcnt's counter to zero and prepare its mutex
116
void qemu_lockcnt_init(QemuLockCnt *lockcnt);
119
* qemu_lockcnt_destroy: destroy a QemuLockcnt
120
* @lockcnt: the lockcnt to destruct
122
* Destroy lockcnt's mutex.
124
void qemu_lockcnt_destroy(QemuLockCnt *lockcnt);
127
* qemu_lockcnt_inc: increment a QemuLockCnt's counter
128
* @lockcnt: the lockcnt to operate on
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.
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:
140
* -------------------------------------------------------
141
* qemu_lockcnt_lock(&lc1);
142
* qemu_lockcnt_lock(&lc2);
143
* qemu_lockcnt_inc(&lc2);
144
* qemu_lockcnt_inc(&lc1);
146
void qemu_lockcnt_inc(QemuLockCnt *lockcnt);
149
* qemu_lockcnt_dec: decrement a QemuLockCnt's counter
150
* @lockcnt: the lockcnt to operate on
152
void qemu_lockcnt_dec(QemuLockCnt *lockcnt);
155
* qemu_lockcnt_dec_and_lock: decrement a QemuLockCnt's counter and
157
* @lockcnt: the lockcnt to operate on
159
* Decrement lockcnt's count. If the new count is zero, lock
160
* the mutex and return true. Otherwise, return false.
162
bool qemu_lockcnt_dec_and_lock(QemuLockCnt *lockcnt);
165
* qemu_lockcnt_dec_if_lock: possibly decrement a QemuLockCnt's counter and
167
* @lockcnt: the lockcnt to operate on
169
* If the count is 1, decrement the count to zero, lock
170
* the mutex and return true. Otherwise, return false.
172
bool qemu_lockcnt_dec_if_lock(QemuLockCnt *lockcnt);
175
* qemu_lockcnt_lock: lock a QemuLockCnt's mutex.
176
* @lockcnt: the lockcnt to operate on
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
182
void qemu_lockcnt_lock(QemuLockCnt *lockcnt);
185
* qemu_lockcnt_unlock: release a QemuLockCnt's mutex.
186
* @lockcnt: the lockcnt to operate on.
188
void qemu_lockcnt_unlock(QemuLockCnt *lockcnt);
191
* qemu_lockcnt_inc_and_unlock: combined unlock/increment on a QemuLockCnt.
192
* @lockcnt: the lockcnt to operate on.
194
* This is the same as
196
* qemu_lockcnt_unlock(lockcnt);
197
* qemu_lockcnt_inc(lockcnt);
199
* but more efficient.
201
void qemu_lockcnt_inc_and_unlock(QemuLockCnt *lockcnt);
204
* qemu_lockcnt_count: query a LockCnt's count.
205
* @lockcnt: the lockcnt to query.
207
* Note that the count can change at any time. Still, while the
208
* lockcnt is locked, one can usefully check whether the count
211
unsigned qemu_lockcnt_count(QemuLockCnt *lockcnt);