fix memory leak
This commit is contained in:
@ -95,6 +95,12 @@ private:
|
||||
std::vector<std::shared_ptr<event_type>> events;
|
||||
|
||||
unique_mutex_lock lock(event_mutex_);
|
||||
const auto lock_and_notify = [this, &lock]() {
|
||||
lock.lock();
|
||||
event_notify_.notify_all();
|
||||
lock.unlock();
|
||||
};
|
||||
|
||||
if (not get_stop_requested() && event_list_.empty()) {
|
||||
event_notify_.wait_for(lock, 4s);
|
||||
}
|
||||
@ -107,6 +113,7 @@ private:
|
||||
lock.unlock();
|
||||
|
||||
if (events.empty()) {
|
||||
lock_and_notify();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -133,12 +140,38 @@ private:
|
||||
notify_events("", *evt.get());
|
||||
notify_events(evt->get_name(), *evt.get());
|
||||
}
|
||||
|
||||
lock_and_notify();
|
||||
}
|
||||
|
||||
void queue_event(std::shared_ptr<event_type> evt) {
|
||||
mutex_lock lock(event_mutex_);
|
||||
static constexpr const auto max_retry{
|
||||
30U,
|
||||
};
|
||||
|
||||
static const auto max_size{
|
||||
std::thread::hardware_concurrency() * 4UL,
|
||||
};
|
||||
|
||||
unique_mutex_lock lock(event_mutex_);
|
||||
event_list_.push_back(std::move(evt));
|
||||
auto size = event_list_.size();
|
||||
event_notify_.notify_all();
|
||||
lock.unlock();
|
||||
|
||||
for (auto retry{0U};
|
||||
size > max_size && retry < max_retry && not get_stop_requested();
|
||||
++retry) {
|
||||
lock.lock();
|
||||
size = event_list_.size();
|
||||
if (size > max_size) {
|
||||
event_notify_.wait_for(lock, 1s);
|
||||
size = event_list_.size();
|
||||
}
|
||||
|
||||
event_notify_.notify_all();
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
Reference in New Issue
Block a user