Skip to content

Commit

Permalink
fix(gpu): use shared locks to check for an exclusive lock (filecoin-p…
Browse files Browse the repository at this point in the history
…roject#213)

Trying to use an exclusive lock, means that the file is actually getting locked
exclusively, even if we just want to check if there is an exclusive lock.
Additionally we now check for the correct error when checking the lock
  • Loading branch information
dignifiedquire authored Aug 31, 2021
1 parent 88bf7a5 commit ab40fb6
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/gpu/locks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,37 @@ impl PriorityLock {
debug!("Priority lock acquired!");
PriorityLock(f)
}

pub fn wait(priority: bool) {
if !priority {
File::create(tmp_path(PRIORITY_LOCK_NAME))
if let Err(err) = File::create(tmp_path(PRIORITY_LOCK_NAME))
.unwrap()
.lock_exclusive()
.unwrap();
{
warn!("failed to create priority log: {:?}", err);
}
}
}

pub fn should_break(priority: bool) -> bool {
!priority
&& File::create(tmp_path(PRIORITY_LOCK_NAME))
.unwrap()
.try_lock_exclusive()
.is_err()
if priority {
return false;
}
if let Err(err) = File::create(tmp_path(PRIORITY_LOCK_NAME))
.unwrap()
.try_lock_shared()
{
// Check that the error is actually a locking one
if err.raw_os_error() == fs2::lock_contended_error().raw_os_error() {
return true;
} else {
warn!("failed to check lock: {:?}", err);
}
}
false
}
}

impl Drop for PriorityLock {
fn drop(&mut self) {
self.0.unlock().unwrap();
Expand Down

0 comments on commit ab40fb6

Please sign in to comment.