Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
cfb40870
Commit
cfb40870
authored
Jan 27, 2012
by
jgm
Browse files
Locking for Notification class.
parent
4d6f296e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
4 deletions
+19
-4
include/gtest/internal/gtest-port.h
include/gtest/internal/gtest-port.h
+19
-4
No files found.
include/gtest/internal/gtest-port.h
View file @
cfb40870
...
...
@@ -1102,22 +1102,37 @@ inline void SleepMilliseconds(int n) {
// use it in user tests, either directly or indirectly.
class
Notification
{
public:
Notification
()
:
notified_
(
false
)
{}
Notification
()
:
notified_
(
false
)
{
GTEST_CHECK_POSIX_SUCCESS_
(
pthread_mutex_init
(
&
mutex_
,
NULL
));
}
~
Notification
()
{
pthread_mutex_destroy
(
&
mutex_
);
}
// Notifies all threads created with this notification to start. Must
// be called from the controller thread.
void
Notify
()
{
notified_
=
true
;
}
void
Notify
()
{
pthread_mutex_lock
(
&
mutex_
);
notified_
=
true
;
pthread_mutex_unlock
(
&
mutex_
);
}
// Blocks until the controller thread notifies. Must be called from a test
// thread.
void
WaitForNotification
()
{
while
(
!
notified_
)
{
for
(;;)
{
pthread_mutex_lock
(
&
mutex_
);
const
bool
notified
=
notified_
;
pthread_mutex_unlock
(
&
mutex_
);
if
(
notified
)
break
;
SleepMilliseconds
(
10
);
}
}
private:
volatile
bool
notified_
;
pthread_mutex_t
mutex_
;
bool
notified_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
Notification
);
};
...
...
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