Skip to content

File thread.hpp

File List > atlas > thread_utils > thread.hpp

Go to the documentation of this file

#pragma once
#include <core/engine_logger.hpp>
#include <thread>

namespace atlas {
    class thread {
    public:
        thread() = delete;
        thread(const std::string& p_tag = "Undefined")
          : m_tag(p_tag) {}

        ~thread() {
            console_log_info("Are you destructed!");
            if (this->Joinable()) {
                this->Join();
            }
        }

        template<typename T, typename... Args>
        void dispatch(T&& func, Args&&... args) {
            m_thread = std::thread(func, std::forward<Args>(args)...);
        }

        bool Joinable() { return m_thread.joinable(); }

        void Join() { m_thread.join(); }

    private:
        std::string m_tag;
        std::thread m_thread;
    };
};