Index: third_party/tcmalloc/chromium/src/tests/malloc_hook_test.cc |
=================================================================== |
--- third_party/tcmalloc/chromium/src/tests/malloc_hook_test.cc (revision 124832) |
+++ third_party/tcmalloc/chromium/src/tests/malloc_hook_test.cc (working copy) |
@@ -36,25 +36,16 @@ |
#ifdef HAVE_MMAP |
#include <sys/mman.h> |
#endif |
-#ifdef HAVE_UNISTD_H |
-#include <unistd.h> // for sleep() |
-#endif |
#include <algorithm> |
#include <string> |
#include <vector> |
-#include <gperftools/malloc_hook.h> |
+#include <google/malloc_hook.h> |
#include "malloc_hook-inl.h" |
#include "base/logging.h" |
-#include "base/simple_mutex.h" |
+#include "base/spinlock.h" |
#include "base/sysinfo.h" |
#include "tests/testutil.h" |
-// On systems (like freebsd) that don't define MAP_ANONYMOUS, use the old |
-// form of the name instead. |
-#ifndef MAP_ANONYMOUS |
-# define MAP_ANONYMOUS MAP_ANON |
-#endif |
- |
namespace { |
using std::string; |
@@ -81,15 +72,6 @@ |
return 0; |
} |
-void Sleep(int seconds) { |
-#ifdef _MSC_VER |
- _sleep(seconds * 1000); // Windows's _sleep takes milliseconds argument |
-#else |
- sleep(seconds); |
-#endif |
-} |
- |
-using std::min; |
using base::internal::kHookListMaxValues; |
// Since HookList is a template and is defined in malloc_hook.cc, we can only |
@@ -99,7 +81,7 @@ |
int TestHookList_Traverse(const TestHookList& list, int* output_array, int n) { |
MallocHook::NewHook values_as_hooks[kHookListMaxValues]; |
- int result = list.Traverse(values_as_hooks, min(n, kHookListMaxValues)); |
+ int result = list.Traverse(values_as_hooks, std::min(n, kHookListMaxValues)); |
for (int i = 0; i < result; ++i) { |
output_array[i] = reinterpret_cast<const int&>(values_as_hooks[i]); |
} |
@@ -247,12 +229,12 @@ |
static volatile int num_threads_remaining; |
static TestHookList list = INIT_HOOK_LIST(69); |
-static Mutex threadcount_lock; |
+static SpinLock threadcount_lock; |
void MultithreadedTestThreadRunner(int thread_num) { |
// Wait for all threads to start running. |
{ |
- MutexLock ml(&threadcount_lock); |
+ SpinLockHolder h(&threadcount_lock); |
assert(num_threads_remaining > 0); |
--num_threads_remaining; |
@@ -260,7 +242,7 @@ |
// go simple and busy-wait. |
while (num_threads_remaining > 0) { |
threadcount_lock.Unlock(); |
- Sleep(1); |
+ SleepForMilliseconds(100); |
threadcount_lock.Lock(); |
} |
} |
@@ -289,10 +271,7 @@ |
EXPECT_EQ(0, list.priv_end); |
} |
-// We only do mmap-hooking on (some) linux systems. |
-#if defined(HAVE_MMAP) && defined(__linux) && \ |
- (defined(__i386__) || defined(__x86_64__) || defined(__PPC__)) |
- |
+#ifdef HAVE_MMAP |
int mmap_calls = 0; |
int mmap_matching_calls = 0; |
int munmap_calls = 0; |
@@ -357,7 +336,7 @@ |
// whoever owns that memory now. |
// EXPECT_DEATH(*ptr = 'a', "SIGSEGV"); |
} |
-#endif // #ifdef HAVE_MMAP && linux && ... |
+#endif // #ifdef HAVE_MMAN |
} // namespace |