diff --git a/.gitmodules b/.gitmodules index 1979edb..c8c3286 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "external/color"] path = external/color url = git@github.com:Sani7/cpp_color_lib.git +[submodule "external/timer"] + path = external/timer + url = git@github.com:Sani7/cpp_timer.git diff --git a/external/timer b/external/timer new file mode 160000 index 0000000..2e0cd5f --- /dev/null +++ b/external/timer @@ -0,0 +1 @@ +Subproject commit 2e0cd5f6515cba0b778d8fa6e5331c5bfb4a9a0b diff --git a/external/timer/CMakeLists.txt b/external/timer/CMakeLists.txt deleted file mode 100644 index 77ab34a..0000000 --- a/external/timer/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -add_library(Timer STATIC) - -target_compile_options(Timer PRIVATE $<$: - -Wall -Wextra -pedantic-errors -Wconversion -Wsign-conversion - >) - -target_sources(Timer - PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/timer.cpp - -) - -target_include_directories(Timer - PUBLIC - ${CMAKE_CURRENT_LIST_DIR} -) \ No newline at end of file diff --git a/external/timer/timer.cpp b/external/timer/timer.cpp deleted file mode 100644 index f38d10f..0000000 --- a/external/timer/timer.cpp +++ /dev/null @@ -1,34 +0,0 @@ -#include "timer.hpp" - -Timer::Timer(void (*function)()) { - this->function = function; -} - -void Timer::setTimeout(std::chrono::milliseconds delay) { - - this->p_clear = false; - std::thread t([this, delay]() { - if(this->p_clear) return; - std::this_thread::sleep_for(delay); - if(this->p_clear) return; - function(); - }); - t.detach(); -} - -void Timer::setInterval(std::chrono::milliseconds interval) { - this->p_clear = false; - std::thread t([this, interval]() { - while(true) { - if(this->p_clear) return; - std::this_thread::sleep_for(interval); - if(this->p_clear) return; - function(); - } - }); - t.detach(); -} - -void Timer::stop() { - this->p_clear = true; -} \ No newline at end of file diff --git a/external/timer/timer.hpp b/external/timer/timer.hpp deleted file mode 100644 index 7c44605..0000000 --- a/external/timer/timer.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include -#include - -class Timer { -public: - Timer(void (*function)()); - void setTimeout(std::chrono::milliseconds delay); - void setInterval(std::chrono::milliseconds interval); - void stop(); -private: - bool p_clear = false; - std::mutex p_clear_mutex; - void (*function)(); -}; \ No newline at end of file