Browse Source
Add support for latest Rust features via `--features latest_rust`
atomic-counter
Roman Zeyde
6 years ago
No known key found for this signature in database
GPG Key ID: 87CAE5FA46917CBB
2 changed files with
29 additions and
4 deletions
-
Cargo.toml
-
src/daemon.rs
|
|
@ -11,6 +11,9 @@ documentation = "https://docs.rs/electrs/" |
|
|
|
readme = "README.md" |
|
|
|
edition = "2018" |
|
|
|
|
|
|
|
[features] |
|
|
|
latest_rust = [] # use latest Rust features (otherwise, support Rust 1.32) |
|
|
|
|
|
|
|
[dependencies] |
|
|
|
arrayref = "0.3" |
|
|
|
base64 = "0.10" |
|
|
|
|
|
@ -13,7 +13,9 @@ use std::collections::{HashMap, HashSet}; |
|
|
|
use std::io::{BufRead, BufReader, Lines, Write}; |
|
|
|
use std::net::{SocketAddr, TcpStream}; |
|
|
|
use std::path::PathBuf; |
|
|
|
use std::sync::{Arc, Mutex, atomic::{AtomicU64, Ordering}}; |
|
|
|
#[cfg(feature = "latest_rust")] |
|
|
|
use std::sync::atomic::{AtomicU64, Ordering}; |
|
|
|
use std::sync::{Arc, Mutex}; |
|
|
|
use std::time::Duration; |
|
|
|
|
|
|
|
use crate::errors::*; |
|
|
@ -266,15 +268,15 @@ impl Connection { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#[cfg(feature = "latest_rust")] |
|
|
|
struct Counter { |
|
|
|
value: AtomicU64, |
|
|
|
} |
|
|
|
|
|
|
|
#[cfg(feature = "latest_rust")] |
|
|
|
impl Counter { |
|
|
|
fn new() -> Self { |
|
|
|
Counter { |
|
|
|
value: 0.into(), |
|
|
|
} |
|
|
|
Counter { value: 0.into() } |
|
|
|
} |
|
|
|
|
|
|
|
fn next(&self) -> u64 { |
|
|
@ -283,6 +285,26 @@ impl Counter { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#[cfg(not(feature = "latest_rust"))] |
|
|
|
struct Counter { |
|
|
|
value: Mutex<u64>, |
|
|
|
} |
|
|
|
|
|
|
|
#[cfg(not(feature = "latest_rust"))] |
|
|
|
impl Counter { |
|
|
|
fn new() -> Self { |
|
|
|
Counter { |
|
|
|
value: Mutex::new(0), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
fn next(&self) -> u64 { |
|
|
|
let mut value = self.value.lock().unwrap(); |
|
|
|
*value += 1; |
|
|
|
*value |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
pub struct Daemon { |
|
|
|
daemon_dir: PathBuf, |
|
|
|
network: Network, |
|
|
|