Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timer_queue initialization order causes compilation failure #165

Open
samiralavi opened this issue May 16, 2024 · 0 comments
Open

timer_queue initialization order causes compilation failure #165

samiralavi opened this issue May 16, 2024 · 0 comments

Comments

@samiralavi
Copy link

I was trying to build the library with GCC compiler that comes with ESP IDF SDK for xtensa architecture. Apart from the install section of the CMakeLists.txt that causes issues, the compiler complains about the initialised order of timer_queue class member variables in the constructor initialiser list. Looking at the source code, the error makes sense:

timer_queue::timer_queue(milliseconds max_waiting_time,
                         const std::function<void(std::string_view thread_name)>& thread_started_callback,
                         const std::function<void(std::string_view thread_name)>& thread_terminated_callback) :
    m_thread_started_callback(thread_started_callback),
    m_thread_terminated_callback(thread_terminated_callback), m_atomic_abort(false), m_abort(false), m_idle(true),
    m_max_waiting_time(max_waiting_time) {}

as m_thread_started_callback and m_thread_terminated_callback are initialised first but they are declared last:

    class CRCPP_API timer_queue : public std::enable_shared_from_this<timer_queue> {
...
       private:
        std::atomic_bool m_atomic_abort;
        std::mutex m_lock;
        request_queue m_request_queue;
        details::thread m_worker;
        std::condition_variable m_condition;
        bool m_abort;
        bool m_idle;
        const std::chrono::milliseconds m_max_waiting_time;
        const std::function<void(std::string_view thread_name)> m_thread_started_callback;
        const std::function<void(std::string_view thread_name)> m_thread_terminated_callback;
...

The good news is after fixing the order everything else worked fine (so far). I am wondering how the tests are passed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant