From c85a77a6ab0ef05c4a9a8554bf8c5e1c8687cc75 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Fri, 26 Feb 2010 05:42:53 +0000 Subject: Simplifies ThreadStartSemaphore's implementation. --- src/gtest-port.cc | 40 ---------------------------------------- 1 file changed, 40 deletions(-) (limited to 'src') diff --git a/src/gtest-port.cc b/src/gtest-port.cc index 1c4c1bdc..b9504f56 100644 --- a/src/gtest-port.cc +++ b/src/gtest-port.cc @@ -75,46 +75,6 @@ const int kStdOutFileno = STDOUT_FILENO; const int kStdErrFileno = STDERR_FILENO; #endif // _MSC_VER -#if GTEST_HAS_PTHREAD - -// ThreadStartSemaphore allows the controller thread to pause execution of -// newly created test threads until signalled. Instances of this class must -// be created and destroyed in the controller thread. -ThreadStartSemaphore::ThreadStartSemaphore() : signalled_(false) { - GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, NULL)); - GTEST_CHECK_POSIX_SUCCESS_(pthread_cond_init(&cond_, NULL)); - pthread_mutex_lock(&mutex_); -} - -ThreadStartSemaphore::~ThreadStartSemaphore() { - // Every ThreadStartSemaphore object must be signalled. It locks - // internal mutex upon creation and Signal unlocks it. - GTEST_CHECK_(signalled_); - GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_)); - GTEST_CHECK_POSIX_SUCCESS_(pthread_cond_destroy(&cond_)); -} - -// Signals to all test threads to start. Must be called from the -// controlling thread. -void ThreadStartSemaphore::Signal() { - signalled_ = true; - GTEST_CHECK_POSIX_SUCCESS_(pthread_cond_signal(&cond_)); - GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_)); -} - -// Blocks until the controlling thread signals. Should be called from a -// test thread. -void ThreadStartSemaphore::Wait() { - GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_)); - - while (!signalled_) { - GTEST_CHECK_POSIX_SUCCESS_(pthread_cond_wait(&cond_, &mutex_)); - } - GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_)); -} - -#endif // GTEST_HAS_PTHREAD - #if GTEST_OS_MAC // Returns the number of threads running in the process, or 0 to indicate that -- cgit v1.2.3