aboutsummaryrefslogtreecommitdiff
path: root/absl/synchronization
Commit message (Collapse)AuthorAgeFilesLines
...
* absl: fix Mutex writer starvation related to uninit priorityAbseil Team2023-06-162-22/+59
| | | | | | | | | | | | | | | | | | Currently when we queue the first thread, we don't init its priority. Subsequent queued threads init priority, but they compare it against the first thread priority, which is uninit. Thus the order can be wrong. It can lead to complete false starvation in some corner cases. On Linux the default priority is 0, which matches the uninit value, thus the problem is harder to spot on Linux (only possible if explicit thread priorities are used). But on Darwin the default priority is 31, thus the first thread falsely looks like lower priority than subsequently queued threads. The added test exposes the problem on Darwin. Always initialize the priority before queuing threads. PiperOrigin-RevId: 540814133 Change-Id: I513ce1493a67afe77d3e92fb49000b046b42a9f2
* absl: move comment in mutex.cc to where it belongsAbseil Team2023-06-151-6/+6
| | | | | | | | | | Move the comment that relates to kMuDesig close to kMuDesig definition. Currently it's placed in between unrelated flags. NFC PiperOrigin-RevId: 540792401 Change-Id: I5f6a928cd9e01664812b2a7c3d9eb087c0723d7f
* Migrate most RAW_LOGs and RAW_CHECKs in tests to regular LOG and CHECK.Andy Getzendanner2023-05-235-106/+93
| | | | | | | | | | | The non-RAW_ versions provide better output but weren't available when most of these tests were written. There are just a couple spots where RAW_ is actually needed, e.g. signal handlers and malloc hooks. Also fix a couple warnings in layout_test.cc newly surfaced because the optimizer understands CHECK_XX differently than INTERNAL_CHECK. PiperOrigin-RevId: 534584435 Change-Id: I8d36fa809ffdaae5a3813064bd602cb8611c1613
* Mutex: Remove the deprecated absl::RegisterSymbolizer() hookDerek Mauro2023-05-152-26/+2
| | | | | | | | absl::RegisterSymbolizer() has been deprecated for 5 years. It is being removed following our compatibility policy. <https://abseil.io/about/compatibility> PiperOrigin-RevId: 532174866 Change-Id: Id5c3b86698e389099d3d707c4e57f30f1f155d2e
* For Bazel builds, mark some of the low-level tests that are dependentDerek Mauro2023-05-081-0/+2
| | | | | | | | | | on timing as flaky. This will run them up to 3 times (in the default configuration) and only consider the test failed if it fails each time. PiperOrigin-RevId: 530348477 Change-Id: Ib77bd8a166828b82a1b49ee5ef2e8321752e51d0
* Nop change.Abseil Team2023-05-081-1/+0
| | | | | PiperOrigin-RevId: 530238518 Change-Id: I2bfca582c0734f7e6943c5359730a2857809e2d2
* Fix spelling mistakesVertexwahn2023-05-022-3/+3
|
* PR #1433: Fix incorrect timespec definition on 32-bit platforms with 64-bit ↵Oleg Lyovin2023-05-021-6/+42
| | | | | | | | | | | | | | | | | time_t Imported from GitHub PR https://github.com/abseil/abseil-cpp/pull/1433 Some 32-bit configurations may use 64-bit time_t, which leads to different layout of userspace timespec and the one expected by SYS_futex implementation in kernel. In particular the issue occurs when using musl libc which has switched to unconditional 64-bit time_t definition. This patch introduces custom struct timespec with two longs when old SYS_futex is used to match the kernel timespec definition. Merge 2eaca415da825b3f31a90f58a35bdef2b6d2a6c5 into f8bf909108b3604a00590a074f2986c0895514d2 Merging this change closes #1433 COPYBARA_INTEGRATE_REVIEW=https://github.com/abseil/abseil-cpp/pull/1433 from olegartys:futex_time64_bug 2eaca415da825b3f31a90f58a35bdef2b6d2a6c5 PiperOrigin-RevId: 528796119 Change-Id: Idaa952f64bd97c6dc9703a8b44deac43e29ff9ae
* For Bazel builds, mark some of the low-level tests that are dependentDerek Mauro2023-05-021-0/+2
| | | | | | | | | | on timing as flaky. This will run them up to 3 times (in the default configuration) and only consider the test failed if it fails each time. PiperOrigin-RevId: 528785128 Change-Id: I4aa5b74aa3a6873c83f2a01734c679351b1cd5d0
* Merge pull request #1416 from AtariDreams:fillCopybara-Service2023-04-241-2/+2
|\ | | | | | | | | PiperOrigin-RevId: 526675031 Change-Id: Ib84423ccea2d0183166194a0916a97a7ed32915c
| * Prefer copy_n and fill_n over copy and fill where appropriate.Rose2023-04-191-2/+2
| | | | | | | | This lets us avoid having to do the addition manually.
* | Mutex: Remove MSVC 2015 workaroundsDerek Mauro2023-04-242-0/+125
| | | | | | | | | | PiperOrigin-RevId: 526653332 Change-Id: I0a20d4ac636da3f1a930f96e0cdb9275527e4688
* | Support pthread_cond_clockwait() and sem_clockwait() on AndroidDerek Mauro2023-04-202-0/+4
| | | | | | | | | | | | | | | | | | for __ANDROID_API__ >= 30 https://android.googlesource.com/platform/bionic/+/69010802d037dbc10377416bd9cc696fa34b9384%5E%21/libc/include/pthread.h PiperOrigin-RevId: 525815479 Change-Id: I88cd1a06a4f7bb5380ff7c1e6a8f45e2b04b7df8
* | Fix flaky test failures.Evan Brown2023-04-201-6/+6
|/ | | | | PiperOrigin-RevId: 525808747 Change-Id: I01aeef6b8558673bf1fc38a948dcecf00300b641
* Spell out the meaning of non-reentrant/non-recursive.Thomas Köppe2023-04-131-12/+28
| | | | | PiperOrigin-RevId: 524112966 Change-Id: I197f98f95b1c4de7f53295a6a01db9b0379b4f55
* Don't override clock_gettime in the KernelTimeout and WaiterDerek Mauro2023-04-134-8/+17
| | | | | | | tests under sanitizers. The overrides break the sanitizers. PiperOrigin-RevId: 524037272 Change-Id: I85b87d3870c488cb316505e94b394c6f98e9f60f
* Synchronization: Consolidate the logic for whether steady clocks are supportedDerek Mauro2023-04-1212-47/+91
| | | | | | | for relative timeouts PiperOrigin-RevId: 523789416 Change-Id: Ide4cfdcae9ea7bffca3355c80ea9c8833a9536e6
* Synchronization: Support true relative timeouts using the POSIXDerek Mauro2023-04-086-11/+150
| | | | | | | | | | | proposed standard pthread_cond_clockwait() and sem_clockwait(). These are currently implemented in glibc >= 2.30. These methods take a clock and use an absolute time with reference to that clock, so KernelTimeout now can produce these values. PiperOrigin-RevId: 522824226 Change-Id: Ife98713f6f95d800b1f8e52d5364a3dbebc4f8a6
* Synchronization: Support true relative timeouts on Apple platformsDerek Mauro2023-04-062-6/+31
| | | | | | | using the non-portable pthread_cond_timedwait_relative_np() PiperOrigin-RevId: 522340555 Change-Id: I08682f74d8d94965330f12274c7a92632b1a29f1
* Fix flakiness issues in timing tests.Evan Brown2023-03-272-4/+4
| | | | | PiperOrigin-RevId: 519939158 Change-Id: I9b049fa55167ed4064f3909887eec7bc52601677
* Internal Code ChangeAbseil Team2023-03-231-1/+1
| | | | | PiperOrigin-RevId: 518835147 Change-Id: I86d8a49563cb5f74461a57e2b6dceac539749c86
* Add an implementation of Waiter that uses std::mutex/std::condition_variableDerek Mauro2023-03-216-0/+160
| | | | | | | | | | | | | | | This implementation may at some point become the default on some platforms. Currently not all platforms have widespread support for both real absolute timeouts or real relative timeouts (here "real" means without converting to the other timeout type which is the only one supported by the underlying APIs). In this case we can defer to their standard library to implement correct support. This is not currently the default on any platform Note: The size of WaiterState had to increase to fit the new implementation PiperOrigin-RevId: 518266646 Change-Id: I7f246646a960d6e1b155f9de0bf2f681c5d3d245
* Synchronization: Refactor Waiter to allow us to write testsDerek Mauro2023-03-2016-517/+1079
| | | | | | | | | | | | | Instead of being only able to test the platform Waiter implementation, this allows us to be able to test all Waiter implementations that build on a specific platform. A unittest is added that tests all implementations that work for the platform, and allows us to check that the expected one is being used by printing the name of the selected implementation. PiperOrigin-RevId: 518072415 Change-Id: Ie9e6fcd9d8283b4038e6f4e68a304d2adcc04b19
* Increase the timeout of Windows for the kernel timeout tests.Tom Rybka2023-03-161-1/+3
| | | | | | | Windows tests often run in Emulation, and even with KVM we can still timeout. PiperOrigin-RevId: 517192968 Change-Id: I3b4e435f8ac8ad1e7eab6f043c051fa75efed64b
* Synchronization: Add support for true relative timeouts usingDerek Mauro2023-03-143-46/+84
| | | | | | | | | | | | | | | | | | | | | | | | | | monotonic clocks on Linux when the implementation uses futexes After this change, when synchronization methods that wait are passed an absl::Duration to limit the wait time, these methods will wait for that interval, even if the system clock is changed (subject to any limitations with how CLOCK_MONOTONIC keeps track of time). In other words, an observer measuring the time with a stop watch will now see the correct interval, even if the system clock is changed. Previously, the duration was added to the current time, and methods would wait until that time was reached on the possibly changed realtime system clock. The behavior of the synchronization methods that take an absl::Time is unchanged. These methods always wait until the absolute point in time is reached and respect changes to the system clock. In other words, an observer will always see the timeout occur when a wall clock reaches that time, even if the clock is manipulated externally. Note: ABSL_PREDICT_FALSE was removed from the error case in Futex as timeouts are handled by this case, and timeouts are part of normal operation. PiperOrigin-RevId: 516534869 Change-Id: Ib70b83e4be3f9e3f1727646975a21a1d30acb242
* Synchronization: Change KernelTimeout to always store absoluteDerek Mauro2023-03-133-73/+72
| | | | | | | | | | timeouts, but when a relative timeout is provided, the timeout is an absolute timeout against a steady clock (when possible). This allows methods that return relative timeouts to automatically recompute the remaining duration, for instance, on suprious wakeups. PiperOrigin-RevId: 516304139 Change-Id: I7d739cb50dd749eba5dba7ac6c34d18dc53703ed
* Rollback Mutex relative timeout support because of internal incompatibilityAbseil Team2023-03-094-177/+47
| | | | | PiperOrigin-RevId: 515427893 Change-Id: I89e8756fcf400459b0226d14785c6511ad3e380b
* Synchronization: Add support for true relative timeouts usingDerek Mauro2023-03-084-47/+177
| | | | | | | | | | | | | | | | | | | | | | | | | | monotonic clocks on Linux when the implementation uses futexes After this change, when synchronization methods that wait are passed an absl::Duration to limit the wait time, these methods will wait for that interval, even if the system clock is changed (subject to any limitations with how CLOCK_MONOTONIC keeps track of time). In other words, an observer measuring the time with a stop watch will now see the correct interval, even if the system clock is changed. Previously, the duration was added to the current time, and methods would wait until that time was reached on the possibly changed realtime system clock. The behavior of the synchronization methods that take an absl::Time is unchanged. These methods always wait until the absolute point in time is reached and respect changes to the system clock. In other words, an observer will always see the timeout occur when a wall clock reaches that time, even if the clock is manipulated externally. Note: ABSL_PREDICT_FALSE was removed from the error case in Futex as timeouts are handled by this case, and timeouts are part of normal operation. PiperOrigin-RevId: 515043788 Change-Id: I151127b588065bd1316273f36d7c946545c2c892
* Rollback because of internal incompatibility.Abseil Team2023-02-284-177/+47
| | | | | PiperOrigin-RevId: 512979517 Change-Id: I7fe38ed246e42e6f8eb322e15c3b299215163168
* Fix out of bounds array access when deadlock detector finds exceptionally ↵Abseil Team2023-02-222-1/+23
| | | | | | | large cycles. PiperOrigin-RevId: 511536497 Change-Id: If70a1c72ef5f7cbb4a80100c4edff459373a5d55
* Synchronization: Add support for true relative timeouts usingDerek Mauro2023-02-174-47/+177
| | | | | | | | | | | | | | | | | | | | | | | | | | monotonic clocks on Linux when the implementation uses futexes After this change, when synchronization methods that wait are passed an absl::Duration to limit the wait time, these methods will wait for that interval, even if the system clock is changed (subject to any limitations with how CLOCK_MONOTONIC keeps track of time). In other words, an observer measuring the time with a stop watch will now see the correct interval, even if the system clock is changed. Previously, the duration was added to the current time, and methods would wait until that time was reached on the possibly changed realtime system clock. The behavior of the synchronization methods that take an absl::Time is unchanged. These methods always wait until the absolute point in time is reached and respect changes to the system clock. In other words, an observer will always see the timeout occur when a wall clock reaches that time, even if the clock is manipulated externally. Note: ABSL_PREDICT_FALSE was removed from the error case in Futex as timeouts are handled by this case, and timeouts are part of normal operation. PiperOrigin-RevId: 510405347 Change-Id: I0b3ea390de97014cfa353079ae2e0c1c637aca69
* Add KernelTimeout methods that convert the timeout to theDerek Mauro2023-02-163-0/+94
| | | | | | | | | | | | | | | std::chrono methods used by std::condition_variable. A followup change will add an implemention of synchronization_internal::Waiter that can use std:mutex/std::condition_variable to implement the per-thread semaphore that absl::Mutex waits on. This implementation may at some point become the default on platforms such as Windows where there doesn't seem to be an easy way of supporting real absolute timeouts. In this case we can defer to their standard library to implement correct support. PiperOrigin-RevId: 510204786 Change-Id: Icf4d695013fd060abbd53dae23e71ea36f731565
* KernelTimeout optimization: Use absl::GetCurrentTimeNanos()Derek Mauro2023-02-151-3/+3
| | | | | | | instead of absl::ToUnixNanos(absl::Now()); PiperOrigin-RevId: 509829866 Change-Id: Ib34362762304ad6eb7980a1227d717069b84f656
* Rewrite KernelTimeout to support both absolute and relative timeoutsDerek Mauro2023-02-095-115/+545
| | | | | | | | | | | | | | APIs that take KernelTimeout as a parameter can now query if an absolute or relative timeout was requested. If the underlying API can only use one type of timeout, the code will do a reasonable conversion. The goal is to eventually enable the possibility of using wait times that are based on monotonic clocks that are safe against system clock steps. PiperOrigin-RevId: 508541507 Change-Id: Id08bf13515f3e1bfd78d88393cde98a6fd3ef72c
* Add overrides to other functions which call Waiter::GetWaiterAbseil Team2023-02-083-9/+26
| | | | | PiperOrigin-RevId: 508124592 Change-Id: Ib183e6e241c81b2760e7f849f8af8e7e2c30ea42
* Delete unused Futex methodsDerek Mauro2023-02-011-25/+0
| | | | | PiperOrigin-RevId: 506323250 Change-Id: I0f7d4532c19088b011740ceff87ecec55cc34edb
* Minor formatting: Fix misplaced space.Abseil Team2023-01-191-1/+1
| | | | | PiperOrigin-RevId: 503110285 Change-Id: I59c48b1486386e2db8fb62cf8bfa1a691865f704
* Clean up the XRay annotation leftover on mutex.Abseil Team2022-12-271-7/+7
| | | | | PiperOrigin-RevId: 497998566 Change-Id: I8d43311e280a5ea46c42abed55be62cd70d4d54a
* Replace ABSL_INTERNAL_UNREACHABLE with ABSL_UNREACHABLE()Derek Mauro2022-12-221-2/+3
| | | | | PiperOrigin-RevId: 497197704 Change-Id: I3865a874e04f6f55a1ab374b03451535a86bc5a3
* Remove unneeded "friends" from KernelTimeout.Abseil Team2022-12-211-5/+3
| | | | | PiperOrigin-RevId: 496974198 Change-Id: I73b4013a2ad9fd37650d788cbd1e758b327b59d2
* Add MakeAbsNs to KernelTimeout.Abseil Team2022-12-151-2/+17
| | | | | | | | | Rather than add new friends every time a new (internal) use arises, just expose the timestamp. PiperOrigin-RevId: 495722262 Change-Id: I25d2ce64769dc58cbe634259f07c600ce6c1e714
* Fix the documentation of the atomic_hook.h registration functions to ↵Greg Falcon2022-12-151-10/+11
| | | | | | | | | | | correctly state that only the first registered hook will be honored. The comments that imply otherwise were never true, and were a leftover artifact during initial development of the feature. Also remove a TODO() I gave myself years ago; this is never going to happen and isn't worth the bother. PiperOrigin-RevId: 495687371 Change-Id: I63f8ef57d659075bf290caae0617ea61ceb2c1db
* Remove static initializer from mutex.h.Abseil Team2022-11-302-6/+6
| | | | | PiperOrigin-RevId: 491915718 Change-Id: I7469601857b5a3506163518d29f49792f3053b34
* absl: fix Mutex TSan annotationsAbseil Team2022-11-281-3/+8
| | | | | | | | | TSan misses synchronization around passing PerThreadSynch between threads since it happens inside of the Mutex code (which me mostly ignore), so we need to ignore all accesses to the object. PiperOrigin-RevId: 491297912 Change-Id: I13ea2015dee5c1a3fc4315c85112902ccffccc45
* Update Condition to allocate 24 bytes for MSVC platform pointers to methods.Abseil Team2022-11-166-103/+174
| | | | | PiperOrigin-RevId: 488986942 Change-Id: I2babb7ea30d60c544f55ca9ed02d9aed23051a12
* Use AnyInvocable in internal thread_poolAbseil Team2022-11-153-4/+9
| | | | | PiperOrigin-RevId: 488676817 Change-Id: I13f15bb93ab6dda4c56caf969be3c14f84ada6a0
* Force a conservative allocation for pointers to methods in Condition objects.Abseil Team2022-11-073-58/+198
| | | | | | | | | | | In order for Condition to work on Microsoft platforms, it has to store pointers to methods that are larger than we usually expect. MSVC pointers to methods from class hierarchies that employ multiple inheritance or virtual inheritance are strictly larger than pointers to methods in class hierarchies that only employ single inheritance. This change introduces an opaque declaration of a class, which is not fulfilled. This declaration is used to calculate the size of the Condition method pointer allocation. Because the declaration is of unspecified inheritance, the compiler is forced to use a conservatively large allocation, which will thereby accommodate all method pointer sizes. Because the `method_` and `function_` callbacks are only populated in mutually exclusive conditions, they can be allowed to take up the same space in the Condition object. This change combines the `method_` and `function_` fields and renames the new field to `callback_`. The constructor logic is updated to reflect the new field. PiperOrigin-RevId: 486701312 Change-Id: If06832cc26f27d91e295183e44dc29440af5f9db
* Merge pull request #1307 from KindDragon:patch-1Copybara-Service2022-11-031-3/+3
|\ | | | | | | | | PiperOrigin-RevId: 485885633 Change-Id: Idfaf6ce22a9421fe05ae38029c8a68b720ce50ba
| * Fix MSVC version checking in lifetime_test.ccArkady Shapkin2022-11-031-3/+2
|/
* Mutex: Fix stall on single-core systemsAbseil Team2022-10-241-8/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | On single-core systems, a thread could be preempted while holding an absl::Mutex, or even worse, the spin lock. If a FIFO thread wakes up and tries to acquire this lock, it might not be able to yield() to the sleeping thread. Within MutexDelay(), a yield() and a sleep(10us) are used to yield the CPU. The yield() would do nothing if the calling thread holds the highest priority in the system. The 10us sleep() may not be able to reach the scheduler either, if the system is slow enough. This code path is known to be reachable in the following scenarios: - a FIFO thread calls LockSlowLoop() with spin lock held by a normal thread - a FIFO thread calls LockWhen*() with the Mutex held by a normal thread for a long time - a FIFO thread calls Await*(), releases the Mutex to be held by a normal thread for a long time This CL adds a mutex global for the sleep time, and sets it using the return time of the a yield() call. Yield() must reach the scheduler even when it fails to yield to anyone, and would allow sleep() to do the same. A small constant multiplier (5) is also applied to overcome uncontrollable factors in the runtime and help sleep() to consistently yield to another thread. Upper and lower bounds for the sleep time is also controlled to block any unreasonable values. PiperOrigin-RevId: 483459711 Change-Id: I14efadbadaf9244a2462f377b515147bda651c89