-
Notifications
You must be signed in to change notification settings - Fork 5.4k
osx: thread id and signal stack support #1373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3beb0c5
1dd74dd
50efa9f
6b2e1a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| #include "common/common/thread.h" | ||
|
|
||
| #ifdef __linux__ | ||
| #include <sys/syscall.h> | ||
| #elif defined(__APPLE__) | ||
| #include <pthread.h> | ||
| #endif | ||
|
|
||
| #include <functional> | ||
|
|
||
|
|
@@ -21,7 +25,17 @@ Thread::Thread(std::function<void()> thread_routine) : thread_routine_(thread_ro | |
| UNREFERENCED_PARAMETER(rc); | ||
| } | ||
|
|
||
| int32_t Thread::currentThreadId() { return syscall(SYS_gettid); } | ||
| int32_t Thread::currentThreadId() { | ||
| #ifdef __linux__ | ||
| return syscall(SYS_gettid); | ||
| #elif defined(__APPLE__) | ||
| uint64_t tid; | ||
| pthread_threadid_np(NULL, &tid); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just use this on all platforms now and lose ifdef? feel free to return uint64_t and lose the static cast if you want.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, ok. nevermind me. :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That function doesn't exist on Linux. |
||
| return static_cast<int32_t>(tid); | ||
| #else | ||
| #error "Enable and test pthread id retrieval code for you arch in thread.cc" | ||
| #endif | ||
| } | ||
|
|
||
| void Thread::join() { | ||
| int rc = pthread_join(thread_id_, nullptr); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: could you either add
#elsecase or use Linux as the fallback? i.e.or
otherwise we're going to end with code that doesn't have return value on other OSes.
Either one is fine with me, assuming @mattklein123 doesn't have any objections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I thought about this. Agree this would be a bit nicer. Either way the compile will fail so not sure it matters that much. No preference from me about either of these or leaving what we have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an #error directive.