File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -1102,22 +1102,37 @@ inline void SleepMilliseconds(int n) {
1102
1102
// use it in user tests, either directly or indirectly.
1103
1103
class Notification {
1104
1104
public:
1105
- Notification () : notified_(false ) {}
1105
+ Notification () : notified_(false ) {
1106
+ GTEST_CHECK_POSIX_SUCCESS_ (pthread_mutex_init (&mutex_, NULL ));
1107
+ }
1108
+ ~Notification () {
1109
+ pthread_mutex_destroy (&mutex_);
1110
+ }
1106
1111
1107
1112
// Notifies all threads created with this notification to start. Must
1108
1113
// be called from the controller thread.
1109
- void Notify () { notified_ = true ; }
1114
+ void Notify () {
1115
+ pthread_mutex_lock (&mutex_);
1116
+ notified_ = true ;
1117
+ pthread_mutex_unlock (&mutex_);
1118
+ }
1110
1119
1111
1120
// Blocks until the controller thread notifies. Must be called from a test
1112
1121
// thread.
1113
1122
void WaitForNotification () {
1114
- while (!notified_) {
1123
+ for (;;) {
1124
+ pthread_mutex_lock (&mutex_);
1125
+ const bool notified = notified_;
1126
+ pthread_mutex_unlock (&mutex_);
1127
+ if (notified)
1128
+ break ;
1115
1129
SleepMilliseconds (10 );
1116
1130
}
1117
1131
}
1118
1132
1119
1133
private:
1120
- volatile bool notified_;
1134
+ pthread_mutex_t mutex_;
1135
+ bool notified_;
1121
1136
1122
1137
GTEST_DISALLOW_COPY_AND_ASSIGN_ (Notification);
1123
1138
};
You can’t perform that action at this time.
0 commit comments