singleton: Use unique_ptr
This commit is contained in:
parent
7cbe7c762a
commit
f3504b2d25
|
@ -500,7 +500,6 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) {
|
|||
bool rel_isResolved = false;
|
||||
u08 rel_sym_type = 0;
|
||||
std::string rel_name;
|
||||
u08 rel_bind_type = -1; //-1 means it didn't resolve
|
||||
|
||||
switch (type) {
|
||||
case R_X86_64_RELATIVE:
|
||||
|
@ -531,7 +530,6 @@ static void relocate(u32 idx, elf_relocation* rel, Module* m, bool isJmpRel) {
|
|||
}
|
||||
switch (sym_bind) {
|
||||
case STB_GLOBAL:
|
||||
rel_bind_type = STB_GLOBAL;
|
||||
rel_name = namesTlb + sym.st_name;
|
||||
m->linker->Resolve(rel_name, rel_sym_type, m, &symrec);
|
||||
symbol_vitrual_addr = symrec.virtual_address;
|
||||
|
|
|
@ -1,24 +1,21 @@
|
|||
#pragma once
|
||||
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
#include <memory>
|
||||
|
||||
template <class T>
|
||||
class singleton {
|
||||
public:
|
||||
public:
|
||||
static T* instance() {
|
||||
if (!m_instance) {
|
||||
m_instance = static_cast<T*>(std::malloc(sizeof(T)));
|
||||
new (m_instance) T;
|
||||
m_instance = std::make_unique<T>();
|
||||
}
|
||||
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
protected:
|
||||
protected:
|
||||
singleton();
|
||||
~singleton();
|
||||
|
||||
private:
|
||||
static inline T* m_instance = nullptr;
|
||||
};
|
||||
private:
|
||||
static inline std::unique_ptr<T> m_instance{};
|
||||
};
|
||||
|
|
|
@ -54,7 +54,7 @@ int main(int argc, char* argv[]) {
|
|||
const char* const path = argv[1]; // argument 1 is the path of self file to boot
|
||||
|
||||
auto* linker = singleton<Linker>::instance();
|
||||
HLE::Libs::Init_HLE_Libs(linker->getHLESymbols());
|
||||
HLE::Libs::Init_HLE_Libs(&linker->getHLESymbols());
|
||||
auto* module = linker->LoadModule(path); // load main executable
|
||||
std::jthread mainthread(
|
||||
[](std::stop_token stop_token, void*) {
|
||||
|
|
Loading…
Reference in New Issue