summaryrefslogtreecommitdiff
path: root/AK/Atomic.h
AgeCommit message (Collapse)Author
2021-07-14AK: Add free function to wrap around __atomic_is_lock_free built-inTimothy Flynn
Note: this exact implementation is needed for __atomic_is_lock_free to link with both GCC (for the SerenityOS build) and Clang (for the Fuzzer build). The size argument must be a compile-time constant, otherwise it fails to link with both compilers. Alternatively, the following definition links with GCC but fails with Clang: template<size_t S> static inline bool atomic_is_lock_free(volatile void* ptr = nullptr) { return __atomic_is_lock_free(S, ptr); }
2021-06-24AK: Specialize `Atomic<Integral>` for clang compatibilityDaniel Bertalan
While Clang claims to implement GCC's atomics libcall API, a small incompatibility caused our builds to fail on Clang. Clang requires requires the operands to its fixed-size functions to be integer types, while GCC will take any type with the same size and alignment as the various integer primitives. This was problematic, as atomic `enum class`es would not compile. Furthermore, Clang does not like if only one operand pointer is marked volatile. Because it only affects the standalone atomic functions, that will be fixed in a later commit. As an added benefit, the code is more type-safe, as it won't let us perform arithmetic on non-integer types. Types with overloaded arithmetic types won't cause unexpected behavior anymore. The constructors for the various atomic types can now be used in constant expressions.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-10AK+Everywhere: Make StdLibExtras templates less wrapper-yAnotherTest
This commit makes the user-facing StdLibExtras templates and utilities arguably more nice-looking by removing the need to reach into the wrapper structs generated by them to get the value/type needed. The C++ standard library had to invent `_v` and `_t` variants (likely because of backwards compat), but we don't need to cater to any codebase except our own, so might as well have good things for free. :^)
2021-03-05AK: Add a full memory barrier function based on atomic operationsLiav A
We use atomic_signal_fence and atomic_thread_fence together to prevent reordering of memory accesses by the CPU and the compiler. The usage of these functions was suggested by @tomuta so we can be sure that important memory accesses happen in the expected order :)
2021-01-17Kernel: Add safe atomic functionsTom
This allows us to perform atomic operations on potentially unsafe user space pointers.
2021-01-04AK: Add default memory order as template argument for Atomic<T>Tom
This is useful for collecting statistics, e.g. Atomic<unsigned, MemoryOrder::memory_order_relaxed> would allow using operators such as ++ to use relaxed semantics throughout without having to explicitly call fetch_add with the memory order.
2020-09-25Meta+AK: Make clang-format-10 cleanBen Wiederhake
2020-08-05AK: Decorate atomic compare exchange operations with [[nodiscard]]Brian Gianforcaro
All CAS operations should always check return values, so they are robust to failure in the event of conflict in parallel operation.
2020-07-03AK: Fixes for atomic pointersTom
2020-06-12AK: ALWAYS_INLINE most Atomic<T> methodsSergey Bugaev
2020-06-04AK: Add atomic free functionsTom
This allows for using atomic operations on any variables, not only those wrapped in AK::Atomic<T>
2020-05-20Revert "AK: Add AtomicRef, for atomically accesing a reference to a varaible"Andreas Kling
This reverts commit aff594f1e790feff0cd7dda3e9f0ecd5573c51bf.
2020-05-20AK: Add AtomicRef, for atomically accesing a reference to a varaibleAndrew Kaster
This is distintly different from Atomic<T*>, because we want to atomically access a variable that the atomic object itself does not own.
2020-01-18Meta: Add license header to source filesAndreas Kling
As suggested by Joshua, this commit adds the 2-clause BSD license as a comment block to the top of every source file. For the first pass, I've just added myself for simplicity. I encourage everyone to add themselves as copyright holders of any file they've added or modified in some significant way. If I've added myself in error somewhere, feel free to replace it with the appropriate copyright holder instead. Going forward, all new source files should include a license header.
2020-01-12AK: Run clang-format on Atomic.hAndreas Kling
Also use <AK/Types.h> instead of <stddef.h>
2019-11-16AK: Atomic.h needs <stddef.h> for ptrdiff_tAndreas Kling
2019-10-12AK: Add Atomic.hTom
Use gcc built-in atomics