aboutsummaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authorErk- <[email protected]>2018-10-15 19:59:49 +0200
committerLakelezz <[email protected]>2018-10-15 19:59:49 +0200
commitb2362dbb0014781bd7757a9e322ae3b8d5f2fadf (patch)
treedb77d2842f5320c39b0d1a957b6e4394dcc994e4 /src/client
parentFix Default Command to inherit Group-Options (#412) (diff)
downloadserenity-b2362dbb0014781bd7757a9e322ae3b8d5f2fadf.tar.xz
serenity-b2362dbb0014781bd7757a9e322ae3b8d5f2fadf.zip
Add configuration for the write lock the cache is using to update (#415)
Diffstat (limited to 'src/client')
-rw-r--r--src/client/dispatch.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/client/dispatch.rs b/src/client/dispatch.rs
index 5f88c34..f3585a8 100644
--- a/src/client/dispatch.rs
+++ b/src/client/dispatch.rs
@@ -25,20 +25,29 @@ use std::time::Duration;
#[cfg(feature = "cache")]
use super::CACHE;
+lazy_static! {
+ pub static ref CACHE_TRY_WRITE_DURATION: Option<Duration> =
+ CACHE.read().get_try_write_duration();
+}
+
macro_rules! update {
($event:expr) => {
{
#[cfg(feature = "cache")]
{
- if let Some(mut lock) = CACHE.try_write_for(Duration::from_millis(10)) {
- lock.update(&mut $event)
+ if let Some(duration) = *CACHE_TRY_WRITE_DURATION {
+ CACHE.try_write_for(duration)
+ .and_then(|mut lock| lock.update(&mut $event))
+ .or_else(|| {
+ warn!(
+ "[dispatch] Possible deadlock: couldn't unlock cache to update with event: {:?}",
+ $event,
+ );
+
+ None
+ })
} else {
- warn!(
- "[dispatch] Possible deadlock: couldn't unlock cache to update with event: {:?}",
- $event,
- );
-
- None
+ CACHE.write().update(&mut $event)
}
}
}