aboutsummaryrefslogtreecommitdiff
path: root/rust/bql/src/lib.rs
blob: ef08221e9c1a0f6774b8305c87066a842c350361 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// SPDX-License-Identifier: GPL-2.0-or-later

mod bindings;
use bindings::{bql_block_unlock, bql_locked, rust_bql_mock_lock};

mod cell;
pub use cell::*;

/// An internal function that is used by doctests.
pub fn start_test() {
    // SAFETY: integration tests are run with --test-threads=1, while
    // unit tests and doctests are not multithreaded and do not have
    // any BQL-protected data.  Just set bql_locked to true.
    unsafe {
        rust_bql_mock_lock();
    }
}

pub fn is_locked() -> bool {
    // SAFETY: the function does nothing but return a thread-local bool
    unsafe { bql_locked() }
}

pub fn block_unlock(increase: bool) {
    // SAFETY: this only adjusts a counter
    unsafe {
        bql_block_unlock(increase);
    }
}