Commit graph

26 commits

Author SHA1 Message Date
Daniel Bertalan 192ee4594c AK: Fix volatile qualifier in Atomic<T*>::ptr()
It's the pointer that should be volatile, not the pointed-to object.
2023-08-18 16:20:13 +02:00
Ali Mohammad Pur f96a3c002a Everywhere: Stop shoving things into ::std and mentioning them as such
Note that this still keeps the old behaviour of putting things in std by
default on serenity so the tools can be happy, but if USING_AK_GLOBALLY
is unset, AK behaves like a good citizen and doesn't try to put things
in the ::std namespace.

std::nothrow_t and its friends get to stay because I'm being told that
compilers assume things about them and I can't yeet them into a
different namespace...for now.
2022-12-14 11:44:32 +01:00
Linus Groh d26aabff04 Everywhere: Run clang-format 2022-12-03 23:52:23 +00:00
Andreas Kling ae3ffdd521 AK: Make it possible to not using AK classes into the global namespace
This patch adds the `USING_AK_GLOBALLY` macro which is enabled by
default, but can be overridden by build flags.

This is a step towards integrating Jakt and AK types.
2022-11-26 15:51:34 +01:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
kleines Filmröllchen 7418bdb85f AK: Prevent Atomic with complex types
This would throw some really weird linker errors, so let's prevent it
from happening instead!
2022-02-23 00:42:49 +00:00
Andrew Kaster 163367da39 AK: Resolve clang-tidy warnings about unusual assignment operators
Either not returning *this, or in the case of Variant, not checking for
self assignment. In AK::Atomic, we can't return *this due to the wrapper
semantics Atomic implements.
2021-11-14 22:52:35 +01:00
Andrew Kaster e982253c33 AK: Avoid else after return in files commonly included by the Kernel 2021-11-14 22:52:35 +01:00
Timothy Flynn d9c2447999 AK: Add free function to wrap around __atomic_is_lock_free built-in
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-07-14 22:13:15 +01:00
Daniel Bertalan d6138df490 AK: Specialize Atomic<Integral> for clang compatibility
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-06-24 17:35:49 +04:30
Brian Gianforcaro 1682f0b760 Everything: Move to SPDX license identifiers in all files.
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-22 11:22:27 +02:00
AnotherTest a6e4482080 AK+Everywhere: Make StdLibExtras templates less wrapper-y
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-04-10 21:01:31 +02:00
Liav A 4a5cf8c789 AK: Add a full memory barrier function based on atomic operations
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-03-05 11:29:34 +01:00
Tom b17a889320 Kernel: Add safe atomic functions
This allows us to perform atomic operations on potentially unsafe
user space pointers.
2021-01-17 20:30:31 +01:00
Tom fb84f0ec9c AK: Add default memory order as template argument for Atomic<T>
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.
2021-01-04 19:13:52 +01:00
Ben Wiederhake 8940bc3503 Meta+AK: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
Brian Gianforcaro 3319803bd9 AK: Decorate atomic compare exchange operations with [[nodiscard]]
All CAS operations should always check return values, so they are
robust to failure in the event of conflict in parallel operation.
2020-08-05 17:28:44 +02:00
Tom 137e1dc7bd AK: Fixes for atomic pointers 2020-07-03 19:32:34 +02:00
Sergey Bugaev 5624f8d8ee AK: ALWAYS_INLINE most Atomic<T> methods 2020-06-12 16:08:45 +02:00
Tom 93b9832fac AK: Add atomic free functions
This allows for using atomic operations on any variables,
not only those wrapped in AK::Atomic<T>
2020-06-04 18:15:23 +02:00
Andreas Kling 67cc7d09a2 Revert "AK: Add AtomicRef, for atomically accesing a reference to a varaible"
This reverts commit aff594f1e7.
2020-05-20 16:24:26 +02:00
Andrew Kaster aff594f1e7 AK: Add AtomicRef, for atomically accesing a reference to a varaible
This is distintly different from Atomic<T*>, because we want to
atomically access a variable that the atomic object itself does not own.
2020-05-20 08:37:50 +02:00
Andreas Kling 94ca55cefd Meta: Add license header to source files
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-18 09:45:54 +01:00
Andreas Kling 61e6b1fb7c AK: Run clang-format on Atomic.h
Also use <AK/Types.h> instead of <stddef.h>
2020-01-12 18:45:13 +01:00
Andreas Kling 39e2b69153 AK: Atomic.h needs <stddef.h> for ptrdiff_t 2019-11-16 12:18:25 +01:00
Tom b0773a8ea6 AK: Add Atomic.h
Use gcc built-in atomics
2019-10-12 19:30:59 +02:00