-
Notifications
You must be signed in to change notification settings - Fork 1.2k
[NSThread] Implement name property #807
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
Conversation
On Darwin, this calls a pthread non-posix API (pthread_setname_np) to give the name to the pthread library for debugging purposes. Is there an equivalent we can use on other platforms? |
That was my initial plan for the implementation, but seeing Darwins Linux equivalents are:
|
On Darwin, the current thread is the implicit argument. We actually only set the name in pthread if the current thread is the same as the |
9f44ffe
to
6fc9e4a
Compare
@parkera Implemented your suggestion. |
cde3288
to
1db8608
Compare
Cool! Is it possible to get a test case along with this? |
@parkera somehow [EDIT] Got it working by wrapping the function in CoreFoundation |
592b1e9
to
d688c49
Compare
I believe those are darwin-only extensions. Is there anything equivalent in the pthread library on used on ubuntu? |
@parkera I got it working on Ubuntu. The problem was, that the functions weren't found in Swift. Calling them from CoreFoundation fixed the problem. |
@@ -1310,6 +1310,14 @@ _CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (* | |||
return thread; | |||
} | |||
|
|||
void _CFThreadSetName(const char *_Nullable name) { |
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.
Let's decorate this with CF_SWIFT_EXPORT
@@ -298,6 +298,8 @@ typedef pthread_t _CFThreadRef; | |||
|
|||
CF_EXPORT _CFThreadRef _CFThreadCreate(const _CFThreadAttributes attrs, void *_Nullable (* _Nonnull startfn)(void *_Nullable), void *restrict _Nullable context); | |||
|
|||
CF_EXPORT void _CFThreadSetName(const char *_Nullable name); |
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.
Here too
d688c49
to
7a10e58
Compare
Done |
Should I add a test to the test case, to see if the pthread name is set correctly? |
Sure, that'd be useful. |
Should I use
|
Generally we like to use the CF types for CF API. So |
7a10e58
to
f2c65de
Compare
Sorry, I couldn't quite get |
fb0f248
to
60aa182
Compare
@parkera could you test? |
Sure, sorry about that. |
@swift-ci please test |
60aa182
to
3b83376
Compare
@parkera I did some small improvements and cleanups to the test code. Could you review and test, please? |
@swift-ci please test and merge |
No description provided.