Skip to content

Commit

Permalink
fix(core): fix unnecessarily strict Ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
SARDONYX-sard committed Jan 8, 2024
1 parent 279d955 commit 1c77b35
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions dar2oar_core/src/fs/converter/parallel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ pub async fn convert_dar_to_oar(
progress_fn(idx);
}

if is_converted_once.load(Ordering::Acquire) {
handle_conversion_results(hide_dar, &dar_namespace, &dar_1st_namespace).await
} else {
Err(ConvertError::NeverConverted)
// # Ordering validity:
// Since all processing threads are loaded after they have finished, ordering relationships are not a concern.
// Therefore, there is no problem in using `Relaxed`.
match is_converted_once.load(Ordering::Relaxed) {
true => handle_conversion_results(hide_dar, &dar_namespace, &dar_1st_namespace).await,
false => Err(ConvertError::NeverConverted),
}
}

Expand Down
10 changes: 6 additions & 4 deletions dar2oar_core/src/fs/converter/sequential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ pub async fn convert_dar_to_oar(
idx += 1;
}

if is_converted_once.load(Ordering::Acquire) {
handle_conversion_results(hide_dar, &dar_namespace, &dar_1st_namespace).await
} else {
Err(ConvertError::NeverConverted)
// # Ordering validity:
// The order is irrelevant because `tokio::spawn` is not used in the while loop.
// Therefore, there is no problem in using `Relaxed`.
match is_converted_once.load(Ordering::Relaxed) {
true => handle_conversion_results(hide_dar, &dar_namespace, &dar_1st_namespace).await,
false => Err(ConvertError::NeverConverted),
}
}

Expand Down

0 comments on commit 1c77b35

Please sign in to comment.