Browse Source

Use AtomicU64 after updating to Rust >=1.34

master
Roman Zeyde 6 years ago
parent
commit
05b653f7f5
  1. 2
      Cargo.toml
  2. 23
      src/daemon.rs

2
Cargo.toml

@ -15,7 +15,7 @@ edition = "2018"
lto = true lto = true
[features] [features]
latest_rust = [] # use latest Rust features (otherwise, support Rust 1.32) latest_rust = [] # use latest Rust features (otherwise, support Rust 1.34)
[dependencies] [dependencies]
base64 = "0.10" base64 = "0.10"

23
src/daemon.rs

@ -13,7 +13,6 @@ use std::collections::{HashMap, HashSet};
use std::io::{BufRead, BufReader, Lines, Write}; use std::io::{BufRead, BufReader, Lines, Write};
use std::net::{SocketAddr, TcpStream}; use std::net::{SocketAddr, TcpStream};
use std::path::PathBuf; use std::path::PathBuf;
#[cfg(feature = "latest_rust")]
use std::sync::atomic::{AtomicU64, Ordering}; use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::time::Duration; use std::time::Duration;
@ -269,12 +268,10 @@ impl Connection {
} }
} }
#[cfg(feature = "latest_rust")]
struct Counter { struct Counter {
value: AtomicU64, value: AtomicU64,
} }
#[cfg(feature = "latest_rust")]
impl Counter { impl Counter {
fn new() -> Self { fn new() -> Self {
Counter { value: 0.into() } Counter { value: 0.into() }
@ -286,26 +283,6 @@ 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 { pub struct Daemon {
daemon_dir: PathBuf, daemon_dir: PathBuf,
network: Network, network: Network,

Loading…
Cancel
Save