summaryrefslogtreecommitdiffstats
path: root/src/plugins/tell/mod.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2018-03-21 16:40:15 +0100
committerJokler <jokler.contact@gmail.com>2018-03-21 16:40:15 +0100
commit516ee046784acb4a6dc97b844ff3af9a54308e30 (patch)
tree672f422c6817734c7404ec26569a366319c1a183 /src/plugins/tell/mod.rs
parent48f547826edd9db9b94376f240a785d8a19a993d (diff)
downloadfrippy-516ee046784acb4a6dc97b844ff3af9a54308e30.tar.gz
frippy-516ee046784acb4a6dc97b844ff3af9a54308e30.zip
Replace every Mutex with RwLock
Diffstat (limited to 'src/plugins/tell/mod.rs')
-rw-r--r--src/plugins/tell/mod.rs29
1 files changed, 10 insertions, 19 deletions
diff --git a/src/plugins/tell/mod.rs b/src/plugins/tell/mod.rs
index 851fa94..be2e17b 100644
--- a/src/plugins/tell/mod.rs
+++ b/src/plugins/tell/mod.rs
@@ -1,9 +1,8 @@
use irc::client::prelude::*;
-
-use std::time::Duration;
-use std::sync::Mutex;
+use antidote::RwLock;
use time;
+use std::time::Duration;
use chrono::NaiveDateTime;
use humantime::format_duration;
@@ -18,24 +17,15 @@ use self::error::*;
pub mod database;
use self::database::Database;
-macro_rules! try_lock {
- ( $m:expr ) => {
- match $m.lock() {
- Ok(guard) => guard,
- Err(poisoned) => poisoned.into_inner(),
- }
- }
-}
-
-#[derive(PluginName, Default)]
+#[derive(PluginName)]
pub struct Tell<T: Database> {
- tells: Mutex<T>,
+ tells: RwLock<T>,
}
impl<T: Database> Tell<T> {
pub fn new(db: T) -> Tell<T> {
Tell {
- tells: Mutex::new(db),
+ tells: RwLock::new(db),
}
}
@@ -71,7 +61,8 @@ impl<T: Database> Tell<T> {
.map(|channel| client.list_users(&channel))
.map(|option| {
option.and_then(|users| {
- users.into_iter()
+ users
+ .into_iter()
.find(|user| user.get_nickname().eq_ignore_ascii_case(&receiver))
})
})
@@ -91,7 +82,7 @@ impl<T: Database> Tell<T> {
};
debug!("Saving tell for {:?}", receiver);
- try_lock!(self.tells).insert_tell(&tell)?;
+ self.tells.write().insert_tell(&tell)?;
no_receiver = false;
}
@@ -107,7 +98,7 @@ impl<T: Database> Tell<T> {
}
fn on_namelist(&self, client: &IrcClient, channel: &str) -> Result<(), FrippyError> {
- let receivers = try_lock!(self.tells)
+ let receivers = self.tells.read()
.get_receivers()
.context(FrippyErrorKind::Tell)?;
@@ -133,7 +124,7 @@ impl<T: Database> Tell<T> {
return Ok(());
}
- let mut tells = try_lock!(self.tells);
+ let mut tells = self.tells.write();
let tell_messages = match tells.get_tells(&receiver.to_lowercase()) {
Ok(t) => t,