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
68609388
authored
9 years ago
by
Danila Klimenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UniqueLock class: fixed documentation; updated unit test for the "Swap" method
parent
256a0f82
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
15 deletions
+7
-15
base_cpp/include/embb/base/mutex.h
+1
-1
base_cpp/test/mutex_test.cc
+6
-14
No files found.
base_cpp/include/embb/base/mutex.h
View file @
68609388
...
@@ -439,7 +439,7 @@ class UniqueLock {
...
@@ -439,7 +439,7 @@ class UniqueLock {
void
Unlock
();
void
Unlock
();
/**
/**
* Exchanges ownership of the wrapped mutex
es
with another lock.
* Exchanges ownership of the wrapped mutex with another lock.
*/
*/
void
Swap
(
void
Swap
(
UniqueLock
<
Mutex
>&
other
UniqueLock
<
Mutex
>&
other
...
...
This diff is collapsed.
Click to expand it.
base_cpp/test/mutex_test.cc
View file @
68609388
...
@@ -191,29 +191,21 @@ void MutexTest::TestUniqueLock() {
...
@@ -191,29 +191,21 @@ void MutexTest::TestUniqueLock() {
}
}
{
// Test lock swapping
{
// Test lock swapping
// Create a second mutex to swap with
UniqueLock
<>
lock1
(
mutex_
);
Mutex
another_mutex
;
UniqueLock
<>
lock1
(
another_mutex
);
PT_EXPECT_EQ
(
lock1
.
OwnsLock
(),
true
);
PT_EXPECT_EQ
(
lock1
.
OwnsLock
(),
true
);
{
{
UniqueLock
<>
lock2
(
mutex_
)
;
UniqueLock
<>
lock2
;
PT_EXPECT_EQ
(
lock2
.
OwnsLock
(),
tru
e
);
PT_EXPECT_EQ
(
lock2
.
OwnsLock
(),
fals
e
);
lock1
.
Swap
(
lock2
);
lock1
.
Swap
(
lock2
);
PT_EXPECT_EQ
(
lock1
.
OwnsLock
(),
tru
e
);
PT_EXPECT_EQ
(
lock1
.
OwnsLock
(),
fals
e
);
PT_EXPECT_EQ
(
lock2
.
OwnsLock
(),
true
);
PT_EXPECT_EQ
(
lock2
.
OwnsLock
(),
true
);
}
}
// At this point,
lock2 was destroyed and "another_mutex" must be unlocked
// At this point,
"lock2" was destroyed and "mutex_" must be unlocked.
UniqueLock
<>
lock3
(
another_mutex
,
embb
::
base
::
try_lock
);
UniqueLock
<>
lock3
(
mutex_
,
embb
::
base
::
try_lock
);
PT_EXPECT_EQ
(
lock3
.
OwnsLock
(),
true
);
PT_EXPECT_EQ
(
lock3
.
OwnsLock
(),
true
);
// But lock1 must still be locking "mutex_"
PT_EXPECT_EQ
(
lock1
.
OwnsLock
(),
true
);
lock1
.
Release
()
->
Unlock
();
PT_EXPECT_EQ
(
lock1
.
OwnsLock
(),
false
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
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