Skip to content

Added UScopeMutex::lockTry() support - #1777

Merged
matlabbe merged 3 commits into
masterfrom
scope_mutex_lock_try
Sep 28, 2026
Merged

matlabbe merged 3 commits into
masterfrom
scope_mutex_lock_try

Conversation

@matlabbe

@matlabbe matlabbe commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

The idea is that we can use the scope mutex to "try lock" the mutex, so that it is safer to use instead of not forgetting to put UMutex::unlock() on all possible return branches.

if(mutex_.tryLock() == 0)
{
  // Someone forgot to unlock before returning in this pre-condition check...
  if(<some condition>) 
    return false;

  // do protected stuff...

  mutex_.unlock(); // never reached if condition triggered above
}
return true;

With the scope mutex, it is safer:

UScopeMutex lock(mutex_, false);
if(lock.tryLock() == 0)
{
  if(<some condition>) 
    return false; // <--- lock out of scope: mutex_ auto unlocked

  // do protected stuff...
}
return true; //  <--- lock out of scope: mutex_  auto unlocked if it was locked

or c++17:

if(UScopeMutex lock(mutex_, false); lock.tryLock() == 0)
{
  if(<some condition>) 
    return false; // <--- lock out of scope: mutex_ auto unlocked

  // do protected stuff...
} // <--- lock out of scope: mutex_  auto unlocked if it was locked

// do some other unprotected stuff...

return true; 

@codecov

codecov Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.98%. Comparing base (8035be5) to head (90e5a21).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1777      +/-   ##
==========================================
+ Coverage   61.97%   61.98%   +0.01%     
==========================================
  Files         291      291              
  Lines       51361    51383      +22     
==========================================
+ Hits        31830    31852      +22     
  Misses      19531    19531              
Files with missing lines Coverage Δ
utilite/include/rtabmap/utilite/UMutex.h 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

github-actions Bot added a commit that referenced this pull request Sep 27, 2026
github-actions Bot added a commit that referenced this pull request Sep 28, 2026
@matlabbe
matlabbe merged commit 0f98c63 into master Sep 28, 2026
38 of 45 checks passed
@matlabbe
matlabbe deleted the scope_mutex_lock_try branch September 28, 2026 16:22
github-actions Bot added a commit that referenced this pull request Sep 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant