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
[Concurrency] Add a unique Task ID to AsyncTask #37325
Conversation
@swift-ci test |
Build failed |
Obviously this changes the size of Job on 32 bits platforms:
@rjmccall That's expected, any preference how to relax the static assert? |
Build failed |
Linux doesn't support |
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.
Generally LGTM, just some slight nit-picking.
include/swift/ABI/Task.h
Outdated
@@ -485,13 +490,24 @@ class AsyncTask : public Job { | |||
return reinterpret_cast<AsyncTask *&>( | |||
SchedulerPrivate[NextWaitingTaskIndex]); | |||
} | |||
|
|||
/// Get the next non-zero Task ID. | |||
uint32_t GetNextTaskId() { |
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.
Style nit: we're consistent about using camelCase
for method names in Swift.
uint32_t GetNextTaskId() { | ||
static std::atomic_uint32_t Id; | ||
uint32_t Next = Id.fetch_add(1, std::memory_order_relaxed); | ||
if (Next == 0) Next = Id.fetch_add(1, std::memory_order_relaxed); |
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.
Maybe initialize it to 1 just so we don't trip this special case the first time? Minor, but still.
@swift-ci test |
Build failed |
@swift-ci test |
@swift-ci Test Windows Platform |
Build failed |
Build failed |
This breaks 3 watch simulator tests:
The tests seem to crash. Any idea what could be wrong @rjmccall ? |
@swift-ci Test Linux Platform |
@swift-ci Test Windows Platform |
@swift-ci please test |
@swift-ci please test |
This commit changes JobFlags storage to be 32bits, but leaves the runtime API expressed in terms of size_t. This allows us to pack an Id in the 32bits we freed up. The offset of this Id in the AsyncTask is an ABI constant. This way introspection tools can extract the currently running task identifier without any need for special APIs.
@swift-ci test |
Build failed |
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.
LGTM
@swift-ci Test Linux Platform |
Build failed |
@swift-ci Test macOS Platform |
The offset of this Id in the AsyncTask is an ABI constant. This way
introspection tools can extract the currently running task identifier
without any need for special APIs.
This PR first changes JobFlags to a 32bits entity in order to be able
to pack the ID in the freed-up space.