This replaces a number of `#include`-s like this:
```
#include "../../../stdlib/public/SwiftShims/Visibility.h"
```
with this:
```
#include "swift/shims/Visibility.h"
```
This is needed to allow SwiftCompilerSources to use C++ headers which include SwiftShims headers. Currently trying to do that results in errors:
```
swift/swift/include/swift/Demangling/../../../stdlib/public/SwiftShims/module.modulemap:1:8: error: redefinition of module 'SwiftShims'
module SwiftShims {
^
Builds.noindex/swift/swift/bootstrapping0/lib/swift/shims/module.modulemap:1:8: note: previously defined here
module SwiftShims {
^
```
This happens because the headers in both the source dir and the build dir refer to SwiftShims headers by relative path, and both the source root and the build root contain SwiftShims headers (which are equivalent, but since they are located in different dirs, Clang treats them as different modules).
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
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
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is too much of a blunt instrument here.
It covers both the Concurrency runtime and the rest of the runtime, but we'd
like to be able to have e.g. a single-threaded Concurrency runtime while
the rest of the runtime is still thread safe (for instance).
So: rename it to SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and make it just
control the Concurrency runtime, then add a SWIFT_STDLIB_THREADING_PACKAGE
setting at the CMake/build-script level, which defines
SWIFT_STDLIB_THREADING_xxx where xxx depends on the chosen threading package.
This is especially useful on systems where there may be a choice of threading
package that you could use.
rdar://90776105
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
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
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is too much of a blunt instrument here.
It covers both the Concurrency runtime and the rest of the runtime, but we'd
like to be able to have e.g. a single-threaded Concurrency runtime while
the rest of the runtime is still thread safe (for instance).
So: rename it to SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and make it just
control the Concurrency runtime, then add a SWIFT_STDLIB_THREADING_PACKAGE
setting at the CMake/build-script level, which defines
SWIFT_STDLIB_THREADING_xxx where xxx depends on the chosen threading package.
This is especially useful on systems where there may be a choice of threading
package that you could use.
rdar://90776105
This removes the explicit tree structure reference in the stubs to
locate the shims. Instead, it expects that the `SwiftShims` directory
will be added to the header search path.
Use the wrapper for the CC adjustment as on Windows x86, the destructor
needs to be `__stdcall`. This would fail otherwise with the following:
```
D:\a\1\s\swift\stdlib\public\stubs\ThreadLocalStorage.cpp(86,18): error: no matching function for call to '_stdlib_thread_key_create'
int result = SWIFT_THREAD_KEY_CREATE(&key, [](void *pointer) {
^~~~~~~~~~~~~~~~~~~~~~~
D:\a\1\s\swift\stdlib\public\stubs/../runtime/ThreadLocalStorage.h(96,35): note: expanded from macro 'SWIFT_THREAD_KEY_CREATE'
^~~~~~~~~~~~~~~~~~~~~~~~~
D:\a\1\s\swift\include\swift/Basic/Lazy.h(42,27): note: expanded from macro 'SWIFT_ONCE_F'
::std::call_once(TOKEN, FUNC, CONTEXT)
^~~~
D:\a\1\s\swift\stdlib\public\stubs\ThreadLocalStorage.cpp(43,1): note: candidate function not viable: no known conversion from '(lambda at D:\a\1\s\swift\stdlib\public\stubs\ThreadLocalStorage.cpp:85:3)' to '__swift_thread_key_destructor _Nullable' (aka 'void (*)(void *) __attribute__((stdcall))') for 2nd argument
_stdlib_thread_key_create(__swift_thread_key_t * _Nonnull key,
^
```
The mapping of the return value of the `FlsAlloc` was flipped resulting
in the failure of the TLS key creation. The test suite would fail to
generate the TLS key resulting in failures.
Due to the build ordering, I didn't notice this earlier. The inclusion
of the header would define the guard, preventing the needed definitions.
Unconditionally define the functions to ensure that they are available.
Fix syntactic issues in the swift runtime build from the recent TLS changes.
Move the helper definitions into the TLS stubs rather than emitting them
everywhere. This allows the runtime to build again on Windows.