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

[issues/2332]clean code, clean up the warning #2336

Merged
merged 1 commit into from
Apr 21, 2022
Merged

Conversation

aengusjiang
Copy link
Contributor

see the issue: #2332

@gabime
Copy link
Owner

gabime commented Apr 18, 2022

This is template instantiation. Not sure this is the correct fix.

@aengusjiang
Copy link
Contributor Author

I known that, the first instantiation locate in file thread_pool.h:85
Then the async.cpp instant it again.
So it is duplicate instantion, becauce anync.cpp inclde thread_pool.h.

Please check it again.

@gabime
Copy link
Owner

gabime commented Apr 21, 2022

I am no expert on this. Are you sure that

 using q_type = details::mpmc_blocking_queue<item_type>;

is also template instantiation ? The cpp spec doesn't mention this.

@aengusjiang
Copy link
Contributor Author

aengusjiang commented Apr 21, 2022

I sure that will instantiation.

class SPDLOG_API thread_pool
{
public:
    using item_type = async_msg;
    using q_type = details::mpmc_blocking_queue<item_type>;

    thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start, std::function<void()> on_thread_stop);
    thread_pool(size_t q_max_items, size_t threads_n, std::function<void()> on_thread_start);
    thread_pool(size_t q_max_items, size_t threads_n);

    // message all threads to terminate gracefully and join them
    ~thread_pool();

    thread_pool(const thread_pool &) = delete;
    thread_pool &operator=(thread_pool &&) = delete;

    void post_log(async_logger_ptr &&worker_ptr, const details::log_msg &msg, async_overflow_policy overflow_policy);
    void post_flush(async_logger_ptr &&worker_ptr, async_overflow_policy overflow_policy);
    size_t overrun_counter();
    size_t queue_size();

private:
    q_type q_;

    std::vector<std::thread> threads_;

    void post_async_msg_(async_msg &&new_msg, async_overflow_policy overflow_policy);
    void worker_loop_();

    // process next message in the queue
    // return true if this thread should still be active (while no terminate msg
    // was received)
    bool process_next_msg_();
};

First, the syntax of using https://en.cppreference.com/w/cpp/language/type_alias
using identifier attr(optional) = type-id
so the type-id must a definition, not a declaration.

Second, When we define a class, the data member must be have definition, not a declaration.
the alias type q_type is a member of thread_pool. it must a clear type, or the complier can't work.

@gabime gabime merged commit 78fbc69 into gabime:v1.x Apr 21, 2022
@gabime
Copy link
Owner

gabime commented Apr 21, 2022

Thanks @aengusjiang . Merged.

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

Successfully merging this pull request may close these issues.

2 participants