feat: further kernel power and power optimizations
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <Terminal/Terminal.hpp>
|
||||
#include <Hal/Apic/Interrupts.hpp>
|
||||
#include <Hal/Apic/IoApic.hpp>
|
||||
#include <Drivers/Input/InputEvents.hpp>
|
||||
|
||||
namespace Drivers::PS2::Keyboard {
|
||||
|
||||
@@ -86,14 +87,15 @@ namespace Drivers::PS2::Keyboard {
|
||||
return shift ^ caps;
|
||||
}
|
||||
|
||||
static void BufferPush(const KeyEvent& event) {
|
||||
static bool BufferPush(const KeyEvent& event) {
|
||||
uint32_t nextHead = (g_BufferHead + 1) & (KeyBufferSize - 1);
|
||||
if (nextHead == g_BufferTail) {
|
||||
// Buffer full, drop the event
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
g_KeyBuffer[g_BufferHead] = event;
|
||||
g_BufferHead = nextHead;
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool BufferPop(KeyEvent& event) {
|
||||
@@ -105,6 +107,16 @@ namespace Drivers::PS2::Keyboard {
|
||||
return true;
|
||||
}
|
||||
|
||||
static void PushAndNotify(const KeyEvent& event) {
|
||||
g_BufferLock.Acquire();
|
||||
bool pushed = BufferPush(event);
|
||||
g_BufferLock.Release();
|
||||
|
||||
if (pushed) {
|
||||
Drivers::InputEvents::NotifyActivity();
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize() {
|
||||
Kt::KernelLogStream(Kt::INFO, "PS2/KB") << "Initializing keyboard driver";
|
||||
|
||||
@@ -169,9 +181,7 @@ namespace Drivers::PS2::Keyboard {
|
||||
.Alt = g_Modifiers.LeftAlt || g_Modifiers.RightAlt,
|
||||
.CapsLock = g_Modifiers.CapsLock
|
||||
};
|
||||
g_BufferLock.Acquire();
|
||||
BufferPush(event);
|
||||
g_BufferLock.Release();
|
||||
PushAndNotify(event);
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -229,9 +239,7 @@ namespace Drivers::PS2::Keyboard {
|
||||
.Alt = g_Modifiers.LeftAlt || g_Modifiers.RightAlt,
|
||||
.CapsLock = g_Modifiers.CapsLock
|
||||
};
|
||||
g_BufferLock.Acquire();
|
||||
BufferPush(event);
|
||||
g_BufferLock.Release();
|
||||
PushAndNotify(event);
|
||||
return;
|
||||
}
|
||||
if (isModifier) return;
|
||||
@@ -256,9 +264,7 @@ namespace Drivers::PS2::Keyboard {
|
||||
.CapsLock = g_Modifiers.CapsLock
|
||||
};
|
||||
|
||||
g_BufferLock.Acquire();
|
||||
BufferPush(event);
|
||||
g_BufferLock.Release();
|
||||
PushAndNotify(event);
|
||||
}
|
||||
|
||||
bool IsKeyAvailable() {
|
||||
@@ -292,9 +298,7 @@ namespace Drivers::PS2::Keyboard {
|
||||
}
|
||||
|
||||
void InjectKeyEvent(const KeyEvent& event) {
|
||||
g_BufferLock.Acquire();
|
||||
BufferPush(event);
|
||||
g_BufferLock.Release();
|
||||
PushAndNotify(event);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user