[bitboard] Use a OnceLock to hold the global BitBoard library instance
Thread safe and a single object instead of two!
This commit is contained in:
parent
4b35051deb
commit
a8034c79aa
1 changed files with 7 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use crate::BitBoard;
|
use crate::BitBoard;
|
||||||
use chessfriend_core::{Color, Direction, Square};
|
use chessfriend_core::{Color, Direction, Square};
|
||||||
use std::sync::Once;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
pub(super) const RANKS: [BitBoard; 8] = [
|
pub(super) const RANKS: [BitBoard; 8] = [
|
||||||
BitBoard(0xFF << 0 * 8),
|
BitBoard(0xFF << 0 * 8),
|
||||||
|
@ -42,15 +42,15 @@ pub(crate) const LIGHT_SQUARES: BitBoard =
|
||||||
pub(crate) const DARK_SQUARES: BitBoard = BitBoard(!LIGHT_SQUARES.0);
|
pub(crate) const DARK_SQUARES: BitBoard = BitBoard(!LIGHT_SQUARES.0);
|
||||||
|
|
||||||
pub(super) fn library() -> &'static MoveLibrary {
|
pub(super) fn library() -> &'static MoveLibrary {
|
||||||
static MOVE_LIBRARY_INIT: Once = Once::new();
|
static mut MOVE_LIBRARY: OnceLock<MoveLibrary> = OnceLock::new();
|
||||||
static mut MOVE_LIBRARY: MoveLibrary = MoveLibrary::new();
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
MOVE_LIBRARY_INIT.call_once(|| {
|
MOVE_LIBRARY.get_or_init(|| {
|
||||||
MOVE_LIBRARY.init();
|
let mut library = MoveLibrary::new();
|
||||||
});
|
library.init();
|
||||||
|
|
||||||
&MOVE_LIBRARY
|
library
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue