Kernel: Don't use function-level static variables

When building the kernel for x86_64 the compiler injects calls to
__cxa_guard_acquire which depends on a bunch of pthread functions
we don't have in the kernel.
This commit is contained in:
Gunnar Beutner 2021-06-23 21:48:51 +02:00 committed by Andreas Kling
parent 6600835802
commit dc3cc7368b
Notes: sideshowbarker 2024-07-18 11:35:58 +09:00

View file

@ -17,6 +17,7 @@
namespace Kernel {
static AK::Singleton<KernelRng> s_the;
static Atomic<u32, AK::MemoryOrder::memory_order_relaxed> s_next_random_value = 1;
KernelRng& KernelRng::the()
{
@ -88,7 +89,6 @@ size_t EntropySource::next_source { static_cast<size_t>(EntropySource::Static::M
static void do_get_fast_random_bytes(u8* buffer, size_t buffer_size)
{
static Atomic<u32, AK::MemoryOrder::memory_order_relaxed> next = 1;
union {
u8 bytes[4];
@ -97,10 +97,10 @@ static void do_get_fast_random_bytes(u8* buffer, size_t buffer_size)
size_t offset = 4;
for (size_t i = 0; i < buffer_size; ++i) {
if (offset >= 4) {
auto current_next = next.load();
auto current_next = s_next_random_value.load();
for (;;) {
auto new_next = current_next * 1103515245 + 12345;
if (next.compare_exchange_strong(current_next, new_next)) {
if (s_next_random_value.compare_exchange_strong(current_next, new_next)) {
u.value = new_next;
break;
}