More removal of RwLocks and replace it with Atomics, to prevent locks.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-06-18 14:17:29 +02:00
parent 59d7344729
commit c45c7538bf
15 changed files with 293 additions and 192 deletions

View File

@@ -1,10 +1,11 @@
use crate::static_data::MoveData;
use std::sync::atomic::{AtomicU8, Ordering};
#[derive(Debug)]
pub struct LearnedMove<'library> {
move_data: &'library MoveData,
max_pp: u8,
remaining_pp: u8,
remaining_pp: AtomicU8,
learn_method: MoveLearnMethod,
}
@@ -19,7 +20,7 @@ impl<'a> LearnedMove<'a> {
Self {
move_data,
max_pp: move_data.base_usages(),
remaining_pp: move_data.base_usages(),
remaining_pp: AtomicU8::new(move_data.base_usages()),
learn_method,
}
}
@@ -32,17 +33,17 @@ impl<'a> LearnedMove<'a> {
self.max_pp
}
pub fn remaining_pp(&self) -> u8 {
self.remaining_pp
self.remaining_pp.load(Ordering::Relaxed)
}
pub fn learn_method(&self) -> MoveLearnMethod {
self.learn_method
}
pub fn try_use(&mut self, amount: u8) -> bool {
if amount > self.remaining_pp {
pub fn try_use(&self, amount: u8) -> bool {
if amount > self.remaining_pp() {
return false;
}
self.remaining_pp -= amount;
return true;
self.remaining_pp.fetch_sub(amount, Ordering::SeqCst);
true
}
}