Commit Graph

14 Commits

Author SHA1 Message Date
John McCall
3343331ded Remove the ConditionVariable abstraction. 2021-12-20 18:04:19 -05:00
Mike Ash
e82d9e8c7b Move ConditionMutex to ConditionVariable::Mutex and move various other Mutex.h types to be nested. 2020-11-10 14:44:59 -05:00
Mike Ash
dd6c235a2d [Runtime] Use os_unfair_lock for Mutex and StaticMutex on Darwin.
os_unfair_lock is much smaller than pthread_mutex_t (4 bytes versus 64) and a bit faster.

However, it doesn't support condition variables. Most of our uses of Mutex don't use condition variables, but a few do. Introduce ConditionMutex and StaticConditionMutex, which allow condition variables and continue to use pthread_mutex_t.

On all other platforms, we continue to use the same backing mutex type for both Mutex and ConditionMutex.

rdar://problem/45412121
2020-11-06 13:05:37 -05:00
Mike Ash
12d114713f [Runtime] Switch MetadataCache to ConcurrentReadableHashMap. (#34307)
* [Runtime] Switch MetadataCache to ConcurrentReadableHashMap.

Use StableAddressConcurrentReadableHashMap. MetadataCacheEntry's methods for awaiting a particular state assume a stable address, where it will repeatedly examine `this` in a loop while waiting on a condition variable, so we give it a stable address to accommodate that. Some of these caches may be able to tolerate unstable addresses if this code is changed to perform the necessary table lookup each time through the loop instead. Some of them store metadata inline and we assume metadata never moves, so they'll have to stay this way.

* Have StableAddressConcurrentReadableHashMap remember the last found entry and check that before doing a more expensive lookup.

* Make a SmallMutex type that stores the mutex data out of line, and use it to get LockingConcurrentMapStorage to fit into the available space on 32-bit.

rdar://problem/70220660
2020-11-04 15:10:50 -05:00
Mike Ash
9134e65fca Move Mutex test's threading helpers to a separate header so other tests can use them. 2020-08-07 11:17:38 -04:00
Mike Ash
855dd8d5fb [Tests] Use a plain array of std::atomic rather than a vector of atomic.
The restrictions on std::atomic make a it fragile to have a vector of them, and this failed to compile on Linux in CI.

While I'm in there, clean up a couple of tests that repeated a raw `10` for the thread count.

rdar://problem/49709062
2019-04-09 10:52:53 -04:00
Mike Ash
6172f72af9 [Tests] Make Mutex.cpp tests more reliable.
Many of these tests would fail if one of the test threads didn't begin execution within 100 milliseconds. They would hit while (!done) the very first time and never execute the loop body. That does happen from time to time, and the result would be a spurious failure. Change the loops to do {} while(!done) to ensure they always execute at least one iteration.

Many tests also had the test threads concurrently write results to a std::vector, which appeared to be causing some failures in my local testing when I had extra sleeps inserted to simulate pathological scheduling. Change the results vectors to be vectors of std::atomic to ensure that this concurrent writing is safe.

These changes shouldn't affect its ability to test the functionality it intends to test.

rdar://problem/49386389
2019-04-05 16:40:08 -04:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Shawn Erickson
d78c6e3403 [runtime] addressed review comments outlined in #1950 2016-04-28 10:39:35 -07:00
Shawn Erickson
a0452be947 [runtime] enhanced and refactored recently added Mutex abstraction
- added read / write lock support
- added non-fatal error support to allow use of mutex in fatal error reporting pathway
- isolated pthread implementation to it own header/cpp file pair
- expanded unit tests to cover new code as well as better test existing mutex
- removed a layer of complexity that added no real value
2016-04-06 13:02:37 -07:00
Ben Langmuir
fa77a7afc9 Fix race condition in Mutex LockableThreaded test
If the thread starts slowly enough it will succeed in taking the lock,
leading to a deadlock. We saw this test hanging on some of our bots
inside of pthread's lock acquire.
2016-04-01 11:06:48 -07:00
Shawn Erickson
aeceb2cad8 [runtime] Addressed PR1731 comments and...
- cleaned up private scoping
- removed generally unneeded API
- fix defect in unit tests causing stuck threads
2016-03-23 22:54:36 -07:00
Shawn Erickson
2f84220712 [runtime] added Mutex, Condition, and Scoped locks for use by Swift runtime (see SR-946) 2016-03-20 22:56:24 -07:00