mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
LibCore: Handle destroyed owner when unregistering timers and notifiers
Cherry-picked from 9f4f319277
This commit is contained in:
parent
944dbfdc97
commit
3214f2c5bf
Notes:
sideshowbarker
2024-07-17 07:19:27 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/LadybirdBrowser/ladybird/commit/3214f2c5bf Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/300
1 changed files with 10 additions and 4 deletions
|
@ -244,10 +244,10 @@ struct ThreadData {
|
|||
return *data;
|
||||
}
|
||||
|
||||
static ThreadData& for_thread(pthread_t thread_id)
|
||||
static ThreadData* for_thread(pthread_t thread_id)
|
||||
{
|
||||
pthread_rwlock_rdlock(&*s_thread_data_lock);
|
||||
auto& result = *s_thread_data.get(thread_id).value();
|
||||
auto result = s_thread_data.get(thread_id).value_or(nullptr);
|
||||
pthread_rwlock_unlock(&*s_thread_data_lock);
|
||||
return result;
|
||||
}
|
||||
|
@ -656,7 +656,10 @@ intptr_t EventLoopManagerUnix::register_timer(EventReceiver& object, int millise
|
|||
void EventLoopManagerUnix::unregister_timer(intptr_t timer_id)
|
||||
{
|
||||
auto* timer = bit_cast<EventLoopTimer*>(timer_id);
|
||||
auto& thread_data = ThreadData::for_thread(timer->owner_thread);
|
||||
auto thread_data_ptr = ThreadData::for_thread(timer->owner_thread);
|
||||
if (!thread_data_ptr)
|
||||
return;
|
||||
auto& thread_data = *thread_data_ptr;
|
||||
auto expected = false;
|
||||
if (timer->is_being_deleted.compare_exchange_strong(expected, true, AK::MemoryOrder::memory_order_acq_rel)) {
|
||||
if (timer->is_scheduled())
|
||||
|
@ -682,8 +685,11 @@ void EventLoopManagerUnix::register_notifier(Notifier& notifier)
|
|||
|
||||
void EventLoopManagerUnix::unregister_notifier(Notifier& notifier)
|
||||
{
|
||||
auto& thread_data = ThreadData::for_thread(notifier.owner_thread());
|
||||
auto thread_data_ptr = ThreadData::for_thread(notifier.owner_thread());
|
||||
if (!thread_data_ptr)
|
||||
return;
|
||||
|
||||
auto& thread_data = *thread_data_ptr;
|
||||
auto it = thread_data.notifier_by_ptr.find(¬ifier);
|
||||
VERIFY(it != thread_data.notifier_by_ptr.end());
|
||||
|
||||
|
|
Loading…
Reference in a new issue