From c659bbd756391fc26e9e862937ef77113ee892ed Mon Sep 17 00:00:00 2001 From: Zeyla Hellyer Date: Sun, 27 May 2018 11:02:01 -0700 Subject: Remove deadlocking in Member::highest_role_info Instead of calling `parking_lot::RwLock::read` on the member's guild, call `parking_lot::RwLock::try_read` and return None early if it would cause a deadlock. --- src/model/guild/member.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/model/guild/member.rs b/src/model/guild/member.rs index cc6bc2a..c95c07f 100644 --- a/src/model/guild/member.rs +++ b/src/model/guild/member.rs @@ -240,21 +240,19 @@ impl Member { /// Retrieves the ID and position of the member's highest role in the /// hierarchy, if they have one. /// - /// This _may_ return `None` if the user has roles, but they are not present - /// in the cache for cache inconsistency reasons. + /// This _may_ return `None` if: + /// + /// - the user has roles, but they are not present in the cache for cache + /// inconsistency reasons + /// - you already have a write lock to the member's guild /// /// The "highest role in hierarchy" is defined as the role with the highest /// position. If two or more roles have the same highest position, then the /// role with the lowest ID is the highest. - /// - /// # Deadlocking - /// - /// This function will deadlock if you have a write lock to the member's - /// guild. #[cfg(feature = "cache")] pub fn highest_role_info(&self) -> Option<(RoleId, i64)> { let guild = self.guild_id.find()?; - let reader = guild.read(); + let reader = guild.try_read()?; let mut highest = None; -- cgit v1.2.3