Commit Graph

45 Commits

Author SHA1 Message Date
Mike Ash
29245e4ef2 [Concurrency] Fix MarkerItem::create to use malloc when there's no task.
Item::destroy will call free when there's no task, so the allocation needs to match, lest we free something that wasn't malloced and crash.

rdar://162589711
2025-10-29 18:17:33 -04:00
Allan Shortlidge
4799f1e295 Concurrency: Suppress some warnings. 2025-02-01 13:52:43 -08:00
Mykola Pokhylets
67ab0d7404 Implement disabling task-local values in isolated deinit
As requested by the LSG during the proposal review.
See https://forums.swift.org/t/accepted-with-modifications-se-0371-isolated-synchronous-deinit/74042
2024-10-28 16:15:21 +01:00
Mykola Pokhylets
2acf5b6b6b Refactoring of the TaskLocal::Item
Replace NextLinkType with Item::Kind with more clear definition.
Use llvm::PointerIntPair<>.
Use hierarchy of classes instead of optional fields inside Item.
Combined Storage::copyToOnlyOnlyFromCurrentGroup() into Storage::initializeLinkParent().
Also create parent task marker when copying items created inside withTaskGroup().
Removed Storage::peekHeadLinkType().
2024-10-27 12:32:21 +01:00
Konrad `ktoso` Malawski
bd554ba524 Merge pull request #76883 from nickolas-pohilets/mpokhylets/move-task-locals-header 2024-10-10 19:38:35 +09:00
Alastair Houghton
54a495527e [Concurrency] Remove C++ runtime references from embedded Concurrency.
In embedded mode, we mustn't have references to the C++ library, because
some embedded platforms don't include the C++ library.

Additionally, it's good to avoid use of global operator new and operator
delete, because they can be globally overridden and this has bitten us
in the past.

rdar://137286187
2024-10-07 10:30:27 +01:00
Mykola Pokhylets
cb4c880af1 Move TaskLocal.h out of ABI folder, because it describes implementation details 2024-10-06 14:37:11 +02:00
Michael Gottesman
cb8e8b505a Fix syntax highlighting by changing how we include COMPATIBILITY_OVERRIDE_INCLUDE_PATH.
The way that we include COMPATIBILITY_OVERRIDE_INCLUDE_PATH freaks out the
syntax highlighting of editors like emacs. It causes the whole file to be
highlighted like it is part of the include string.

To work around this, this patch creates a separate file called
CompatibilityOverrideIncludePath.h that just includes
COMPATIBILITY_OVERRIDE_INCLUDE_PATH. So its syntax highlighting is borked, but
at least in the actual files that contain real code, the syntax highlighting is
restored.
2024-10-01 16:17:16 -07:00
Konrad `ktoso` Malawski
14b8546392 [Concurrency] Don't add new task locals copy runtime func 2024-06-03 13:55:02 +09:00
Konrad `ktoso` Malawski
0c44645832 [Concurrency] Implement defensive copying in task groups, rather than crashing (#73978) 2024-05-31 11:27:03 -07:00
Allan Shortlidge
79d0ecafaa NFC: Ignore deprecation of asl_log in the runtime and demangling library.
ASL is deprecated in macOS 10.12. It may be time to transition to os_log now
that deployment targets have been raised to 10.12, but until that project
starts these warnings are just pollution.

Filed rdar://121066531 to track adoption of `os_log()` if appropriate.
2024-01-16 13:27:55 -08:00
Konrad `ktoso` Malawski
eaafe3f79e [TaskGroup] Stop using group.spawn in warning messages 2023-08-08 20:38:57 +09:00
Alastair Houghton
48255788dd [Concurrency] Remove redundant include.
Clean up an unnecesary include.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
eb4c81d60e [Threading] Don't use TLS keys as template arguments.
There's no guarantee that e.g. pthread_key_t is an integral type.  It could
be some kind of struct, or some other thing that isn't valid as a template
argument.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
0e9318cec5 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
ef2e40a937 [Concurrency][Windows] Remove unnecessary includes.
TaskLocal.cpp doesn't need <handleapi.h> or <processthreadsapi.h>, both of
which want <windows.h>, which isn't included any more.

rdar://90776105
2022-06-07 07:39:52 +01:00
Alastair Houghton
f5bdb858e0 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alex Hoppen
4aa2bbbf06 Revert "Merge pull request #42447 from al45tair/eng/PR-90776105"
This reverts commit 8bcb71140f, reversing
changes made to c4dd271d36.
2022-06-02 18:03:23 +02:00
Alastair Houghton
a987cb9eac [Concurrency] Remove redundant include.
Clean up an unnecesary include.

rdar://90776105
2022-05-24 14:57:42 +01:00
Alastair Houghton
69f0b03a73 [Threading] Don't use TLS keys as template arguments.
There's no guarantee that e.g. pthread_key_t is an integral type.  It could
be some kind of struct, or some other thing that isn't valid as a template
argument.

rdar://90776105
2022-05-24 14:57:42 +01:00
Alastair Houghton
b5bd267ff1 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-05-24 14:57:41 +01:00
Alastair Houghton
da42d728d7 [Concurrency][Windows] Remove unnecessary includes.
TaskLocal.cpp doesn't need <handleapi.h> or <processthreadsapi.h>, both of
which want <windows.h>, which isn't included any more.

rdar://90776105
2022-05-24 14:57:41 +01:00
Alastair Houghton
63a09007a1 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-05-24 14:57:39 +01:00
Saleem Abdulrasool
a8b0ee24dc runtime: blanket application of namespacing and inclusion of new
Apply a blanket pass of including `new` for the placement new allocation
and namespacing the call to the global placement new allocator.  This
should repair the Android ARMv7 builds.
2022-04-14 14:21:12 -07:00
Kuba (Brecka) Mracek
ffb1cacac3 [Concurrency] Avoid using asl_log when not available (#41277) 2022-02-09 09:40:53 -08:00
Mike Ash
2d6a6927e9 Merge pull request #38162 from mikeash/concurrency-constant-pthread-keys
[Concurrency] Use pthread_specific for thread-local storage on Darwin.
2021-07-02 13:22:15 -04:00
Konrad `ktoso` Malawski
bb16d734f3 [Concurrency] add TaskLocal::Item:iisParentPointer for cleaner API 2021-07-02 11:53:50 +09:00
Konrad `ktoso` Malawski
cd0708b315 [Concurrency] task local must not copy null values 2021-07-02 11:36:20 +09:00
Mike Ash
190d3fd22e [Concurrency] Use pthread_specific for thread-local storage on Darwin.
The pthread_specific APIs are better than C++ thread_local storage on Darwin since we can use Swift's reserved pthread keys there.

rdar://79504652
2021-06-29 16:56:59 -04:00
Konrad `ktoso` Malawski
0cf6d9a18a [TaskLocal] copyTo must initializeWithCopy the task local value (#37988) 2021-06-23 15:45:37 +09:00
John McCall
db3967f41d Future-proof the layout of AsyncTask. 2021-05-20 15:30:48 -04:00
Konrad `ktoso` Malawski
6cbb792f92 [TaskLocals] Propagate task-locals through async{} 2021-05-11 11:06:17 +09:00
Konrad `ktoso` Malawski
82e91b7785 [TaskLocals] Enable sync functions to bind task-locals; Keep Storage in TLS 2021-05-11 11:06:16 +09:00
Konrad `ktoso` Malawski
5ff76c6a0d [TaskLocals] Windows: fix missing io.h
TaskLocals print a verbose error before crashing if API is abused within a task-group.
This printing needs `io.h` on windows.
2021-04-30 17:00:24 +09:00
Konrad `ktoso` Malawski
6f3dac190a [TaskLocals] remove TaskLocalInheritance, we'll introduce when needed 2021-04-29 15:48:22 +09:00
Konrad `ktoso` Malawski
664936cd03 [TaskLocal] crash on illegal withValue 2021-04-29 15:48:22 +09:00
Konrad `ktoso` Malawski
58ea749304 [TaskLocal] Crash on inapropriate use within task group 2021-04-29 15:48:22 +09:00
Konrad `ktoso` Malawski
3d96d05546 [TaskLocals] property wrapper keys 2021-04-29 15:48:09 +09:00
Mike Ash
6aab257c33 [Concurrency] Add compatibility overrides to Concurrency library.
Take the existing CompatibilityOverride mechanism and generalize it so it can be used in both the runtime and Concurrency libraries. The mechanism is preprocessor-heavy, so this requires some tricks. Use the SWIFT_TARGET_LIBRARY_NAME define to distinguish the libraries, and use a different .def file and mach-o section name accordingly.

We want the global/main executor functions to be a little more flexible. Instead of using the override mechanism, we expose function pointers that can be set by the compatibility library, or by any other code that wants to use a custom implementation.

rdar://73726764
2021-03-22 11:09:06 -04:00
John McCall
6c879d6fd3 Change the async ABI to not pass the active task and executor.
Most of the async runtime functions have been changed to not
expect the task and executor to be passed in.  When knowing the
task and executor is necessary, there are runtime functions
available to recover them.

The biggest change I had to make to a runtime function signature
was to swift_task_switch, which has been altered to expect to be
passed the context and resumption function instead of requiring
the caller to park the task.  This has the pleasant consequence
of allowing the implementation to very quickly turn around when
it recognizes that the current executor is satisfactory.  It does
mean that on arm64e we have to sign the continuation function
pointer as an argument and then potentially resign it when
assigning into the task's resume slot.

rdar://70546948
2021-03-16 22:52:54 -04:00
Konrad `ktoso` Malawski
fcb1c01a36 [TaskLocal] Use the task-local stack discipline allocator 2021-03-02 11:14:41 +09:00
Konrad `ktoso` Malawski
d7169edc21 [TaskLocals] Cleanly separate locals impl from Task, no need for fragment 2021-03-02 00:54:47 +09:00
Konrad `ktoso` Malawski
d2bd6abe61 [Concurrency] TaskLocals allow configuring inheritance: never 2021-02-13 20:09:11 +09:00
Konrad `ktoso` Malawski
b811b12246 [Concurrency] TaskLocals lookup "skip" optimization 2021-02-13 10:39:22 +09:00
Konrad `ktoso` Malawski
1044723787 [Concurrency] Initial Task Local Values implementation 2021-02-13 10:39:22 +09:00