qemu/stubs/iothread-lock.c
Paolo Bonzini d4873c5d4f bql: add a "mock" BQL for Rust unit tests
Right now, the stub BQL in stubs/iothread-lock.c always reports itself as
unlocked.  However, Rust would like to run its tests in an environment where
the BQL *is* locked.  Provide an extremely dirty function that flips the
return value of bql_is_locked() to true.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-19 19:36:37 +01:00

36 lines
627 B
C

#include "qemu/osdep.h"
#include "qemu/main-loop.h"
static bool bql_is_locked = false;
static uint32_t bql_unlock_blocked;
bool bql_locked(void)
{
return bql_is_locked;
}
void rust_bql_mock_lock(void)
{
bql_is_locked = true;
}
void bql_lock_impl(const char *file, int line)
{
}
void bql_unlock(void)
{
assert(!bql_unlock_blocked);
}
void bql_block_unlock(bool increase)
{
uint32_t new_value;
assert(bql_locked());
/* check for overflow! */
new_value = bql_unlock_blocked + increase - !increase;
assert((new_value > bql_unlock_blocked) == increase);
bql_unlock_blocked = new_value;
}