Skip to content

Commit

Permalink
src/histogram: Drop collect lock guard explicitly
Browse files Browse the repository at this point in the history
Rusts drop semantics can be confusing sometimes. E.g. `let _ = l.lock()`
would drop the lock guard immediately whereas `let _guard = l.lock()`
would drop the guard in LIFO order at the end of the current scope.

Instead of relying on the above guarantee with `let _guard`, drop the
mutex guard explicitely hopefully making this less error prone in the
future.

Signed-off-by: Max Inden <mail@max-inden.de>
  • Loading branch information
mxinden committed Jun 19, 2020
1 parent 3db6ddf commit 79a499f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/histogram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ impl HistogramCore {
// remaining `observe` calls to finish on the previously hot now cold shard,
// snapshot the data, update the now hot shard and reset the cold shard.
pub fn proto(&self) -> proto::Histogram {
let _guard = self.collect_lock.lock().expect("Lock poisoned");
let _collect_guard = self.collect_lock.lock().expect("Lock poisoned");

// `flip` needs to use AcqRel ordering to ensure the lock operation
// above stays above and the histogram operations (especially the shard
Expand Down Expand Up @@ -450,6 +450,8 @@ impl HistogramCore {
hot_shard.count.inc_by(overall_count);
hot_shard.sum.inc_by(cold_shard_sum);

drop(_collect_guard);

h
}

Expand Down

0 comments on commit 79a499f

Please sign in to comment.