diff --git a/premake5.lua b/premake5.lua index d21fb5f..e578481 100644 --- a/premake5.lua +++ b/premake5.lua @@ -21,9 +21,9 @@ project "bakatools" "%{prj.location}/src/bakatoolspch.h", "%{prj.location}/src/bakatoolspch.cpp", } - + filter "system:windows" - buildoptions "/MT" + buildoptions { "/MT", "/utf-8" } defines { "BK_PLATFORM_WINDOWS" diff --git a/src/bakatools/file_system/dir_entry.cpp b/src/bakatools/file_system/dir_entry.cpp index ab43a85..3edb654 100644 --- a/src/bakatools/file_system/dir_entry.cpp +++ b/src/bakatools/file_system/dir_entry.cpp @@ -1,5 +1,7 @@ #include "dir_entry.h" -#include +#ifdef BK_PLATFORM_LINUX + #include +#endif #include namespace Bk @@ -29,7 +31,7 @@ namespace Bk return ent.file_size(); } - std::chrono::time_point DirEntry::last_write() + std::filesystem::file_time_type DirEntry::last_write() { return ent.last_write_time(); } diff --git a/src/bakatools/file_system/dir_entry.h b/src/bakatools/file_system/dir_entry.h index dc4a211..9cead62 100644 --- a/src/bakatools/file_system/dir_entry.h +++ b/src/bakatools/file_system/dir_entry.h @@ -2,7 +2,6 @@ #include #include "bakatools/container/types.h" -#include #include namespace Bk @@ -35,7 +34,7 @@ namespace Bk std::string name(); u64 size(); - std::chrono::time_point last_write(); + std::filesystem::file_time_type last_write(); bool exists(); FilePerms perms(); uintmax_t hard_links(); diff --git a/src/bakatools/thread/task_pool.h b/src/bakatools/thread/task_pool.h new file mode 100644 index 0000000..785e9d4 --- /dev/null +++ b/src/bakatools/thread/task_pool.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace Bk +{ + class ThreadPool + { + public: + ThreadPool(size_t num_threads + = std::thread::hardware_concurrency()) + { + + for (size_t i = 0; i < num_threads; ++i) { + threads_.emplace_back([this] { + while (true) { + std::function task; + { + std::unique_lock lock(queue_mutex_); + cv_.wait(lock, [this] { + return !tasks_.empty() || stop_; + }); + + if (stop_ && tasks_.empty()) { + return; + } + + task = std::move(tasks_.front()); + tasks_.pop(); + } + task(); + } + }); + } + } + + ~ThreadPool() + { + { + std::unique_lock lock(queue_mutex_); + stop_ = true; + } + + cv_.notify_all(); + + for (auto& thread : threads_) { + thread.join(); + } + } + + void queue(std::function task) + { + { + std::unique_lock lock(queue_mutex_); + tasks_.emplace(std::move(task)); + } + cv_.notify_one(); + } + + void stop() + { + std::unique_lock lock(queue_mutex_); + stop_ = true; + } + + private: + std::vector threads_; + std::queue > tasks_; + + std::mutex queue_mutex_; + std::condition_variable cv_; + + bool stop_ = false; + }; +} \ No newline at end of file diff --git a/src/bakatoolspch.h b/src/bakatoolspch.h index b3cb28a..10c5541 100644 --- a/src/bakatoolspch.h +++ b/src/bakatoolspch.h @@ -20,5 +20,5 @@ #include #include -#include -#include \ No newline at end of file +#include "bakatools/base.h" +#include "bakatools/logging/log.h" \ No newline at end of file