File tree Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Expand file tree Collapse file tree 3 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,10 @@ class LLDB_API SBMutex {
3131 // / Releases ownership of this lock.
3232 void unlock () const ;
3333
34+ // / Tries to lock the mutex. Returns immediately. On successful lock
35+ // / acquisition returns true, otherwise returns false.
36+ bool try_lock () const ;
37+
3438private:
3539 // Private constructor used by SBTarget to create the Target API mutex.
3640 // Requires a friend declaration.
Original file line number Diff line number Diff line change @@ -58,3 +58,12 @@ void SBMutex::unlock() const {
5858 if (m_opaque_sp)
5959 m_opaque_sp->unlock ();
6060}
61+
62+ bool SBMutex::try_lock () const {
63+ LLDB_INSTRUMENT_VA (this );
64+
65+ if (m_opaque_sp)
66+ return m_opaque_sp->try_lock ();
67+
68+ return false ;
69+ }
Original file line number Diff line number Diff line change @@ -36,11 +36,16 @@ TEST_F(SBMutexTest, LockTest) {
3636 std::future<void > f;
3737 {
3838 lldb::SBMutex lock = target.GetAPIMutex ();
39+
40+ ASSERT_TRUE (lock.try_lock ());
41+ lock.unlock ();
42+
3943 std::lock_guard<lldb::SBMutex> lock_guard (lock);
4044 ASSERT_FALSE (locked.exchange (true ));
4145
4246 f = std::async (std::launch::async, [&]() {
4347 ASSERT_TRUE (locked);
48+ EXPECT_FALSE (lock.try_lock ());
4449 target.BreakpointCreateByName (" foo" , " bar" );
4550 ASSERT_FALSE (locked);
4651 });
You can’t perform that action at this time.
0 commit comments