Kernel: Replace HPET CriticalScope with SpinLock
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <kernel/InterruptController.h>
|
#include <kernel/InterruptController.h>
|
||||||
|
#include <kernel/Lock/SpinLock.h>
|
||||||
#include <kernel/Timer/Timer.h>
|
#include <kernel/Timer/Timer.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
@@ -30,6 +31,8 @@ namespace Kernel
|
|||||||
uint64_t read_main_counter() const;
|
uint64_t read_main_counter() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
mutable SpinLock m_lock;
|
||||||
|
|
||||||
bool m_is_64bit { false };
|
bool m_is_64bit { false };
|
||||||
|
|
||||||
uint64_t m_last_ticks { 0 };
|
uint64_t m_last_ticks { 0 };
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ namespace Kernel
|
|||||||
if (m_is_64bit)
|
if (m_is_64bit)
|
||||||
return regs.main_counter.full;
|
return regs.main_counter.full;
|
||||||
|
|
||||||
CriticalScope _;
|
SpinLockGuard _(m_lock);
|
||||||
uint32_t current_low = regs.main_counter.low;
|
uint32_t current_low = regs.main_counter.low;
|
||||||
uint32_t wraps = m_32bit_wraps;
|
uint32_t wraps = m_32bit_wraps;
|
||||||
if (current_low < (uint32_t)m_last_ticks)
|
if (current_low < (uint32_t)m_last_ticks)
|
||||||
@@ -256,8 +256,10 @@ namespace Kernel
|
|||||||
{
|
{
|
||||||
auto& regs = registers();
|
auto& regs = registers();
|
||||||
|
|
||||||
uint64_t current_ticks;
|
{
|
||||||
|
SpinLockGuard _(m_lock);
|
||||||
|
|
||||||
|
uint64_t current_ticks;
|
||||||
if (m_is_64bit)
|
if (m_is_64bit)
|
||||||
current_ticks = regs.main_counter.full;
|
current_ticks = regs.main_counter.full;
|
||||||
else
|
else
|
||||||
@@ -267,8 +269,8 @@ namespace Kernel
|
|||||||
m_32bit_wraps++;
|
m_32bit_wraps++;
|
||||||
current_ticks = ((uint64_t)m_32bit_wraps << 32) | current_low;
|
current_ticks = ((uint64_t)m_32bit_wraps << 32) | current_low;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_last_ticks = current_ticks;
|
m_last_ticks = current_ticks;
|
||||||
|
}
|
||||||
|
|
||||||
Scheduler::get().timer_reschedule();
|
Scheduler::get().timer_reschedule();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user