Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
a3244754
authored
Jun 16, 2015
by
Danila Klimenko
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'embb470_uniquelock_swap' into development
parents
ca9ffed3
68609388
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
10 deletions
+19
-10
base_cpp/include/embb/base/internal/mutex-inl.h
+3
-2
base_cpp/include/embb/base/mutex.h
+2
-2
base_cpp/test/mutex_test.cc
+14
-6
No files found.
base_cpp/include/embb/base/internal/mutex-inl.h
View file @
a3244754
...
...
@@ -28,6 +28,7 @@
#define EMBB_BASE_INTERNAL_MUTEX_INL_H_
#include <cassert>
#include <algorithm>
namespace
embb
{
namespace
base
{
...
...
@@ -95,8 +96,8 @@ void UniqueLock<Mutex>::Unlock() {
template
<
typename
Mutex
>
void
UniqueLock
<
Mutex
>::
Swap
(
UniqueLock
<
Mutex
>&
other
)
{
locked_
=
other
.
locked_
;
mutex_
=
other
.
Release
(
);
std
::
swap
(
mutex_
,
other
.
mutex_
)
;
std
::
swap
(
locked_
,
other
.
locked_
);
}
template
<
typename
Mutex
>
...
...
base_cpp/include/embb/base/mutex.h
View file @
a3244754
...
...
@@ -439,11 +439,11 @@ class UniqueLock {
void
Unlock
();
/**
*
Transfers ownership of a mutex to this
lock.
*
Exchanges ownership of the wrapped mutex with another
lock.
*/
void
Swap
(
UniqueLock
<
Mutex
>&
other
/**< [IN/OUT]
Lock from which ownership shall be transferred
*/
/**< [IN/OUT]
The lock to exchange ownership with
*/
);
/**
...
...
base_cpp/test/mutex_test.cc
View file @
a3244754
...
...
@@ -191,13 +191,21 @@ void MutexTest::TestUniqueLock() {
}
{
// Test lock swapping
UniqueLock
<>
lock1
;
UniqueLock
<>
lock2
(
mutex_
);
PT_EXPECT_EQ
(
lock1
.
OwnsLock
(),
false
);
PT_EXPECT_EQ
(
lock2
.
OwnsLock
(),
true
);
lock1
.
Swap
(
lock2
);
UniqueLock
<>
lock1
(
mutex_
);
PT_EXPECT_EQ
(
lock1
.
OwnsLock
(),
true
);
PT_EXPECT_EQ
(
lock2
.
OwnsLock
(),
false
);
{
UniqueLock
<>
lock2
;
PT_EXPECT_EQ
(
lock2
.
OwnsLock
(),
false
);
lock1
.
Swap
(
lock2
);
PT_EXPECT_EQ
(
lock1
.
OwnsLock
(),
false
);
PT_EXPECT_EQ
(
lock2
.
OwnsLock
(),
true
);
}
// At this point, "lock2" was destroyed and "mutex_" must be unlocked.
UniqueLock
<>
lock3
(
mutex_
,
embb
::
base
::
try_lock
);
PT_EXPECT_EQ
(
lock3
.
OwnsLock
(),
true
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment