Googletest export
Remove GoogleTest's SleepMilliseconds function. It is only used in tests and a portable implementation is available. PiperOrigin-RevId: 405437102
This commit is contained in:
parent
f503588aee
commit
489ef888d9
@ -1163,21 +1163,8 @@ void ClearInjectableArgvs();
|
|||||||
|
|
||||||
// Defines synchronization primitives.
|
// Defines synchronization primitives.
|
||||||
#if GTEST_IS_THREADSAFE
|
#if GTEST_IS_THREADSAFE
|
||||||
# if GTEST_HAS_PTHREAD
|
|
||||||
// Sleeps for (roughly) n milliseconds. This function is only for testing
|
|
||||||
// Google Test's own constructs. Don't use it in user tests, either
|
|
||||||
// directly or indirectly.
|
|
||||||
inline void SleepMilliseconds(int n) {
|
|
||||||
const timespec time = {
|
|
||||||
0, // 0 seconds.
|
|
||||||
n * 1000L * 1000L, // And n ms.
|
|
||||||
};
|
|
||||||
nanosleep(&time, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
# elif GTEST_OS_WINDOWS
|
|
||||||
GTEST_API_ void SleepMilliseconds(int n);
|
|
||||||
|
|
||||||
|
# if GTEST_OS_WINDOWS
|
||||||
// Provides leak-safe Windows kernel handle ownership.
|
// Provides leak-safe Windows kernel handle ownership.
|
||||||
// Used in death tests and in threading support.
|
// Used in death tests and in threading support.
|
||||||
class GTEST_API_ AutoHandle {
|
class GTEST_API_ AutoHandle {
|
||||||
@ -1206,7 +1193,6 @@ class GTEST_API_ AutoHandle {
|
|||||||
|
|
||||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
|
GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
|
||||||
};
|
};
|
||||||
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if GTEST_HAS_NOTIFICATION_
|
# if GTEST_HAS_NOTIFICATION_
|
||||||
|
@ -280,10 +280,6 @@ size_t GetThreadCount() {
|
|||||||
|
|
||||||
#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
|
#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
|
||||||
|
|
||||||
void SleepMilliseconds(int n) {
|
|
||||||
::Sleep(static_cast<DWORD>(n));
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoHandle::AutoHandle()
|
AutoHandle::AutoHandle()
|
||||||
: handle_(INVALID_HANDLE_VALUE) {}
|
: handle_(INVALID_HANDLE_VALUE) {}
|
||||||
|
|
||||||
|
@ -36,8 +36,10 @@
|
|||||||
# include <time.h>
|
# include <time.h>
|
||||||
#endif // GTEST_OS_MAC
|
#endif // GTEST_OS_MAC
|
||||||
|
|
||||||
|
#include <chrono> // NOLINT
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <thread> // NOLINT
|
||||||
#include <utility> // For std::pair and std::make_pair.
|
#include <utility> // For std::pair and std::make_pair.
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -333,7 +335,7 @@ TEST(GetThreadCountTest, ReturnsCorrectValue) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SleepMilliseconds(100);
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Retry if an arbitrary other thread was created or destroyed.
|
// Retry if an arbitrary other thread was created or destroyed.
|
||||||
@ -1050,7 +1052,7 @@ class AtomicCounterWithMutex {
|
|||||||
int temp = value_;
|
int temp = value_;
|
||||||
{
|
{
|
||||||
// We need to put up a memory barrier to prevent reads and writes to
|
// We need to put up a memory barrier to prevent reads and writes to
|
||||||
// value_ rearranged with the call to SleepMilliseconds when observed
|
// value_ rearranged with the call to sleep_for when observed
|
||||||
// from other threads.
|
// from other threads.
|
||||||
#if GTEST_HAS_PTHREAD
|
#if GTEST_HAS_PTHREAD
|
||||||
// On POSIX, locking a mutex puts up a memory barrier. We cannot use
|
// On POSIX, locking a mutex puts up a memory barrier. We cannot use
|
||||||
@ -1061,7 +1063,8 @@ class AtomicCounterWithMutex {
|
|||||||
pthread_mutex_init(&memory_barrier_mutex, nullptr));
|
pthread_mutex_init(&memory_barrier_mutex, nullptr));
|
||||||
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&memory_barrier_mutex));
|
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&memory_barrier_mutex));
|
||||||
|
|
||||||
SleepMilliseconds(static_cast<int>(random_.Generate(30)));
|
std::this_thread::sleep_for(
|
||||||
|
std::chrono::milliseconds(random_.Generate(30)));
|
||||||
|
|
||||||
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&memory_barrier_mutex));
|
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&memory_barrier_mutex));
|
||||||
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&memory_barrier_mutex));
|
GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&memory_barrier_mutex));
|
||||||
@ -1069,7 +1072,8 @@ class AtomicCounterWithMutex {
|
|||||||
// On Windows, performing an interlocked access puts up a memory barrier.
|
// On Windows, performing an interlocked access puts up a memory barrier.
|
||||||
volatile LONG dummy = 0;
|
volatile LONG dummy = 0;
|
||||||
::InterlockedIncrement(&dummy);
|
::InterlockedIncrement(&dummy);
|
||||||
SleepMilliseconds(static_cast<int>(random_.Generate(30)));
|
std::this_thread::sleep_for(
|
||||||
|
std::chrono::milliseconds(random_.Generate(30)));
|
||||||
::InterlockedIncrement(&dummy);
|
::InterlockedIncrement(&dummy);
|
||||||
#else
|
#else
|
||||||
# error "Memory barrier not implemented on this platform."
|
# error "Memory barrier not implemented on this platform."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user