Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
0c28f56c
Commit
0c28f56c
authored
11 years ago
by
Lofar test build account
Browse files
Options
Downloads
Patches
Plain Diff
Task #5385: [mol] Added inverse ScopedLock to temporarily unlock a mutex
parent
309c8b59
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
LCS/Common/include/Common/Thread/Mutex.h
+11
-5
11 additions, 5 deletions
LCS/Common/include/Common/Thread/Mutex.h
LCS/Common/test/tMutex.cc
+7
-0
7 additions, 0 deletions
LCS/Common/test/tMutex.cc
with
18 additions
and
5 deletions
LCS/Common/include/Common/Thread/Mutex.h
+
11
−
5
View file @
0c28f56c
...
...
@@ -70,7 +70,11 @@ class Mutex
class
ScopedLock
{
public:
ScopedLock
(
Mutex
&
);
// Locks a mutex while this objects exists.
//
// If unlock = true, the working is reversed:
// the mutex is unlocked while this object exists.
ScopedLock
(
Mutex
&
,
bool
unlock
=
false
);
~
ScopedLock
();
private:
...
...
@@ -78,6 +82,7 @@ class ScopedLock
ScopedLock
&
operator
=
(
const
ScopedLock
&
);
Mutex
&
itsMutex
;
const
bool
itsUnlock
;
};
...
...
@@ -159,18 +164,19 @@ inline bool Mutex::trylock()
}
inline
ScopedLock
::
ScopedLock
(
Mutex
&
mutex
)
inline
ScopedLock
::
ScopedLock
(
Mutex
&
mutex
,
bool
unlock
)
:
itsMutex
(
mutex
)
itsMutex
(
mutex
),
itsUnlock
(
unlock
)
{
itsMutex
.
lock
();
itsUnlock
?
itsMutex
.
unlock
()
:
itsMutex
.
lock
();
}
inline
ScopedLock
::~
ScopedLock
()
{
try
{
itsMutex
.
unlock
();
itsUnlock
?
itsMutex
.
lock
()
:
itsMutex
.
unlock
();
}
catch
(
std
::
exception
&
)
{}
}
...
...
This diff is collapsed.
Click to expand it.
LCS/Common/test/tMutex.cc
+
7
−
0
View file @
0c28f56c
...
...
@@ -58,6 +58,13 @@ void test_simple(Mutex::Type type) {
{
ScopedLock
sl
(
mutex
);
}
{
// scoped locking and unlocking should be stackable
ScopedLock
sl1
(
mutex
,
false
);
ScopedLock
sl2
(
mutex
,
true
);
ScopedLock
sl3
(
mutex
,
false
);
}
}
void
test_trylock
(
Mutex
::
Type
type
)
{
...
...
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