diff options
author | Aliaksey Kandratsenka <alk@tut.by> | 2013-09-21 18:14:00 -0700 |
---|---|---|
committer | Aliaksey Kandratsenka <alk@tut.by> | 2014-01-18 17:23:14 -0800 |
commit | 54568e32fc2321e0adef15fb1eab4e3a7f8ce5b0 (patch) | |
tree | d28c1c773693dd9f875831cf438c788baeab8702 /src | |
parent | 64bc1baa1f4723d73ba40cd730b72896bd45a810 (diff) | |
download | gperftools-54568e32fc2321e0adef15fb1eab4e3a7f8ce5b0.tar.gz |
issue-565: don't pollute global namespace with thread lister API
Instead those functions that are original taken from google's "base"
code now have prefix TCMalloc_. So that they don't conflict with other
google's libraries having same functions.
Diffstat (limited to 'src')
-rw-r--r-- | src/base/linuxthreads.cc | 24 | ||||
-rw-r--r-- | src/base/thread_lister.c | 6 | ||||
-rw-r--r-- | src/base/thread_lister.h | 14 | ||||
-rw-r--r-- | src/gperftools/heap-checker.h | 6 | ||||
-rwxr-xr-x | src/heap-checker.cc | 29 | ||||
-rw-r--r-- | src/memory_region_map.h | 2 |
6 files changed, 41 insertions, 40 deletions
diff --git a/src/base/linuxthreads.cc b/src/base/linuxthreads.cc index 11b35f9..ffa5cc2 100644 --- a/src/base/linuxthreads.cc +++ b/src/base/linuxthreads.cc @@ -194,9 +194,9 @@ static int c_open(const char *fname, int flags, int mode) { * In order to find the main application from the signal handler, we * need to store information about it in global variables. This is * safe, because the main application should be suspended at this - * time. If the callback ever called ResumeAllProcessThreads(), then + * time. If the callback ever called TCMalloc_ResumeAllProcessThreads(), then * we are running a higher risk, though. So, try to avoid calling - * abort() after calling ResumeAllProcessThreads. + * abort() after calling TCMalloc_ResumeAllProcessThreads. */ static volatile int *sig_pids, sig_num_threads, sig_proc, sig_marker; @@ -215,7 +215,7 @@ static void SignalHandler(int signum, siginfo_t *si, void *data) { sys_ptrace(PTRACE_KILL, sig_pids[sig_num_threads], 0, 0); } } else if (sig_num_threads > 0) { - ResumeAllProcessThreads(sig_num_threads, (int *)sig_pids); + TCMalloc_ResumeAllProcessThreads(sig_num_threads, (int *)sig_pids); } } sig_pids = NULL; @@ -497,7 +497,7 @@ static void ListerThread(struct ListerParams *args) { * error to the caller. */ if (!found_parent) { - ResumeAllProcessThreads(num_threads, pids); + TCMalloc_ResumeAllProcessThreads(num_threads, pids); sys__exit(3); } @@ -509,7 +509,7 @@ static void ListerThread(struct ListerParams *args) { args->err = errno; /* Callback should have resumed threads, but better safe than sorry */ - if (ResumeAllProcessThreads(num_threads, pids)) { + if (TCMalloc_ResumeAllProcessThreads(num_threads, pids)) { /* Callback forgot to resume at least one thread, report error */ args->err = EINVAL; args->result = -1; @@ -519,7 +519,7 @@ static void ListerThread(struct ListerParams *args) { } detach_threads: /* Resume all threads prior to retrying the operation */ - ResumeAllProcessThreads(num_threads, pids); + TCMalloc_ResumeAllProcessThreads(num_threads, pids); sig_pids = NULL; num_threads = 0; sig_num_threads = num_threads; @@ -537,19 +537,19 @@ static void ListerThread(struct ListerParams *args) { * address space, the filesystem, and the filehandles with the caller. Most * notably, it does not share the same pid and ppid; and if it terminates, * the rest of the application is still there. 'callback' is supposed to do - * or arrange for ResumeAllProcessThreads. This happens automatically, if + * or arrange for TCMalloc_ResumeAllProcessThreads. This happens automatically, if * the thread raises a synchronous signal (e.g. SIGSEGV); asynchronous * signals are blocked. If the 'callback' decides to unblock them, it must * ensure that they cannot terminate the application, or that - * ResumeAllProcessThreads will get called. + * TCMalloc_ResumeAllProcessThreads will get called. * It is an error for the 'callback' to make any library calls that could * acquire locks. Most notably, this means that most system calls have to * avoid going through libc. Also, this means that it is not legal to call * exit() or abort(). * We return -1 on error and the return value of 'callback' on success. */ -int ListAllProcessThreads(void *parameter, - ListAllProcessThreadsCallBack callback, ...) { +int TCMalloc_ListAllProcessThreads(void *parameter, + ListAllProcessThreadsCallBack callback, ...) { char altstack_mem[ALT_STACKSIZE]; struct ListerParams args; pid_t clone_pid; @@ -689,11 +689,11 @@ failed: } /* This function resumes the list of all linux threads that - * ListAllProcessThreads pauses before giving to its callback. + * TCMalloc_ListAllProcessThreads pauses before giving to its callback. * The function returns non-zero if at least one thread was * suspended and has now been resumed. */ -int ResumeAllProcessThreads(int num_threads, pid_t *thread_pids) { +int TCMalloc_ResumeAllProcessThreads(int num_threads, pid_t *thread_pids) { int detached_at_least_one = 0; while (num_threads-- > 0) { detached_at_least_one |= sys_ptrace_detach(thread_pids[num_threads]) >= 0; diff --git a/src/base/thread_lister.c b/src/base/thread_lister.c index bc180db..ca1b2de 100644 --- a/src/base/thread_lister.c +++ b/src/base/thread_lister.c @@ -48,8 +48,8 @@ * or if the multi-threading code has not been ported, yet. */ -int ListAllProcessThreads(void *parameter, - ListAllProcessThreadsCallBack callback, ...) { +int TCMalloc_ListAllProcessThreads(void *parameter, + ListAllProcessThreadsCallBack callback, ...) { int rc; va_list ap; pid_t pid; @@ -70,7 +70,7 @@ int ListAllProcessThreads(void *parameter, return rc; } -int ResumeAllProcessThreads(int num_threads, pid_t *thread_pids) { +int TCMalloc_ResumeAllProcessThreads(int num_threads, pid_t *thread_pids) { return 1; } diff --git a/src/base/thread_lister.h b/src/base/thread_lister.h index f5e60e2..6e70b89 100644 --- a/src/base/thread_lister.h +++ b/src/base/thread_lister.h @@ -55,26 +55,26 @@ typedef int (*ListAllProcessThreadsCallBack)(void *parameter, * address space, the filesystem, and the filehandles with the caller. Most * notably, it does not share the same pid and ppid; and if it terminates, * the rest of the application is still there. 'callback' is supposed to do - * or arrange for ResumeAllProcessThreads. This happens automatically, if + * or arrange for TCMalloc_ResumeAllProcessThreads. This happens automatically, if * the thread raises a synchronous signal (e.g. SIGSEGV); asynchronous * signals are blocked. If the 'callback' decides to unblock them, it must * ensure that they cannot terminate the application, or that - * ResumeAllProcessThreads will get called. + * TCMalloc_ResumeAllProcessThreads will get called. * It is an error for the 'callback' to make any library calls that could * acquire locks. Most notably, this means that most system calls have to * avoid going through libc. Also, this means that it is not legal to call * exit() or abort(). * We return -1 on error and the return value of 'callback' on success. */ -int ListAllProcessThreads(void *parameter, - ListAllProcessThreadsCallBack callback, ...); +int TCMalloc_ListAllProcessThreads(void *parameter, + ListAllProcessThreadsCallBack callback, ...); /* This function resumes the list of all linux threads that - * ListAllProcessThreads pauses before giving to its callback. - * The function returns non-zero if at least one thread was + * TCMalloc_ListAllProcessThreads pauses before giving to its + * callback. The function returns non-zero if at least one thread was * suspended and has now been resumed. */ -int ResumeAllProcessThreads(int num_threads, pid_t *thread_pids); +int TCMalloc_ResumeAllProcessThreads(int num_threads, pid_t *thread_pids); #ifdef __cplusplus } diff --git a/src/gperftools/heap-checker.h b/src/gperftools/heap-checker.h index dfa99a5..6c1187f 100644 --- a/src/gperftools/heap-checker.h +++ b/src/gperftools/heap-checker.h @@ -257,15 +257,15 @@ class PERFTOOLS_DLL_DECL HeapLeakChecker { // Helper for DoNoLeaks to ignore all objects reachable from all live data static void IgnoreAllLiveObjectsLocked(const void* self_stack_top); - // Callback we pass to ListAllProcessThreads (see thread_lister.h) + // Callback we pass to TCMalloc_ListAllProcessThreads (see thread_lister.h) // that is invoked when all threads of our process are found and stopped. // The call back does the things needed to ignore live data reachable from // thread stacks and registers for all our threads // as well as do other global-live-data ignoring // (via IgnoreNonThreadLiveObjectsLocked) // during the quiet state of all threads being stopped. - // For the argument meaning see the comment by ListAllProcessThreads. - // Here we only use num_threads and thread_pids, that ListAllProcessThreads + // For the argument meaning see the comment by TCMalloc_ListAllProcessThreads. + // Here we only use num_threads and thread_pids, that TCMalloc_ListAllProcessThreads // fills for us with the number and pids of all the threads of our process // it found and attached to. static int IgnoreLiveThreadsLocked(void* parameter, diff --git a/src/heap-checker.cc b/src/heap-checker.cc index 5a6a3de..9c82dea 100755 --- a/src/heap-checker.cc +++ b/src/heap-checker.cc @@ -286,7 +286,7 @@ static const int heap_checker_info_level = 0; // Wrapper of LowLevelAlloc for STL_Allocator and direct use. // We always access this class under held heap_checker_lock, // this allows us to in particular protect the period when threads are stopped -// at random spots with ListAllProcessThreads by heap_checker_lock, +// at random spots with TCMalloc_ListAllProcessThreads by heap_checker_lock, // w/o worrying about the lock in LowLevelAlloc::Arena. // We rely on the fact that we use an own arena with an own lock here. class HeapLeakChecker::Allocator { @@ -1044,7 +1044,7 @@ static enum { THREAD_REGS thread_regs; #define sys_ptrace(r, p, a, d) syscall(SYS_ptrace, (r), (p), (a), (d)) // We use sys_ptrace to avoid thread locking - // because this is called from ListAllProcessThreads + // because this is called from TCMalloc_ListAllProcessThreads // when all but this thread are suspended. if (sys_ptrace(PTRACE_GETREGS, thread_pids[i], NULL, &thread_regs) == 0) { // Need to use SP to get all the data from the very last stack frame: @@ -1080,7 +1080,7 @@ static enum { // Do all other liveness walking while all threads are stopped: IgnoreNonThreadLiveObjectsLocked(); // Can now resume the threads: - ResumeAllProcessThreads(num_threads, thread_pids); + TCMalloc_ResumeAllProcessThreads(num_threads, thread_pids); thread_listing_status = CALLBACK_COMPLETED; return failures; } @@ -1238,7 +1238,7 @@ void HeapLeakChecker::IgnoreNonThreadLiveObjectsLocked() { } } -// Callback for ListAllProcessThreads in IgnoreAllLiveObjectsLocked below +// Callback for TCMalloc_ListAllProcessThreads in IgnoreAllLiveObjectsLocked below // to test/verify that we have just the one main thread, in which case // we can do everything in that main thread, // so that CPU profiler can collect all its samples. @@ -1249,7 +1249,7 @@ static int IsOneThread(void* parameter, int num_threads, RAW_LOG(WARNING, "Have threads: Won't CPU-profile the bulk of leak " "checking work happening in IgnoreLiveThreadsLocked!"); } - ResumeAllProcessThreads(num_threads, thread_pids); + TCMalloc_ResumeAllProcessThreads(num_threads, thread_pids); return num_threads; } @@ -1291,16 +1291,17 @@ void HeapLeakChecker::IgnoreAllLiveObjectsLocked(const void* self_stack_top) { if (FLAGS_heap_check_ignore_thread_live) { // In case we are doing CPU profiling we'd like to do all the work // in the main thread, not in the special thread created by - // ListAllProcessThreads, so that CPU profiler can collect all its samples. - // The machinery of ListAllProcessThreads conflicts with the CPU profiler - // by also relying on signals and ::sigaction. - // We can do this (run everything in the main thread) safely - // only if there's just the main thread itself in our process. - // This variable reflects these two conditions: + // TCMalloc_ListAllProcessThreads, so that CPU profiler can + // collect all its samples. The machinery of + // TCMalloc_ListAllProcessThreads conflicts with the CPU profiler + // by also relying on signals and ::sigaction. We can do this + // (run everything in the main thread) safely only if there's just + // the main thread itself in our process. This variable reflects + // these two conditions: bool want_and_can_run_in_main_thread = ProfilingIsEnabledForAllThreads() && - ListAllProcessThreads(NULL, IsOneThread) == 1; - // When the normal path of ListAllProcessThreads below is taken, + TCMalloc_ListAllProcessThreads(NULL, IsOneThread) == 1; + // When the normal path of TCMalloc_ListAllProcessThreads below is taken, // we fully suspend the threads right here before any liveness checking // and keep them suspended for the whole time of liveness checking // inside of the IgnoreLiveThreadsLocked callback. @@ -1309,7 +1310,7 @@ void HeapLeakChecker::IgnoreAllLiveObjectsLocked(const void* self_stack_top) { // graph while we walk it). int r = want_and_can_run_in_main_thread ? IgnoreLiveThreadsLocked(NULL, 1, &self_thread_pid, dummy_ap) - : ListAllProcessThreads(NULL, IgnoreLiveThreadsLocked); + : TCMalloc_ListAllProcessThreads(NULL, IgnoreLiveThreadsLocked); need_to_ignore_non_thread_objects = r < 0; if (r < 0) { RAW_LOG(WARNING, "Thread finding failed with %d errno=%d", r, errno); diff --git a/src/memory_region_map.h b/src/memory_region_map.h index 03b660f..ec388e1 100644 --- a/src/memory_region_map.h +++ b/src/memory_region_map.h @@ -301,7 +301,7 @@ class MemoryRegionMap { // To be accessed *only* when Lock() is held. // Hence we protect the non-recursive lock used inside of arena_ // with our recursive Lock(). This lets a user prevent deadlocks - // when threads are stopped by ListAllProcessThreads at random spots + // when threads are stopped by TCMalloc_ListAllProcessThreads at random spots // simply by acquiring our recursive Lock() before that. static RegionSet* regions_; |