Skip to content
Snippets Groups Projects
Commit 9cda3df8 authored by Sergey Matveev's avatar Sergey Matveev
Browse files

[sanitizer] Move FindThreadByOSIdLocked from lsan to sanitizer_common.

llvm-svn: 182728
parent 9c2bcf8c
No related branches found
No related tags found
No related merge requests found
...@@ -106,18 +106,6 @@ ThreadContext *CurrentThreadContext() { ...@@ -106,18 +106,6 @@ ThreadContext *CurrentThreadContext() {
return (ThreadContext *)thread_registry->GetThreadLocked(GetCurrentThread()); 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) { static bool FindThreadByUid(ThreadContextBase *tctx, void *arg) {
uptr uid = (uptr)arg; uptr uid = (uptr)arg;
if (tctx->user_id == uid && tctx->status != ThreadStatusInvalid) { if (tctx->user_id == uid && tctx->status != ThreadStatusInvalid) {
...@@ -140,9 +128,9 @@ void ThreadJoin(u32 tid) { ...@@ -140,9 +128,9 @@ void ThreadJoin(u32 tid) {
bool GetThreadRangesLocked(uptr os_id, uptr *stack_begin, uptr *stack_end, bool GetThreadRangesLocked(uptr os_id, uptr *stack_begin, uptr *stack_end,
uptr *tls_begin, uptr *tls_end, uptr *tls_begin, uptr *tls_end,
uptr *cache_begin, uptr *cache_end) { uptr *cache_begin, uptr *cache_end) {
ThreadContext *context = FindThreadByOsIDLocked(os_id); ThreadContext *context = static_cast<ThreadContext *>(
if (!context) thread_registry->FindThreadContextByOsIDLocked(os_id));
return false; if (!context) return false;
*stack_begin = context->stack_begin(); *stack_begin = context->stack_begin();
*stack_end = context->stack_end(); *stack_end = context->stack_end();
*tls_begin = context->tls_begin(); *tls_begin = context->tls_begin();
......
...@@ -180,6 +180,17 @@ ThreadRegistry::FindThreadContextLocked(FindThreadCallback cb, void *arg) { ...@@ -180,6 +180,17 @@ ThreadRegistry::FindThreadContextLocked(FindThreadCallback cb, void *arg) {
return 0; 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) { void ThreadRegistry::SetThreadName(u32 tid, const char *name) {
BlockingMutexLock l(&mtx_); BlockingMutexLock l(&mtx_);
CHECK_LT(tid, n_contexts_); CHECK_LT(tid, n_contexts_);
......
...@@ -102,10 +102,11 @@ class ThreadRegistry { ...@@ -102,10 +102,11 @@ class ThreadRegistry {
// Finds a thread using the provided callback. Returns kUnknownTid if no // Finds a thread using the provided callback. Returns kUnknownTid if no
// thread is found. // thread is found.
u32 FindThread(FindThreadCallback cb, void *arg); 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. // is found.
ThreadContextBase *FindThreadContextLocked(FindThreadCallback cb, ThreadContextBase *FindThreadContextLocked(FindThreadCallback cb,
void *arg); void *arg);
ThreadContextBase *FindThreadContextByOsIDLocked(uptr os_id);
void SetThreadName(u32 tid, const char *name); void SetThreadName(u32 tid, const char *name);
void DetachThread(u32 tid); void DetachThread(u32 tid);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment