[PATCH] [sanitizer] Move FindThreadByOSIdLocked from lsan to sanitizer_common.
Sergey Matveev
earthdok at google.com
Fri May 24 11:22:40 PDT 2013
Hi kcc, glider, samsonov,
Factored out a function that will also be used in asan.
http://llvm-reviews.chandlerc.com/D861
Files:
lib/lsan/lsan_thread.cc
lib/sanitizer_common/sanitizer_thread_registry.cc
lib/sanitizer_common/sanitizer_thread_registry.h
Index: lib/lsan/lsan_thread.cc
===================================================================
--- lib/lsan/lsan_thread.cc
+++ lib/lsan/lsan_thread.cc
@@ -106,18 +106,6 @@
return (ThreadContext *)thread_registry->GetThreadLocked(GetCurrentThread());
}
-bool FindThreadByOsIdCallback(ThreadContextBase *tctx, void *arg) {
- return (tctx->os_id == (uptr)arg && tctx->status != ThreadStatusInvalid &&
- tctx->status != ThreadStatusDead);
-}
-
-ThreadContext *FindThreadByOsIDLocked(uptr os_id) {
- ThreadContextBase *tctx =
- thread_registry->FindThreadContextLocked(FindThreadByOsIdCallback,
- (void*)os_id);
- return static_cast<ThreadContext *>(tctx);
-}
-
static bool FindThreadByUid(ThreadContextBase *tctx, void *arg) {
uptr uid = (uptr)arg;
if (tctx->user_id == uid && tctx->status != ThreadStatusInvalid) {
@@ -140,9 +128,9 @@
bool GetThreadRangesLocked(uptr os_id, uptr *stack_begin, uptr *stack_end,
uptr *tls_begin, uptr *tls_end,
uptr *cache_begin, uptr *cache_end) {
- ThreadContext *context = FindThreadByOsIDLocked(os_id);
- if (!context)
- return false;
+ ThreadContext *context = static_cast<ThreadContext *>(
+ thread_registry->FindThreadContextByOsIDLocked(os_id));
+ if (!context) return false;
*stack_begin = context->stack_begin();
*stack_end = context->stack_end();
*tls_begin = context->tls_begin();
Index: lib/sanitizer_common/sanitizer_thread_registry.cc
===================================================================
--- lib/sanitizer_common/sanitizer_thread_registry.cc
+++ lib/sanitizer_common/sanitizer_thread_registry.cc
@@ -180,6 +180,17 @@
return 0;
}
+static bool FindThreadContextByOsIdCallback(ThreadContextBase *tctx,
+ void *arg) {
+ return (tctx->os_id == (uptr)arg && tctx->status != ThreadStatusInvalid &&
+ tctx->status != ThreadStatusDead);
+}
+
+ThreadContextBase *ThreadRegistry::FindThreadContextByOsIDLocked(uptr os_id) {
+ return FindThreadContextLocked(FindThreadContextByOsIdCallback,
+ (void *)os_id);
+}
+
void ThreadRegistry::SetThreadName(u32 tid, const char *name) {
BlockingMutexLock l(&mtx_);
CHECK_LT(tid, n_contexts_);
Index: lib/sanitizer_common/sanitizer_thread_registry.h
===================================================================
--- lib/sanitizer_common/sanitizer_thread_registry.h
+++ lib/sanitizer_common/sanitizer_thread_registry.h
@@ -102,10 +102,11 @@
// Finds a thread using the provided callback. Returns kUnknownTid if no
// thread is found.
u32 FindThread(FindThreadCallback cb, void *arg);
- // Should be guarded by ThreadRegistryLock. Returns 0 if no thread
+ // Should be guarded by ThreadRegistryLock. Return 0 if no thread
// is found.
ThreadContextBase *FindThreadContextLocked(FindThreadCallback cb,
void *arg);
+ ThreadContextBase *FindThreadContextByOsIDLocked(uptr os_id);
void SetThreadName(u32 tid, const char *name);
void DetachThread(u32 tid);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D861.1.patch
Type: text/x-patch
Size: 3159 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130524/1554da93/attachment.bin>
More information about the llvm-commits
mailing list