Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
ae325716
Commit
ae325716
authored
2 years ago
by
Rye Mutt
Browse files
Options
Downloads
Patches
Plain Diff
Swap LLMutex impl to recursive_mutex to avoid reinventing the wheel
parent
e01309b7
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
indra/llcommon/llmutex.cpp
+2
-63
2 additions, 63 deletions
indra/llcommon/llmutex.cpp
indra/llcommon/llmutex.h
+1
-9
1 addition, 9 deletions
indra/llcommon/llmutex.h
indra/llcommon/llsingleton.h
+2
-3
2 additions, 3 deletions
indra/llcommon/llsingleton.h
with
5 additions
and
75 deletions
indra/llcommon/llmutex.cpp
+
2
−
63
View file @
ae325716
...
...
@@ -34,43 +34,12 @@
void
LLMutex
::
lock
()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD
if
(
isSelfLocked
())
{
//redundant lock
mCount
++
;
return
;
}
mMutex
.
lock
();
#if MUTEX_DEBUG
// Have to have the lock before we can access the debug info
auto
id
=
LLThread
::
currentID
();
if
(
mIsLocked
[
id
]
!=
FALSE
)
LL_ERRS
()
<<
"Already locked in Thread: "
<<
id
<<
LL_ENDL
;
mIsLocked
[
id
]
=
TRUE
;
#endif
mLockingThread
=
LLThread
::
currentID
();
}
void
LLMutex
::
unlock
()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD
if
(
mCount
>
0
)
{
//not the root unlock
mCount
--
;
return
;
}
#if MUTEX_DEBUG
// Access the debug info while we have the lock
auto
id
=
LLThread
::
currentID
();
if
(
mIsLocked
[
id
]
!=
TRUE
)
LL_ERRS
()
<<
"Not locked in Thread: "
<<
id
<<
LL_ENDL
;
mIsLocked
[
id
]
=
FALSE
;
#endif
mLockingThread
=
LLThread
::
id_t
();
mMutex
.
unlock
();
}
...
...
@@ -88,40 +57,10 @@ bool LLMutex::isLocked()
}
}
bool
LLMutex
::
isSelfLocked
()
{
return
mLockingThread
==
LLThread
::
currentID
();
}
LLThread
::
id_t
LLMutex
::
lockingThread
()
const
{
return
mLockingThread
;
}
bool
LLMutex
::
try_lock
()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD
if
(
isSelfLocked
())
{
//redundant lock
mCount
++
;
return
true
;
}
if
(
!
mMutex
.
try_lock
())
{
return
false
;
}
#if MUTEX_DEBUG
// Have to have the lock before we can access the debug info
auto
id
=
LLThread
::
currentID
();
if
(
mIsLocked
[
id
]
!=
FALSE
)
LL_ERRS
()
<<
"Already locked in Thread: "
<<
id
<<
LL_ENDL
;
mIsLocked
[
id
]
=
TRUE
;
#endif
mLockingThread
=
LLThread
::
currentID
();
return
true
;
return
mMutex
.
try_lock
();
}
//============================================================================
...
...
@@ -135,7 +74,7 @@ LLCondition::LLCondition() :
void
LLCondition
::
wait
()
{
LL_PROFILE_ZONE_SCOPED_CATEGORY_THREAD
std
::
unique_lock
<
std
::
shared
_mutex
>
lock
(
mMutex
);
std
::
unique_lock
<
std
::
recursive
_mutex
>
lock
(
mMutex
);
mCond
.
wait
(
lock
);
}
...
...
This diff is collapsed.
Click to expand it.
indra/llcommon/llmutex.h
+
1
−
9
View file @
ae325716
...
...
@@ -52,17 +52,9 @@ class LL_COMMON_API LLMutex
bool
try_lock
();
// non-blocking, returns true if lock held.
void
unlock
();
// undefined behavior when called on mutex not being held
bool
isLocked
();
// non-blocking, but does do a lock/unlock so not free
bool
isSelfLocked
();
//return true if locked in a same thread
LLThread
::
id_t
lockingThread
()
const
;
//get ID of locking thread
protected:
std
::
shared_mutex
mMutex
;
mutable
U32
mCount
=
0
;
mutable
LLThread
::
id_t
mLockingThread
;
#if MUTEX_DEBUG
std
::
map
<
LLThread
::
id_t
,
BOOL
>
mIsLocked
;
#endif
std
::
recursive_mutex
mMutex
;
};
// Actually a condition/mutex pair (since each condition needs to be associated with a mutex).
...
...
This diff is collapsed.
Click to expand it.
indra/llcommon/llsingleton.h
+
2
−
3
View file @
ae325716
...
...
@@ -31,11 +31,10 @@
#include
<list>
#include
<typeinfo>
#include
<vector>
#include
<shared_
mutex
>
#include
"
mutex
.h"
#include
"lockstatic.h"
#include
"llthread.h"
// on_main_thread()
#include
"llmainthreadtask.h"
#include
"llmutex.h"
class
LLSingletonBase
:
private
boost
::
noncopyable
{
...
...
@@ -293,7 +292,7 @@ class LLSingleton : public LLSingletonBase
{
// Use a recursive_mutex in case of constructor circularity. With a
// non-recursive mutex, that would result in deadlock.
typedef
LLM
utex
mutex_t
;
typedef
std
::
recursive_m
utex
mutex_t
;
mutex_t
mMutex
;
// LockStatic looks for mMutex
EInitState
mInitState
{
UNINITIALIZED
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment