diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d79d8ec1..edb9e83c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,24 @@ +cmake_minimum_required(VERSION 3.10) set(NAME SonicUtils) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + set(SRCS - ELFLoader.cpp - ELFSymbolDatabase.cpp - LogManager.cpp - VM.cpp) -add_library(${NAME} ${SRCS}) + Source/ELFLoader.cpp + Source/ELFSymbolDatabase.cpp + Source/LogManager.cpp + Source/VM.cpp) + +add_library(${NAME} SHARED ${SRCS}) +target_include_directories(${NAME} PUBLIC include/) + +install(TARGETS ${NAME} + LIBRARY + DESTINATION lib + COMPONENT Libraries) + +install(DIRECTORY include/SonicUtils + DESTINATION include + COMPONENT Development) + diff --git a/Event.h b/Event.h deleted file mode 100644 index 6ec1f0fd1..000000000 --- a/Event.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once -#include -#include -#include - -class Event final { -private: -/** - * @brief Literally just an atomic bool that we are using for this class - */ -class Flag final { -public: - bool TestAndSet(bool SetValue = true) { - bool Expected = !SetValue; - return Value.compare_exchange_strong(Expected, SetValue); - } - - bool TestAndClear() { - return TestAndSet(false); - } - -private: - std::atomic_bool Value {false}; -}; - -public: - ~Event() { - NotifyAll(); - } - void NotifyOne() { - if (FlagObject.TestAndSet()) { - std::lock_guard lk(MutexObject); - CondObject.notify_one(); - } - } - - void NotifyAll() { - if (FlagObject.TestAndSet()) { - std::lock_guard lk(MutexObject); - CondObject.notify_all(); - } - } - - void Wait() { - // Have we signaled before we started waiting? - if (FlagObject.TestAndClear()) - return; - - std::unique_lock lk(MutexObject); - CondObject.wait(lk, [this]{ return FlagObject.TestAndClear(); }); - } - - template - bool WaitFor(std::chrono::duration const& time) { - // Have we signaled before we started waiting? - if (FlagObject.TestAndClear()) - return true; - - std::unique_lock lk(MutexObject); - bool DidSignal = CondObject.wait_for(lk, time, [this]{ return FlagObject.TestAndClear(); }); - return DidSignal; - } - -private: - Flag FlagObject; - std::mutex MutexObject; - std::condition_variable CondObject; -}; diff --git a/ELFLoader.cpp b/Source/ELFLoader.cpp similarity index 99% rename from ELFLoader.cpp rename to Source/ELFLoader.cpp index 2ef607f66..a11963988 100644 --- a/ELFLoader.cpp +++ b/Source/ELFLoader.cpp @@ -1,5 +1,5 @@ -#include "ELFLoader.h" -#include "LogManager.h" +#include +#include #include #include #include diff --git a/ELFSymbolDatabase.cpp b/Source/ELFSymbolDatabase.cpp similarity index 98% rename from ELFSymbolDatabase.cpp rename to Source/ELFSymbolDatabase.cpp index 9e1fd1a64..21e1dfc4e 100644 --- a/ELFSymbolDatabase.cpp +++ b/Source/ELFSymbolDatabase.cpp @@ -1,6 +1,6 @@ -#include "ELFSymbolDatabase.h" -#include "LogManager.h" -#include "Common/MathUtils.h" +#include +#include +#include #include #include diff --git a/LogManager.cpp b/Source/LogManager.cpp similarity index 95% rename from LogManager.cpp rename to Source/LogManager.cpp index 6abbab9d7..d807eecfa 100644 --- a/LogManager.cpp +++ b/Source/LogManager.cpp @@ -1,4 +1,4 @@ -#include "LogManager.h" +#include #include #include diff --git a/VM.cpp b/Source/VM.cpp similarity index 99% rename from VM.cpp rename to Source/VM.cpp index f3e895dc2..af2c82e6f 100644 --- a/VM.cpp +++ b/Source/VM.cpp @@ -1,5 +1,5 @@ -#include "LogManager.h" -#include "VM.h" +#include +#include #include #include diff --git a/include/SonicUtils/Common/MathUtils.h b/include/SonicUtils/Common/MathUtils.h new file mode 100644 index 000000000..8274ad2be --- /dev/null +++ b/include/SonicUtils/Common/MathUtils.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +static inline uint64_t AlignUp(uint64_t value, uint64_t size) { + return value + (size - value % size) % size; +}; + +static inline uint64_t AlignDown(uint64_t value, uint64_t size) { + return value - value % size; +}; + + diff --git a/ELFLoader.h b/include/SonicUtils/ELFLoader.h similarity index 100% rename from ELFLoader.h rename to include/SonicUtils/ELFLoader.h diff --git a/ELFSymbolDatabase.h b/include/SonicUtils/ELFSymbolDatabase.h similarity index 100% rename from ELFSymbolDatabase.h rename to include/SonicUtils/ELFSymbolDatabase.h diff --git a/LogManager.h b/include/SonicUtils/LogManager.h similarity index 100% rename from LogManager.h rename to include/SonicUtils/LogManager.h diff --git a/VM.h b/include/SonicUtils/VM.h similarity index 100% rename from VM.h rename to include/SonicUtils/VM.h