Commit Graph

69 Commits

Author SHA1 Message Date
Yuta Saito
ead6e3dca7 [Threading] Use raw gettid syscall for older glibc compatibility
`gettid` wrapper was added in glibc 2.30, and Ubuntu 18.04 uses glibc
2.27, so use raw syscall instead of it.
2022-06-02 06:25:46 +00:00
Alastair Houghton
43cc1f97ba [Threading] Use llvm::Optional<> rather than making a zero lower bound special.
While most systems aren't going to have their stack bottom at zero,
using llvm::Optional<> here is cleaner.

rdar://90776105
2022-05-24 17:46:33 +01:00
Alastair Houghton
901ceaef13 [Threading] Add the ability to use any C++ callable in swift::once().
This allows the use of C++ lambdas and functors, in addition to plain
old functions.

rdar://90776105
2022-05-24 14:57:42 +01:00
Alastair Houghton
fc4f941185 [Threading] Move stack bounds fetching into the threading library.
Fetching the current stack bounds is done using threading functions, so
should be in the threading library.

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
2884ddbc3e [Threading] Fix some problems with the C11 threading code.
These changes are needed to get things building with a C11 threads shim
header on macOS.

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
6e875dacc9 [Threading] Remove thread_get_main().
Removing thread_get_main() means we don't need a static initializer on
Darwin, which means we can delete Darwin.cpp as well.  We can also delete
Nothreads.cpp while we're about it, because there's nothing in that file.

rdar://90776105
2022-05-24 14:57:41 +01:00
Alastair Houghton
d090bb0c3e [Threading][Windows] Try to avoid declaring _RTL_SRWLOCK
Declaring _RTL_SRWLOCK ourselves causes clashes with <windows.h>.
Rather than doing that, declare an equivalent struct, and some overloads.

rdar://90776105
2022-05-24 14:57:41 +01:00
Alastair Houghton
c034d6c3da [Concurrency][Threading] Remove use of platform thread functions.
The concurrency library can use the new threading library functions,
which avoids the problem of including <windows.h>.

rdar://90776105
2022-05-24 14:57:41 +01:00
Alastair Houghton
b718432946 [Threading][Windows] Don't include <windows.h>
We can't safely include <windows.h> because it defines a large number
of macros, some of which clash with things in the Swift source tree,
and others of which clash with things in the LLVM source tree.  Sadly
we *also* can't just include the Windows headers we need, because they
pull in some of the problematic macros.

In this instance, the best thing seems to be to grab the definitions
for the types and functions we are going to use and put them in their
own header file.  If we define them correctly, then #including
<windows.h> before or after this header won't have any adverse effects.

rdar://90776105
2022-05-24 14:57:40 +01:00
Alastair Houghton
709d06fecd [Threading][Windows] Undefine Yield and ERROR.
`windows.h` defines a couple of very unhelpfully named macros.
Undefine them after including it.

rdar://90776105
2022-05-24 14:57:40 +01:00
Alastair Houghton
4527c08f8f [Threading][Windows] More header file fixes.
rdar://90776105
2022-05-24 14:57:40 +01:00
Alastair Houghton
6f4d9cca41 [Threading][Windows] Fix another Windows niggle.
Looks like I forgot to update the Win32.h implementation.

rdar://90776105
2022-05-24 14:57:40 +01:00
Alastair Houghton
f04b6580fb [Threading][Windows] Fix missing close brace.
Apparently I missed a close brace from the end of Win32.h.

rdar://90776105
2022-05-24 14:57:40 +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
2398fe76f6 [Threading] A couple of header file fixes.
Some declarations were missing from non-Darwin sources, and the Linux
header was slightly broken.

rdar://90776105
2022-05-24 14:57:39 +01:00
Alastair Houghton
1243d155b5 [Threading] Auto-detect threading in the preprocessor.
Some things (LLDB's language plugin, for instance), include Swift headers
from outside of our build system, and may not know to define one of the
threading package defines.

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