Commit Graph

21 Commits

Author SHA1 Message Date
Egor Zhdan
84a1ffcb33 [Shims] Include SwiftShims headers without ../
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).
2022-09-14 11:14:50 +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
6d1b6dbd1c [Threading] Fix the Linux build.
A few fixes specifically for the Linux build.

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
Alastair Houghton
0cf687aa2b [Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
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
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
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
fc90280e34 [Threading] Fix the Linux build.
A few fixes specifically for the Linux build.

rdar://90776105
2022-05-24 14:57:39 +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
Alastair Houghton
dadcb04ae2 [Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
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
2022-05-24 14:57:38 +01:00
Saleem Abdulrasool
ca39bb5b10 stubs: avoid reaching up-tree, prefer inclusion options
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.
2022-01-14 09:34:56 -08: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
Kuba (Brecka) Mracek
9ead8d57fa Add a single-threaded stdlib mode, use it for the 'minimal' stdlib (#33437) 2020-08-25 06:03:14 -07:00
Saleem Abdulrasool
64ed0a4077 stdlib: silence a unused function warning (NFC)
Pre-process away the unused function on Darwin.  NFC.
2019-09-20 17:34:17 -07:00
Saleem Abdulrasool
cc9a567ec7 stdlib: use the destructor CC adjustment thunk
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,
^

```
2019-08-20 19:11:46 -07:00
Saleem Abdulrasool
40da65a43f runtime: correct _stdlib_thread_key_create
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.
2018-12-23 10:02:49 -08:00
Saleem Abdulrasool
c3d5c3d75b stdlib: fix THreadLocalStorage builds for Windows
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.
2018-09-22 09:32:33 -07:00
Saleem Abdulrasool
1b47910cd9 stdlib: repair the Windows runtime build
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.
2018-09-14 11:12:57 -07:00
Mike Ash
29ff3de4ab [Runtime][Stdlib] Use dedicated thread-local storage keys when possible.
rdar://problem/32275323 rdar://problem/44104305
2018-09-13 14:36:57 -04:00