From ceaa33f3a72997f34d794afd6a44dc1de09a44cd Mon Sep 17 00:00:00 2001 From: AsterNighT Date: Tue, 12 Dec 2023 12:45:13 +0800 Subject: [PATCH 1/2] Fix incorrect use of atomic variable --- src/perf_trace.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/perf_trace.rs b/src/perf_trace.rs index 8766cb5..028060a 100644 --- a/src/perf_trace.rs +++ b/src/perf_trace.rs @@ -66,11 +66,10 @@ pub mod inner { let msg = $msg(); let start_info = "Start:".yellow().bold(); - let indent_amount = 2 * NUM_INDENT.fetch_add(0, Ordering::Relaxed); + let indent_amount = 2 * NUM_INDENT.fetch_add(1, Ordering::Relaxed); let indent = compute_indent(indent_amount); $crate::perf_trace::println!("{}{:8} {}", indent, start_info, msg); - NUM_INDENT.fetch_add(1, Ordering::Relaxed); $crate::perf_trace::TimerInfo { msg: msg.to_string(), time: Instant::now(), @@ -110,8 +109,7 @@ pub mod inner { let end_info = "End:".green().bold(); let message = format!("{} {}", $time.msg, $msg()); - NUM_INDENT.fetch_sub(1, Ordering::Relaxed); - let indent_amount = 2 * NUM_INDENT.fetch_add(0, Ordering::Relaxed); + let indent_amount = 2 * NUM_INDENT.fetch_sub(1, Ordering::Relaxed); let indent = compute_indent(indent_amount); // Todo: Recursively ensure that *entire* string is of appropriate @@ -144,7 +142,7 @@ pub mod inner { let start_indent_amount = 2 * NUM_INDENT.fetch_add(0, Ordering::Relaxed); let start_indent = compute_indent(start_indent_amount); - let msg_indent_amount = 2 * NUM_INDENT.fetch_add(0, Ordering::Relaxed) + 2; + let msg_indent_amount = start_indent_amount + 2; let msg_indent = compute_indent_whitespace(msg_indent_amount); let mut final_message = "\n".to_string(); for line in $msg().lines() { From c51999bd0bdb3c3879033d8305edba3b39e3c8b8 Mon Sep 17 00:00:00 2001 From: AsterNighT Date: Tue, 12 Dec 2023 13:00:02 +0800 Subject: [PATCH 2/2] update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a70b41..00565fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Pending +- [\#47](https://github.com/arkworks-rs/std/pull/47) Fix incorrect use of atomic variable in `src/perf_trace.rs` ### Breaking changes