mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Properly save and restore the current task in the runtime so that tasks
can be reentrantly executed. I don't think doing this is *actually a good idea*, but corrupting the runtime is an even worse idea, and the overhead here is very low.
This commit is contained in:
@@ -115,6 +115,15 @@ public:
|
||||
T get() { return value; }
|
||||
|
||||
void set(T newValue) { value = newValue; }
|
||||
|
||||
T swap(T newValue) {
|
||||
// There's an implicit optimization here because we implicitly
|
||||
// materialize the address of the thread-local once instead of
|
||||
// separately for two calls to get and set.
|
||||
auto curValue = get();
|
||||
set(newValue);
|
||||
return curValue;
|
||||
}
|
||||
};
|
||||
#else
|
||||
// A wrapper around a TLS key that is lazily initialized using swift::once.
|
||||
@@ -168,6 +177,12 @@ public:
|
||||
memcpy(&storedValue, &newValue, sizeof(T));
|
||||
tls_set(key.getKey(), storedValue);
|
||||
}
|
||||
|
||||
T swap(T newValue) {
|
||||
auto curValue = get();
|
||||
set(newValue);
|
||||
return curValue;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user