More removal of RwLocks and replace it with Atomics, to prevent locks.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user