mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:58:11 +00:00
Kernel: Switch singletons to use new Singleton class
MemoryManager cannot use the Singleton class because MemoryManager::initialize is called before the global constructors are run. That caused the Singleton to be re-initialized, causing it to create another MemoryManager instance. Fixes #3226
This commit is contained in:
parent
ba6e4fb77f
commit
d89582880e
46 changed files with 221 additions and 170 deletions
|
@ -24,6 +24,7 @@
|
|||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <AK/Singleton.h>
|
||||
#include <Kernel/ACPI/Parser.h>
|
||||
#include <Kernel/CommandLine.h>
|
||||
#include <Kernel/Scheduler.h>
|
||||
|
@ -39,12 +40,11 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
static TimeManagement* s_time_management;
|
||||
static AK::Singleton<TimeManagement> s_the;
|
||||
|
||||
TimeManagement& TimeManagement::the()
|
||||
{
|
||||
ASSERT(s_time_management);
|
||||
return *s_time_management;
|
||||
return *s_the;
|
||||
}
|
||||
|
||||
bool TimeManagement::is_system_timer(const HardwareTimer& timer) const
|
||||
|
@ -65,11 +65,9 @@ time_t TimeManagement::epoch_time() const
|
|||
|
||||
void TimeManagement::initialize()
|
||||
{
|
||||
ASSERT(!s_time_management);
|
||||
if (kernel_command_line().lookup("time").value_or("modern") == "legacy")
|
||||
s_time_management = new TimeManagement(false);
|
||||
else
|
||||
s_time_management = new TimeManagement(true);
|
||||
ASSERT(!s_the.is_initialized());
|
||||
s_the.ensure_instance();
|
||||
|
||||
}
|
||||
time_t TimeManagement::seconds_since_boot() const
|
||||
{
|
||||
|
@ -90,8 +88,9 @@ time_t TimeManagement::boot_time() const
|
|||
return RTC::boot_time();
|
||||
}
|
||||
|
||||
TimeManagement::TimeManagement(bool probe_non_legacy_hardware_timers)
|
||||
TimeManagement::TimeManagement()
|
||||
{
|
||||
bool probe_non_legacy_hardware_timers = !(kernel_command_line().lookup("time").value_or("modern") == "legacy");
|
||||
if (ACPI::is_enabled()) {
|
||||
if (!ACPI::Parser::the()->x86_specific_flags().cmos_rtc_not_present) {
|
||||
RTC::initialize();
|
||||
|
@ -117,7 +116,8 @@ TimeManagement::TimeManagement(bool probe_non_legacy_hardware_timers)
|
|||
|
||||
timeval TimeManagement::now_as_timeval()
|
||||
{
|
||||
return { s_time_management->epoch_time(), (suseconds_t)s_time_management->ticks_this_second() * (suseconds_t)1000 };
|
||||
auto* time_management = s_the.ptr();
|
||||
return { time_management->epoch_time(), (suseconds_t)time_management->ticks_this_second() * (suseconds_t)1000 };
|
||||
}
|
||||
|
||||
Vector<HardwareTimer*> TimeManagement::scan_and_initialize_periodic_timers()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue