1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:37:35 +00:00

Kernel: Make KernelRng not inherit from Lockable

This class was misusing the outdate Lockable template and didn't take
advantage of the lock/resource separation mechanism fully anyway.

Since the underlying PRNG has its own SpinLock, and we already use that
for synchronization everywhere anyway, we can simply remove the Lockable
inheritance from this class.
This commit is contained in:
Andreas Kling 2021-12-26 14:31:45 +01:00
parent 5ec39ca363
commit fcf6ccd771
2 changed files with 12 additions and 16 deletions

View file

@ -10,7 +10,6 @@
#include <AK/Assertions.h>
#include <AK/ByteBuffer.h>
#include <AK/Types.h>
#include <Kernel/Locking/Lockable.h>
#include <Kernel/Locking/Mutex.h>
#include <Kernel/StdLib.h>
#include <LibCrypto/Cipher/AES.h>
@ -120,7 +119,7 @@ private:
Spinlock m_lock;
};
class KernelRng : public Lockable<FortunaPRNG<Crypto::Cipher::AESCipher, Crypto::Hash::SHA256, 256>> {
class KernelRng : public FortunaPRNG<Crypto::Cipher::AESCipher, Crypto::Hash::SHA256, 256> {
AK_MAKE_ETERNAL;
public:
@ -131,8 +130,6 @@ public:
void wake_if_ready();
Spinlock& get_lock() { return resource().get_lock(); }
private:
WaitQueue m_seed_queue;
};
@ -168,7 +165,7 @@ public:
SpinlockLocker lock(kernel_rng.get_lock());
// We don't lock this because on the off chance a pool is corrupted, entropy isn't lost.
Event<T> event = { read_tsc(), m_source, event_data };
kernel_rng.resource().add_random_event(event, m_pool);
kernel_rng.add_random_event(event, m_pool);
m_pool++;
kernel_rng.wake_if_ready();
}