This commit is contained in:
aozhiwei 2024-08-23 15:28:34 +08:00
parent bfde769e98
commit 17166c21d3

View File

@ -22,7 +22,7 @@
class EventHandler : public std::enable_shared_from_this<EventHandler>
{
public:
a8::CommonCbProc cb;
std::shared_ptr<a8::CommonCbProc> cb;
list_head entry;
std::shared_ptr<EventHandler> holder;
@ -497,7 +497,8 @@ std::weak_ptr<EventHandler> Trigger::AddListener(int event_id, a8::CommonCbProc
INIT_LIST_HEAD(&itr->second);
}
auto p = std::make_shared<EventHandler>();
p->cb = cb;
p->cb = std::make_shared<a8::CommonCbProc>();
*p->cb = cb;
list_add_tail(&p->entry, &itr->second);
p->holder = p;
return p;
@ -529,7 +530,8 @@ void Trigger::DispatchEvent(int event_id, const std::vector<std::any>& param)
if (itr != listeners_hash_.end()) {
struct EventHandler *handle = nullptr, *tmp = nullptr;
list_for_each_entry_safe(handle, tmp, &itr->second, entry) {
handle->cb(param);
auto cb = handle->cb;
(*cb)(param);
}
}
}