mirror of
https://github.com/romanz/electrs.git
synced 2025-02-23 22:56:55 +01:00
Merge branch 'atomic-counter'
This commit is contained in:
commit
70d0c1d47f
2 changed files with 24 additions and 0 deletions
|
@ -14,6 +14,9 @@ edition = "2018"
|
|||
[profile.release]
|
||||
lto = true
|
||||
|
||||
[features]
|
||||
latest_rust = [] # use latest Rust features (otherwise, support Rust 1.32)
|
||||
|
||||
[dependencies]
|
||||
arrayref = "0.3"
|
||||
base64 = "0.10"
|
||||
|
|
|
@ -13,6 +13,8 @@ use std::collections::{HashMap, HashSet};
|
|||
use std::io::{BufRead, BufReader, Lines, Write};
|
||||
use std::net::{SocketAddr, TcpStream};
|
||||
use std::path::PathBuf;
|
||||
#[cfg(feature = "latest_rust")]
|
||||
use std::sync::atomic::{AtomicU64, Ordering};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
|
||||
|
@ -266,10 +268,29 @@ impl Connection {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "latest_rust")]
|
||||
struct Counter {
|
||||
value: AtomicU64,
|
||||
}
|
||||
|
||||
#[cfg(feature = "latest_rust")]
|
||||
impl Counter {
|
||||
fn new() -> Self {
|
||||
Counter { value: 0.into() }
|
||||
}
|
||||
|
||||
fn next(&self) -> u64 {
|
||||
// fetch_add() returns previous value, we want current one
|
||||
self.value.fetch_add(1, Ordering::Relaxed) + 1
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "latest_rust"))]
|
||||
struct Counter {
|
||||
value: Mutex<u64>,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "latest_rust"))]
|
||||
impl Counter {
|
||||
fn new() -> Self {
|
||||
Counter {
|
||||
|
|
Loading…
Add table
Reference in a new issue