mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-28 04:43:54 -06:00

The Big QEMU Lock (BQL) is used to provide interior mutability to Rust code. While BqlCell performs indivisible accesses, an equivalent of RefCell will allow the borrower to hold to the interior content for a long time. If the BQL is dropped, another thread could come and mutate the data from C code (Rust code would panic on borrow_mut() instead). In order to prevent this, add a new BQL primitive that can mark BQL-atomic sections and aborts if the BQL is dropped within them. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
30 lines
523 B
C
30 lines
523 B
C
#include "qemu/osdep.h"
|
|
#include "qemu/main-loop.h"
|
|
|
|
static uint32_t bql_unlock_blocked;
|
|
|
|
bool bql_locked(void)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
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;
|
|
}
|