mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:07:45 +00:00
LibCore: Guard access to EventLoop notifiers set with a mutex
This fixes a CI flake we've been seeing lately in TestLibCoreStream. The solution itself is somewhat of a stop-gap as there are more thorough event loop threading improvements in the works.
This commit is contained in:
parent
f0b500a062
commit
0631d3fed5
1 changed files with 16 additions and 7 deletions
|
@ -59,6 +59,8 @@ static Vector<EventLoop&>* s_event_loop_stack;
|
||||||
static NeverDestroyed<IDAllocator> s_id_allocator;
|
static NeverDestroyed<IDAllocator> s_id_allocator;
|
||||||
static HashMap<int, NonnullOwnPtr<EventLoopTimer>>* s_timers;
|
static HashMap<int, NonnullOwnPtr<EventLoopTimer>>* s_timers;
|
||||||
static HashTable<Notifier*>* s_notifiers;
|
static HashTable<Notifier*>* s_notifiers;
|
||||||
|
static Threading::Mutex s_notifiers_mutex;
|
||||||
|
|
||||||
int EventLoop::s_wake_pipe_fds[2];
|
int EventLoop::s_wake_pipe_fds[2];
|
||||||
static RefPtr<InspectorServerConnection> s_inspector_server_connection;
|
static RefPtr<InspectorServerConnection> s_inspector_server_connection;
|
||||||
|
|
||||||
|
@ -605,13 +607,17 @@ retry:
|
||||||
int max_fd_added = -1;
|
int max_fd_added = -1;
|
||||||
add_fd_to_set(s_wake_pipe_fds[0], rfds);
|
add_fd_to_set(s_wake_pipe_fds[0], rfds);
|
||||||
max_fd = max(max_fd, max_fd_added);
|
max_fd = max(max_fd, max_fd_added);
|
||||||
for (auto& notifier : *s_notifiers) {
|
|
||||||
if (notifier->event_mask() & Notifier::Read)
|
{
|
||||||
add_fd_to_set(notifier->fd(), rfds);
|
Threading::MutexLocker locker(s_notifiers_mutex);
|
||||||
if (notifier->event_mask() & Notifier::Write)
|
for (auto& notifier : *s_notifiers) {
|
||||||
add_fd_to_set(notifier->fd(), wfds);
|
if (notifier->event_mask() & Notifier::Read)
|
||||||
if (notifier->event_mask() & Notifier::Exceptional)
|
add_fd_to_set(notifier->fd(), rfds);
|
||||||
VERIFY_NOT_REACHED();
|
if (notifier->event_mask() & Notifier::Write)
|
||||||
|
add_fd_to_set(notifier->fd(), wfds);
|
||||||
|
if (notifier->event_mask() & Notifier::Exceptional)
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool queued_events_is_empty;
|
bool queued_events_is_empty;
|
||||||
|
@ -698,6 +704,7 @@ try_select_again:
|
||||||
if (!marked_fd_count)
|
if (!marked_fd_count)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
Threading::MutexLocker locker(s_notifiers_mutex);
|
||||||
for (auto& notifier : *s_notifiers) {
|
for (auto& notifier : *s_notifiers) {
|
||||||
if (FD_ISSET(notifier->fd(), &rfds)) {
|
if (FD_ISSET(notifier->fd(), &rfds)) {
|
||||||
if (notifier->event_mask() & Notifier::Event::Read)
|
if (notifier->event_mask() & Notifier::Event::Read)
|
||||||
|
@ -763,11 +770,13 @@ bool EventLoop::unregister_timer(int timer_id)
|
||||||
|
|
||||||
void EventLoop::register_notifier(Badge<Notifier>, Notifier& notifier)
|
void EventLoop::register_notifier(Badge<Notifier>, Notifier& notifier)
|
||||||
{
|
{
|
||||||
|
Threading::MutexLocker locker(s_notifiers_mutex);
|
||||||
s_notifiers->set(¬ifier);
|
s_notifiers->set(¬ifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EventLoop::unregister_notifier(Badge<Notifier>, Notifier& notifier)
|
void EventLoop::unregister_notifier(Badge<Notifier>, Notifier& notifier)
|
||||||
{
|
{
|
||||||
|
Threading::MutexLocker locker(s_notifiers_mutex);
|
||||||
s_notifiers->remove(¬ifier);
|
s_notifiers->remove(¬ifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue