Export Test - Do Not Merge
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
8cd676a484
commit
8a9094f673
@ -1163,21 +1163,8 @@ void ClearInjectableArgvs();
|
||||
|
||||
// Defines synchronization primitives.
|
||||
#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.
|
||||
// Used in death tests and in threading support.
|
||||
class GTEST_API_ AutoHandle {
|
||||
@ -1206,7 +1193,6 @@ class GTEST_API_ AutoHandle {
|
||||
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle);
|
||||
};
|
||||
|
||||
# endif
|
||||
|
||||
# if GTEST_HAS_NOTIFICATION_
|
||||
|
@ -280,10 +280,6 @@ size_t GetThreadCount() {
|
||||
|
||||
#if GTEST_IS_THREADSAFE && GTEST_OS_WINDOWS
|
||||
|
||||
void SleepMilliseconds(int n) {
|
||||
::Sleep(static_cast<DWORD>(n));
|
||||
}
|
||||
|
||||
AutoHandle::AutoHandle()
|
||||
: handle_(INVALID_HANDLE_VALUE) {}
|
||||
|
||||
|
@ -36,8 +36,10 @@
|
||||
# include <time.h>
|
||||
#endif // GTEST_OS_MAC
|
||||
|
||||
#include <chrono> // NOLINT
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <thread> // NOLINT
|
||||
#include <utility> // For std::pair and std::make_pair.
|
||||
#include <vector>
|
||||
|
||||
@ -333,7 +335,7 @@ TEST(GetThreadCountTest, ReturnsCorrectValue) {
|
||||
break;
|
||||
}
|
||||
|
||||
SleepMilliseconds(100);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
}
|
||||
|
||||
// Retry if an arbitrary other thread was created or destroyed.
|
||||
@ -1050,7 +1052,7 @@ class AtomicCounterWithMutex {
|
||||
int temp = value_;
|
||||
{
|
||||
// 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.
|
||||
#if GTEST_HAS_PTHREAD
|
||||
// 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));
|
||||
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_destroy(&memory_barrier_mutex));
|
||||
@ -1069,7 +1072,8 @@ class AtomicCounterWithMutex {
|
||||
// On Windows, performing an interlocked access puts up a memory barrier.
|
||||
volatile LONG dummy = 0;
|
||||
::InterlockedIncrement(&dummy);
|
||||
SleepMilliseconds(static_cast<int>(random_.Generate(30)));
|
||||
std::this_thread::sleep_for(
|
||||
std::chrono::milliseconds(random_.Generate(30)));
|
||||
::InterlockedIncrement(&dummy);
|
||||
#else
|
||||
# error "Memory barrier not implemented on this platform."
|
||||
|
Loading…
Reference in New Issue
Block a user