aboutsummaryrefslogtreecommitdiff
path: root/src/model/guild
diff options
context:
space:
mode:
authorZeyla Hellyer <[email protected]>2018-05-27 11:02:01 -0700
committerZeyla Hellyer <[email protected]>2018-05-27 11:02:49 -0700
commitc659bbd756391fc26e9e862937ef77113ee892ed (patch)
tree7356f49c82036c6e61bfd05f6174d5dcce92910e /src/model/guild
parentDo some little optimizations on `find(_n)` (diff)
downloadserenity-c659bbd756391fc26e9e862937ef77113ee892ed.tar.xz
serenity-c659bbd756391fc26e9e862937ef77113ee892ed.zip
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.
Diffstat (limited to 'src/model/guild')
-rw-r--r--src/model/guild/member.rs14
1 files changed, 6 insertions, 8 deletions
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;