From 91cce8fb13ed86fb15d47e8c94c7e92a78091794 Mon Sep 17 00:00:00 2001 From: Aiden McClelland Date: Thu, 9 Sep 2021 11:19:54 -0600 Subject: [PATCH] feature log --- patch-db/Cargo.toml | 18 ++++++++++++++++-- patch-db/src/locker.rs | 8 ++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/patch-db/Cargo.toml b/patch-db/Cargo.toml index 594d0a5..6d5225a 100644 --- a/patch-db/Cargo.toml +++ b/patch-db/Cargo.toml @@ -20,6 +20,7 @@ indexmap = { version = "1.6.2", features = ["serde"] } json-patch = { path = "../json-patch" } json-ptr = { path = "../json-ptr" } lazy_static = "1.4.0" +log = { version = "*", optional = true } nix = "0.20.0" patch-db-macro = { path = "../patch-db-macro" } qutex = { path = "../qutex", package = "qutex-2" } @@ -27,9 +28,22 @@ serde = { version = "1.0.118", features = ["rc"] } serde_cbor = { path = "../cbor" } serde_json = "1.0.61" thiserror = "1.0.23" -tokio = { version = "1.0.1", features = ["sync", "fs", "rt", "io-util", "macros"] } +tokio = { version = "1.0.1", features = [ + "sync", + "fs", + "rt", + "io-util", + "macros", +] } [dev-dependencies] proptest = "1.0.0" serde = { version = "1.0.118", features = ["rc", "derive"] } -tokio = { version = "1.0.1", features = ["sync", "fs", "rt", "rt-multi-thread", "io-util", "macros"] } +tokio = { version = "1.0.1", features = [ + "sync", + "fs", + "rt", + "rt-multi-thread", + "io-util", + "macros", +] } diff --git a/patch-db/src/locker.rs b/patch-db/src/locker.rs index e59079a..f3144e1 100644 --- a/patch-db/src/locker.rs +++ b/patch-db/src/locker.rs @@ -82,6 +82,8 @@ impl Locker { ptr: &JsonPointer, deep: bool, ) -> ReadGuard> { + #[cfg(feature = "log")] + log::debug!("Locking {} for READ: {{ deep: {} }}", ptr, deep); let mut lock = Some(self.0.clone().read().await.unwrap()); for seg in ptr.iter() { let new_lock = if let Some(locker) = lock.as_ref().unwrap().get(seg) { @@ -98,6 +100,8 @@ impl Locker { if deep { Self::lock_root_read(&res); } + #[cfg(feature = "log")] + log::debug!("Locked {} for READ: {{ deep: {} }}", ptr, deep); res } pub(crate) async fn add_read_lock + Clone, V: SegList + Clone>( @@ -135,6 +139,8 @@ impl Locker { ptr: &JsonPointer, deep: bool, ) -> WriteGuard> { + #[cfg(feature = "log")] + log::debug!("Locking {} for WRITE: {{ deep: {} }}", ptr, deep); let mut lock = self.0.clone().write().await.unwrap(); for seg in ptr.iter() { let new_lock = if let Some(locker) = lock.get(seg) { @@ -149,6 +155,8 @@ impl Locker { if deep { Self::lock_root_write(&res); } + #[cfg(feature = "log")] + log::debug!("Locked {} for WRITE: {{ deep: {} }}", ptr, deep); res } pub(crate) async fn add_write_lock + Clone, V: SegList + Clone>(