More sane variants of "Ordering" used

Stores use "Ordering::Release", loads use "Ordering::Acquire", and swaps
use "Ordering::AcqRel".
This commit is contained in:
Stephen Seo 2024-07-21 21:21:46 +09:00
parent e8b170e0e2
commit 502795c6cf
2 changed files with 22 additions and 22 deletions

View file

@ -810,7 +810,7 @@ impl EventHandler for MPDDisplay {
.dirty_flag .dirty_flag
.as_ref() .as_ref()
.unwrap() .unwrap()
.swap(false, Ordering::Relaxed) .swap(false, Ordering::AcqRel)
{ {
log( log(
"dirty_flag cleared, acquiring shared data...", "dirty_flag cleared, acquiring shared data...",
@ -858,7 +858,7 @@ impl EventHandler for MPDDisplay {
self.dirty_flag self.dirty_flag
.as_ref() .as_ref()
.unwrap() .unwrap()
.store(true, Ordering::Relaxed); .store(true, Ordering::Release);
} }
if !shared.artist.is_empty() { if !shared.artist.is_empty() {
if shared.artist != self.artist_string_cache { if shared.artist != self.artist_string_cache {
@ -873,7 +873,7 @@ impl EventHandler for MPDDisplay {
self.dirty_flag self.dirty_flag
.as_ref() .as_ref()
.unwrap() .unwrap()
.store(true, Ordering::Relaxed); .store(true, Ordering::Release);
} }
if !shared.album.is_empty() { if !shared.album.is_empty() {
if shared.album != self.album_string_cache { if shared.album != self.album_string_cache {
@ -888,7 +888,7 @@ impl EventHandler for MPDDisplay {
self.dirty_flag self.dirty_flag
.as_ref() .as_ref()
.unwrap() .unwrap()
.store(true, Ordering::Relaxed); .store(true, Ordering::Release);
} }
if !shared.filename.is_empty() { if !shared.filename.is_empty() {
if shared.filename != self.filename_string_cache { if shared.filename != self.filename_string_cache {
@ -907,7 +907,7 @@ impl EventHandler for MPDDisplay {
self.dirty_flag self.dirty_flag
.as_ref() .as_ref()
.unwrap() .unwrap()
.store(true, Ordering::Relaxed); .store(true, Ordering::Release);
} }
self.timer = shared.pos; self.timer = shared.pos;
self.length = shared.length; self.length = shared.length;

View file

@ -332,7 +332,7 @@ impl MPDHandler {
#[allow(dead_code)] #[allow(dead_code)]
pub fn is_dirty(&self) -> Result<bool, ()> { pub fn is_dirty(&self) -> Result<bool, ()> {
if let Ok(write_lock) = self.state.try_write() { if let Ok(write_lock) = self.state.try_write() {
return Ok(write_lock.dirty_flag.swap(false, Ordering::Relaxed)); return Ok(write_lock.dirty_flag.swap(false, Ordering::AcqRel));
} }
Err(()) Err(())
@ -372,7 +372,7 @@ impl MPDHandler {
pub fn stop_thread(&self) -> Result<(), ()> { pub fn stop_thread(&self) -> Result<(), ()> {
let read_handle = self.state.try_read().map_err(|_| ())?; let read_handle = self.state.try_read().map_err(|_| ())?;
read_handle.stop_flag.store(true, Ordering::Relaxed); read_handle.stop_flag.store(true, Ordering::Release);
Ok(()) Ok(())
} }
@ -441,7 +441,7 @@ impl MPDHandler {
} }
if let Ok(read_handle) = self.state.try_read() { if let Ok(read_handle) = self.state.try_read() {
if read_handle.stop_flag.load(Ordering::Relaxed) || !read_handle.can_authenticate { if read_handle.stop_flag.load(Ordering::Acquire) || !read_handle.can_authenticate {
break 'main; break 'main;
} }
} }
@ -511,7 +511,7 @@ impl MPDHandler {
write_handle.log_level, write_handle.log_level,
); );
if write_handle.art_data.len() == write_handle.art_data_size { if write_handle.art_data.len() == write_handle.art_data_size {
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
} }
} else { } else {
write_handle.art_data.extend_from_slice(&buf_vec); write_handle.art_data.extend_from_slice(&buf_vec);
@ -526,7 +526,7 @@ impl MPDHandler {
write_handle.log_level, write_handle.log_level,
); );
if write_handle.art_data.len() == write_handle.art_data_size { if write_handle.art_data.len() == write_handle.art_data_size {
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
} }
break 'handle_buf; break 'handle_buf;
} }
@ -561,7 +561,7 @@ impl MPDHandler {
PollState::ReadPicture => { PollState::ReadPicture => {
if write_handle.art_data.is_empty() { if write_handle.art_data.is_empty() {
write_handle.can_get_album_art = false; write_handle.can_get_album_art = false;
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
log( log(
"No embedded album art", "No embedded album art",
LogState::Warning, LogState::Warning,
@ -572,7 +572,7 @@ impl MPDHandler {
PollState::ReadPictureInDir => { PollState::ReadPictureInDir => {
if write_handle.art_data.is_empty() { if write_handle.art_data.is_empty() {
write_handle.can_get_album_art_in_dir = false; write_handle.can_get_album_art_in_dir = false;
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
log( log(
"No album art in dir", "No album art in dir",
LogState::Warning, LogState::Warning,
@ -589,13 +589,13 @@ impl MPDHandler {
match write_handle.poll_state { match write_handle.poll_state {
PollState::Password => { PollState::Password => {
write_handle.can_authenticate = false; write_handle.can_authenticate = false;
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
write_handle.error_text = "Failed to authenticate to MPD".into(); write_handle.error_text = "Failed to authenticate to MPD".into();
write_handle.stop_flag.store(true, Ordering::Relaxed); write_handle.stop_flag.store(true, Ordering::Release);
} }
PollState::CurrentSong | PollState::Status => { PollState::CurrentSong | PollState::Status => {
write_handle.can_get_status = false; write_handle.can_get_status = false;
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
write_handle.error_text = "Failed to get MPD status".into(); write_handle.error_text = "Failed to get MPD status".into();
if line.contains("don't have permission") { if line.contains("don't have permission") {
write_handle.can_authenticate = false; write_handle.can_authenticate = false;
@ -604,7 +604,7 @@ impl MPDHandler {
} }
PollState::ReadPicture => { PollState::ReadPicture => {
write_handle.can_get_album_art = false; write_handle.can_get_album_art = false;
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
log( log(
"Failed to get readpicture", "Failed to get readpicture",
LogState::Warning, LogState::Warning,
@ -615,7 +615,7 @@ impl MPDHandler {
} }
PollState::ReadPictureInDir => { PollState::ReadPictureInDir => {
write_handle.can_get_album_art_in_dir = false; write_handle.can_get_album_art_in_dir = false;
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
log( log(
"Failed to get albumart", "Failed to get albumart",
LogState::Warning, LogState::Warning,
@ -677,13 +677,13 @@ impl MPDHandler {
write_handle.force_get_status = true; write_handle.force_get_status = true;
write_handle.error_text.clear(); write_handle.error_text.clear();
} }
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
write_handle.song_title_get_time = Instant::now(); write_handle.song_title_get_time = Instant::now();
} else if line.starts_with("elapsed: ") { } else if line.starts_with("elapsed: ") {
let parse_pos_result = f64::from_str(&line.split_off(9)); let parse_pos_result = f64::from_str(&line.split_off(9));
if let Ok(value) = parse_pos_result { if let Ok(value) = parse_pos_result {
write_handle.current_song_position = value; write_handle.current_song_position = value;
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
write_handle.song_pos_get_time = Instant::now(); write_handle.song_pos_get_time = Instant::now();
} else { } else {
log( log(
@ -696,7 +696,7 @@ impl MPDHandler {
let parse_pos_result = f64::from_str(&line.split_off(10)); let parse_pos_result = f64::from_str(&line.split_off(10));
if let Ok(value) = parse_pos_result { if let Ok(value) = parse_pos_result {
write_handle.current_song_length = value; write_handle.current_song_length = value;
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
write_handle.song_length_get_time = Instant::now(); write_handle.song_length_get_time = Instant::now();
} else { } else {
log( log(
@ -709,7 +709,7 @@ impl MPDHandler {
let parse_artsize_result = usize::from_str(&line.split_off(6)); let parse_artsize_result = usize::from_str(&line.split_off(6));
if let Ok(value) = parse_artsize_result { if let Ok(value) = parse_artsize_result {
write_handle.art_data_size = value; write_handle.art_data_size = value;
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
} else { } else {
log( log(
"Failed to parse album art byte size", "Failed to parse album art byte size",
@ -762,7 +762,7 @@ impl MPDHandler {
} // 'handle_buf: loop } // 'handle_buf: loop
if got_mpd_state != write_handle.mpd_play_state { if got_mpd_state != write_handle.mpd_play_state {
write_handle.dirty_flag.store(true, Ordering::Relaxed); write_handle.dirty_flag.store(true, Ordering::Release);
if got_mpd_state == MPDPlayState::Playing { if got_mpd_state == MPDPlayState::Playing {
write_handle.error_text.clear(); write_handle.error_text.clear();
} }