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
14ba0c19
Commit
14ba0c19
authored
4 years ago
by
Rye Mutt
Browse files
Options
Downloads
Patches
Plain Diff
Change LLMutex internal mutex type from std::mutex to absl::Mutex
parent
2cafc3a6
No related branches found
No related tags found
No related merge requests found
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
indra/llcommon/llmutex.cpp
+10
-41
10 additions, 41 deletions
indra/llcommon/llmutex.cpp
indra/llcommon/llmutex.h
+32
-12
32 additions, 12 deletions
indra/llcommon/llmutex.h
with
42 additions
and
53 deletions
indra/llcommon/llmutex.cpp
+
10
−
41
View file @
14ba0c19
...
@@ -45,7 +45,7 @@ void LLMutex::lock()
...
@@ -45,7 +45,7 @@ void LLMutex::lock()
return
;
return
;
}
}
mMutex
.
l
ock
();
mMutex
.
L
ock
();
#if MUTEX_DEBUG
#if MUTEX_DEBUG
// Have to have the lock before we can access the debug info
// Have to have the lock before we can access the debug info
...
@@ -75,18 +75,18 @@ void LLMutex::unlock()
...
@@ -75,18 +75,18 @@ void LLMutex::unlock()
#endif
#endif
mLockingThread
=
LLThread
::
id_t
();
mLockingThread
=
LLThread
::
id_t
();
mMutex
.
u
nlock
();
mMutex
.
U
nlock
();
}
}
bool
LLMutex
::
isLocked
()
bool
LLMutex
::
isLocked
()
{
{
if
(
!
mMutex
.
t
ry
_l
ock
())
if
(
!
mMutex
.
T
ry
L
ock
())
{
{
return
true
;
return
true
;
}
}
else
else
{
{
mMutex
.
u
nlock
();
mMutex
.
U
nlock
();
return
false
;
return
false
;
}
}
}
}
...
@@ -109,7 +109,7 @@ bool LLMutex::trylock()
...
@@ -109,7 +109,7 @@ bool LLMutex::trylock()
return
true
;
return
true
;
}
}
if
(
!
mMutex
.
t
ry
_l
ock
())
if
(
!
mMutex
.
T
ry
L
ock
())
{
{
return
false
;
return
false
;
}
}
...
@@ -136,50 +136,19 @@ LLCondition::LLCondition() :
...
@@ -136,50 +136,19 @@ LLCondition::LLCondition() :
void
LLCondition
::
wait
()
void
LLCondition
::
wait
()
{
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mMutex
);
mMutex
.
Lock
();
mCond
.
wait
(
lock
);
mCond
.
Wait
(
&
mMutex
);
mMutex
.
Unlock
();
}
}
void
LLCondition
::
signal
()
void
LLCondition
::
signal
()
{
{
mCond
.
notify_one
();
mCond
.
Signal
();
}
}
void
LLCondition
::
broadcast
()
void
LLCondition
::
broadcast
()
{
{
mCond
.
notify_all
();
mCond
.
SignalAll
();
}
LLMutexTrylock
::
LLMutexTrylock
(
LLMutex
*
mutex
)
:
mMutex
(
mutex
),
mLocked
(
false
)
{
if
(
mMutex
)
mLocked
=
mMutex
->
trylock
();
}
LLMutexTrylock
::
LLMutexTrylock
(
LLMutex
*
mutex
,
U32
aTries
,
U32
delay_ms
)
:
mMutex
(
mutex
),
mLocked
(
false
)
{
if
(
!
mMutex
)
return
;
for
(
U32
i
=
0
;
i
<
aTries
;
++
i
)
{
mLocked
=
mMutex
->
trylock
();
if
(
mLocked
)
break
;
ms_sleep
(
delay_ms
);
}
}
LLMutexTrylock
::~
LLMutexTrylock
()
{
if
(
mMutex
&&
mLocked
)
mMutex
->
unlock
();
}
}
//============================================================================
//============================================================================
This diff is collapsed.
Click to expand it.
indra/llcommon/llmutex.h
+
32
−
12
View file @
14ba0c19
...
@@ -32,10 +32,6 @@
...
@@ -32,10 +32,6 @@
#include
"absl/synchronization/mutex.h"
#include
"absl/synchronization/mutex.h"
#include
<mutex>
#include
<condition_variable>
//============================================================================
//============================================================================
#define MUTEX_DEBUG (LL_DEBUG || LL_RELEASE_WITH_DEBUG_INFO)
#define MUTEX_DEBUG (LL_DEBUG || LL_RELEASE_WITH_DEBUG_INFO)
...
@@ -50,7 +46,6 @@ class LL_COMMON_API LLMutex
...
@@ -50,7 +46,6 @@ class LL_COMMON_API LLMutex
{
{
public:
public:
LLMutex
();
LLMutex
();
virtual
~
LLMutex
()
=
default
;
void
lock
();
// blocks
void
lock
();
// blocks
bool
trylock
();
// non-blocking, returns true if lock held.
bool
trylock
();
// non-blocking, returns true if lock held.
...
@@ -60,7 +55,7 @@ class LL_COMMON_API LLMutex
...
@@ -60,7 +55,7 @@ class LL_COMMON_API LLMutex
LLThread
::
id_t
lockingThread
()
const
;
//get ID of locking thread
LLThread
::
id_t
lockingThread
()
const
;
//get ID of locking thread
protected:
protected:
std
::
m
utex
mMutex
;
absl
::
M
utex
mMutex
;
mutable
U32
mCount
;
mutable
U32
mCount
;
mutable
LLThread
::
id_t
mLockingThread
;
mutable
LLThread
::
id_t
mLockingThread
;
...
@@ -70,18 +65,17 @@ class LL_COMMON_API LLMutex
...
@@ -70,18 +65,17 @@ class LL_COMMON_API LLMutex
};
};
// Actually a condition/mutex pair (since each condition needs to be associated with a mutex).
// Actually a condition/mutex pair (since each condition needs to be associated with a mutex).
class
LL_COMMON_API
LLCondition
:
public
LLMutex
class
LL_COMMON_API
LLCondition
final
:
public
LLMutex
{
{
public:
public:
LLCondition
();
LLCondition
();
~
LLCondition
()
=
default
;
void
wait
();
// blocks
void
wait
();
// blocks
void
signal
();
void
signal
();
void
broadcast
();
void
broadcast
();
protected:
protected:
std
::
c
ond
ition_variable
mCond
;
absl
::
C
ond
Var
mCond
;
};
};
class
LLMutexLock
class
LLMutexLock
...
@@ -120,9 +114,35 @@ class LLMutexLock
...
@@ -120,9 +114,35 @@ class LLMutexLock
class
LLMutexTrylock
class
LLMutexTrylock
{
{
public:
public:
LLMutexTrylock
(
LLMutex
*
mutex
);
LLMutexTrylock
(
LLMutex
*
mutex
)
LLMutexTrylock
(
LLMutex
*
mutex
,
U32
aTries
,
U32
delay_ms
=
10
);
:
mMutex
(
mutex
),
~
LLMutexTrylock
();
mLocked
(
false
)
{
if
(
mMutex
)
mLocked
=
mMutex
->
trylock
();
}
LLMutexTrylock
(
LLMutex
*
mutex
,
U32
aTries
,
U32
delay_ms
)
:
mMutex
(
mutex
),
mLocked
(
false
)
{
if
(
!
mMutex
)
return
;
for
(
U32
i
=
0
;
i
<
aTries
;
++
i
)
{
mLocked
=
mMutex
->
trylock
();
if
(
mLocked
)
break
;
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
delay_ms
));
}
}
~
LLMutexTrylock
()
{
if
(
mMutex
&&
mLocked
)
mMutex
->
unlock
();
}
bool
isLocked
()
const
bool
isLocked
()
const
{
{
...
...
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