thread header

The documentation of QEMU’s qemu/thread.h header.

void qemu_thread_atexit_add(struct Notifier * notifier)

Parameters

struct Notifier * notifier
Notifier to add

Description

Add the specified notifier to a list which will be run via notifier_list_notify() when this thread exits (either by calling qemu_thread_exit() or by returning from its start_routine). The usual usage is that the caller passes a Notifier which is a per-thread variable; it can then use the callback to free other per-thread data.

If the thread exits as part of the entire process exiting, it is unspecified whether notifiers are called or not.

void qemu_thread_atexit_remove(struct Notifier * notifier)

Parameters

struct Notifier * notifier
Notifier to remove

Description

Remove the specified notifier from the thread-exit notification list. It is not valid to try to remove a notifier which is not on the list.

void qemu_lockcnt_init(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to initialize

Description

Initialize lockcnt’s counter to zero and prepare its mutex for usage.

void qemu_lockcnt_destroy(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to destruct

Description

Destroy lockcnt’s mutex.

void qemu_lockcnt_inc(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to operate on

Description

If the lockcnt’s count is zero, wait for critical sections to finish and increment lockcnt’s count to 1. If the count is not zero, just increment it.

Because this function can wait on the mutex, it must not be called while the lockcnt’s mutex is held by the current thread. For the same reason, qemu_lockcnt_inc can also contribute to AB-BA deadlocks. This is a sample deadlock scenario:

qemu_lockcnt_lock(lc1);
qemu_lockcnt_lock(lc2);
qemu_lockcnt_inc(lc2);
qemu_lockcnt_inc(lc1);
void qemu_lockcnt_dec(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to operate on
bool qemu_lockcnt_dec_and_lock(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to operate on

Description

possibly lock it. Decrement lockcnt’s count. If the new count is zero, lock the mutex and return true. Otherwise, return false.

bool qemu_lockcnt_dec_if_lock(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to operate on

Description

lock it. If the count is 1, decrement the count to zero, lock the mutex and return true. Otherwise, return false.

void qemu_lockcnt_lock(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to operate on

Description

Remember that concurrent visits are not blocked unless the count is also zero. You can use qemu_lockcnt_count to check for this inside a critical section.

void qemu_lockcnt_unlock(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to operate on.
void qemu_lockcnt_inc_and_unlock(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to operate on.

Description

This is the same as

qemu_lockcnt_unlock(lockcnt); qemu_lockcnt_inc(lockcnt);

but more efficient.

unsigned qemu_lockcnt_count(QemuLockCnt * lockcnt)

Parameters

QemuLockCnt * lockcnt
the lockcnt to query.

Description

Note that the count can change at any time. Still, while the lockcnt is locked, one can usefully check whether the count is non-zero.