| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3796a73 commit 95c7fc6
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1236,16 +1236,46 @@ class GTEST_API_ [[nodiscard]] AutoHandle { | |||
| 1236 | 1236 | // Nothing to do here. | |
| 1237 | 1237 | ||
| 1238 | 1238 | #else | |
| 1239 | - GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ | ||
| 1240 | - /* class A needs to have dll-interface to be used by clients of class B */) | ||
| 1241 | - | ||
| 1242 | 1239 | // Allows a controller thread to pause execution of newly created | |
| 1243 | 1240 | // threads until notified. Instances of this class must be created | |
| 1244 | 1241 | // and destroyed in the controller thread. | |
| 1245 | 1242 | // | |
| 1246 | 1243 | // This class is only for testing Google Test's own constructs. Do not | |
| 1247 | 1244 | // use it in user tests, either directly or indirectly. | |
| 1248 | 1245 | // TODO(b/203539622): Replace unconditionally with absl::Notification. | |
| 1246 | + #ifdef GTEST_OS_WINDOWS_MINGW | ||
| 1247 | + // GCC version < 13 with the win32 thread model does not provide std::mutex and | ||
| 1248 | + // std::condition_variable in the <mutex> and <condition_variable> headers. So | ||
| 1249 | + // we implement the Notification class using a Windows manual-reset event. See | ||
| 1250 | + // https://gcc.gnu.org/gcc-13/changes.html#windows. | ||
| 1251 | + class GTEST_API_ [[nodiscard]] Notification { | ||
| 1252 | + public: | ||
| 1253 | + Notification(); | ||
| 1254 | + Notification(const Notification&) = delete; | ||
| 1255 | + Notification& operator=(const Notification&) = delete; | ||
| 1256 | + ~Notification(); | ||
| 1257 | + | ||
| 1258 | + // Notifies all threads created with this notification to start. Must | ||
| 1259 | + // be called from the controller thread. | ||
| 1260 | + void Notify(); | ||
| 1261 | + | ||
| 1262 | + // Blocks until the controller thread notifies. Must be called from a test | ||
| 1263 | + // thread. | ||
| 1264 | + void WaitForNotification(); | ||
| 1265 | + | ||
| 1266 | + private: | ||
| 1267 | + // Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to | ||
| 1268 | + // avoid including <windows.h> in this header file. Including <windows.h> is | ||
| 1269 | + // undesirable because it defines a lot of symbols and macros that tend to | ||
| 1270 | + // conflict with client code. This assumption is verified by | ||
| 1271 | + // WindowsTypesTest.HANDLEIsVoidStar. | ||
| 1272 | + typedef void* Handle; | ||
| 1273 | + Handle event_; | ||
| 1274 | + }; | ||
| 1275 | + #else | ||
| 1276 | + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ | ||
| 1277 | + /* class A needs to have dll-interface to be used by clients of class B */) | ||
| 1278 | + | ||
| 1249 | 1279 | class GTEST_API_ [[nodiscard]] Notification { | |
| 1250 | 1280 | public: | |
| 1251 | 1281 | Notification() : notified_(false) {} | |
@@ -1273,6 +1303,7 @@ class GTEST_API_ [[nodiscard]] Notification { | |||
| 1273 | 1303 | bool notified_; | |
| 1274 | 1304 | }; | |
| 1275 | 1305 | GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 | |
| 1306 | + #endif // GTEST_OS_WINDOWS_MINGW | ||
| 1276 | 1307 | #endif // GTEST_HAS_NOTIFICATION_ | |
| 1277 | 1308 | ||
| 1278 | 1309 | // On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -303,6 +303,22 @@ bool AutoHandle::IsCloseable() const { | |||
| 303 | 303 | return handle_ != nullptr && handle_ != INVALID_HANDLE_VALUE; | |
| 304 | 304 | } | |
| 305 | 305 | ||
| 306 | + #if !GTEST_HAS_NOTIFICATION_ && defined(GTEST_OS_WINDOWS_MINGW) | ||
| 307 | + Notification::Notification() { | ||
| 308 | + // Create a manual-reset event object. | ||
| 309 | + event_ = ::CreateEvent(nullptr, TRUE, FALSE, nullptr); | ||
| 310 | + GTEST_CHECK_(event_ != nullptr); | ||
| 311 | + } | ||
| 312 | + | ||
| 313 | + Notification::~Notification() { ::CloseHandle(event_); } | ||
| 314 | + | ||
| 315 | + void Notification::Notify() { GTEST_CHECK_(::SetEvent(event_)); } | ||
| 316 | + | ||
| 317 | + void Notification::WaitForNotification() { | ||
| 318 | + GTEST_CHECK_(::WaitForSingleObject(event_, INFINITE) == WAIT_OBJECT_0); | ||
| 319 | + } | ||
| 320 | + #endif // !GTEST_HAS_NOTIFICATION_ && defined(GTEST_OS_WINDOWS_MINGW) | ||
| 321 | + | ||
| 306 | 322 | Mutex::Mutex() | |
| 307 | 323 | : owner_thread_id_(0), | |
| 308 | 324 | type_(kDynamic), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments