Skip to content

[Build][Runtime] Add a new threading library. #59287

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 40 commits into from
Jun 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0cf687a
[Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
al45tair Mar 25, 2022
66b9d21
[Runtime] Remove all use of read/write locks.
al45tair Mar 29, 2022
f5bdb85
[Threading] Create new threading library and use it.
al45tair Apr 15, 2022
2ba80e1
[Unittests] Make the Threading unit tests work.
al45tair Apr 20, 2022
785f4a2
[Unittests] Add more threading library tests.
al45tair Apr 20, 2022
e934cbc
[Threading] Fix case sensitivity bug.
al45tair Apr 20, 2022
a699633
[Threading] Auto-detect threading in the preprocessor.
al45tair Apr 20, 2022
e0d23ed
[Threading] A couple of header file fixes.
al45tair Apr 20, 2022
6d1b6db
[Threading] Fix the Linux build.
al45tair Apr 21, 2022
84083af
[Build] Move initialization of SWIFT_HOST_VARIANT_SDK further up.
al45tair Apr 21, 2022
8615983
[Build] Fix static linking.
al45tair Apr 22, 2022
02b3431
[Build] Fix the name of the threading package setting.
al45tair Apr 22, 2022
4eca62a
[Threading][Windows] Fix missing close brace.
al45tair Apr 22, 2022
9d5736e
[Threading][Windows] Fix another Windows niggle.
al45tair Apr 22, 2022
d76f80d
[Threading][Windows] More header file fixes.
al45tair Apr 22, 2022
a7e42d0
[Threading][Windows] Undefine Yield and ERROR.
al45tair Apr 26, 2022
05cccf9
[Runtime][Windows] Need to link with Synchronization.lib.
al45tair Apr 26, 2022
2e28ac4
[Threading][Windows] Don't include <windows.h>
al45tair Apr 27, 2022
66f6eb6
[Runtime][Windows] A couple of files need to include <windows.h>
al45tair Apr 27, 2022
14a4bd4
[Concurrency][Threading] Remove use of platform thread functions.
al45tair Apr 27, 2022
d6cff94
[Threading][Windows] Try to avoid declaring _RTL_SRWLOCK
al45tair Apr 28, 2022
e305a7d
[Concurrency][Windows] Add a couple of includes for Windows.
al45tair Apr 28, 2022
ef2e40a
[Concurrency][Windows] Remove unnecessary includes.
al45tair Apr 28, 2022
3bfc7e0
[Threading][Windows] Link the unit test against Synchronization.lib
al45tair Apr 28, 2022
210b772
[UnitTests][Windows] Link with Synchronization.lib
al45tair Apr 28, 2022
f3a412d
[Threading] Remove thread_get_main().
al45tair Apr 28, 2022
0e9318c
[Threading] Put everything through git clang-format.
al45tair Apr 28, 2022
c7c1c1b
[Threading] Fix some problems with the C11 threading code.
al45tair Apr 29, 2022
eb4c81d
[Threading] Don't use TLS keys as template arguments.
al45tair May 4, 2022
b5c8b79
[Threading] Move stack bounds fetching into the threading library.
al45tair May 6, 2022
4825578
[Concurrency] Remove redundant include.
al45tair May 6, 2022
dc809f8
[Threading] A few include tweaks.
al45tair May 6, 2022
6962758
[Threading] Add the ability to use any C++ callable in swift::once().
al45tair May 24, 2022
668bcbc
[Threading] Fix a few things following rebase.
al45tair May 24, 2022
c401cc3
[Threading] Use llvm::Optional<> rather than making a zero lower boun…
al45tair May 24, 2022
33f103f
[Build] Fix some issues with the standalone library build.
al45tair May 31, 2022
124581a
[Build][Concurrency] Fix Concurrency build to work for Linux.
al45tair Jun 1, 2022
aa0265b
[Threading] Use raw gettid syscall for older glibc compatibility
kateinoigakukun Jun 2, 2022
c46d4af
[Build] Explicitly include threading library when not building stdlib.
al45tair Jun 6, 2022
ede4010
[BackDeployConcurrency] Fix to use the new threading library.
al45tair Jun 7, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[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
  • Loading branch information
al45tair committed Jun 7, 2022
commit d6cff94e7f5b35e725ecef0bfa2b2f1f52d34c5a
24 changes: 12 additions & 12 deletions include/swift/Threading/Impl/Win32.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,31 @@ inline bool threads_same(thread_id a, thread_id b) { return a == b; }

// .. Mutex support ..........................................................

using mutex_handle = ::SRWLOCK;
using mutex_handle = SWIFT_SRWLOCK;

inline void mutex_init(mutex_handle &handle, bool checked=false) {
handle = SRWLOCK_INIT;
}
inline void mutex_destroy(mutex_handle &handle) { }

inline void mutex_lock(mutex_handle &handle) {
::AcquireSRWLockExclusive(&handle);
AcquireSRWLockExclusive(&handle);
}
inline void mutex_unlock(mutex_handle &handle) {
::ReleaseSRWLockExclusive(&handle);
ReleaseSRWLockExclusive(&handle);
}
inline bool mutex_try_lock(mutex_handle &handle) {
return !!::TryAcquireSRWLockExclusive(&handle);
return !!TryAcquireSRWLockExclusive(&handle);
}

inline void mutex_unsafe_lock(mutex_handle &handle) {
::AcquireSRWLockExclusive(&handle);
AcquireSRWLockExclusive(&handle);
}
inline void mutex_unsafe_unlock(mutex_handle &handle) {
::ReleaseSRWLockExclusive(&handle);
ReleaseSRWLockExclusive(&handle);
}

using lazy_mutex_handle = ::SRWLOCK;
using lazy_mutex_handle = SWIFT_SRWLOCK;

// We don't need to be lazy here because Win32 has SRWLOCK_INIT.
inline constexpr lazy_mutex_handle lazy_mutex_initializer() {
Expand All @@ -68,20 +68,20 @@ inline constexpr lazy_mutex_handle lazy_mutex_initializer() {
inline void lazy_mutex_destroy(lazy_mutex_handle &handle) { }

inline void lazy_mutex_lock(lazy_mutex_handle &handle) {
::AcquireSRWLockExclusive(&handle);
AcquireSRWLockExclusive(&handle);
}
inline void lazy_mutex_unlock(lazy_mutex_handle &handle) {
::ReleaseSRWLockExclusive(&handle);
ReleaseSRWLockExclusive(&handle);
}
inline bool lazy_mutex_try_lock(lazy_mutex_handle &handle) {
return !!::TryAcquireSRWLockExclusive(&handle);
return !!TryAcquireSRWLockExclusive(&handle);
}

inline void lazy_mutex_unsafe_lock(lazy_mutex_handle &handle) {
::AcquireSRWLockExclusive(&handle);
AcquireSRWLockExclusive(&handle);
}
inline void lazy_mutex_unsafe_unlock(lazy_mutex_handle &handle) {
::ReleaseSRWLockExclusive(&handle);
ReleaseSRWLockExclusive(&handle);
}

// .. Once ...................................................................
Expand Down
38 changes: 29 additions & 9 deletions include/swift/Threading/Impl/Win32/Win32Defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,8 @@ typedef unsigned long DWORD;

typedef VOID (NTAPI* PFLS_CALLBACK_FUNCTION)(PVOID lpFlsData);

// We can't define this struct if <winnt.h> already did so
#ifndef _WINNT_
struct _RTL_SRWLOCK {
PVOID Ptr;
};
#endif // _WINNT_

typedef struct _RTL_SRWLOCK RTL_SRWLOCK, *PRTL_SRWLOCK;
typedef RTL_SRWLOCK SRWLOCK, *PSRWLOCK;
typedef struct _RTL_SRWLOCK *PRTL_SRWLOCK;
typedef PRTL_SRWLOCK PSRWLOCK;

// These have to be #defines, to avoid problems with <windows.h>
#define RTL_SRWLOCK_INIT {0}
Expand All @@ -68,4 +61,31 @@ extern "C" {
WINBASEAPI BOOL WINAPI FlsFree(DWORD dwFlsIndex);
}

namespace swift {
namespace threading_impl {

// We do this because we can't declare _RTL_SRWLOCK here in case someone
// later includes <windows.h>
struct SWIFT_SRWLOCK {
PVOID Ptr;
};

typedef SWIFT_SRWLOCK *PSWIFT_SRWLOCK;

inline VOID InitializeSRWLock(PSWIFT_SRWLOCK SRWLock) {
::InitializeSRWLock(reinterpret_cast<PSRWLOCK>(SRWLock));
}
inline VOID ReleaseSRWLockExclusive(PSWIFT_SRWLOCK SRWLock) {
::ReleaseSRWLockExclusive(reinterpret_cast<PSRWLOCK>(SRWLock));
}
inline VOID AcquireSRWLockExclusive(PSWIFT_SRWLOCK SRWLock) {
::AcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(SRWLock));
}
inline BOOLEAN TryAcquireSRWLockExclusive(PSWIFT_SRWLOCK SRWLock) {
return ::TryAcquireSRWLockExclusive(reinterpret_cast<PSRWLOCK>(SRWLock));
}

}
}

#endif // SWIFT_THREADING_IMPL_WIN32_DEFS_H