Commit 1291d0c2 authored by yukishiino's avatar yukishiino Committed by Commit bot

linux: Fixes a racy crash by key input at termination.

It seems that it's possible that GDK events happen while we're going
to unregister the GDK event handler, and the code must be thread-safe.
(A gpointer |data| in the old code seems pointing to the deleted object.)

This CL removes use of |data| pointer and makes the code thread-safe
without adding any mutex.

BUG=417210

Review URL: https://codereview.chromium.org/610523002

Cr-Commit-Position: refs/heads/master@{#297112}
parent bd3ad7a6
...@@ -20,7 +20,7 @@ Gtk2EventLoop* Gtk2EventLoop::GetInstance() { ...@@ -20,7 +20,7 @@ Gtk2EventLoop* Gtk2EventLoop::GetInstance() {
} }
Gtk2EventLoop::Gtk2EventLoop() { Gtk2EventLoop::Gtk2EventLoop() {
gdk_event_handler_set(GdkEventTrampoline, this, NULL); gdk_event_handler_set(DispatchGdkEvent, NULL, NULL);
} }
Gtk2EventLoop::~Gtk2EventLoop() { Gtk2EventLoop::~Gtk2EventLoop() {
...@@ -29,12 +29,7 @@ Gtk2EventLoop::~Gtk2EventLoop() { ...@@ -29,12 +29,7 @@ Gtk2EventLoop::~Gtk2EventLoop() {
} }
// static // static
void Gtk2EventLoop::GdkEventTrampoline(GdkEvent* event, gpointer data) { void Gtk2EventLoop::DispatchGdkEvent(GdkEvent* gdk_event, gpointer) {
Gtk2EventLoop* loop = reinterpret_cast<Gtk2EventLoop*>(data);
loop->DispatchGdkEvent(event);
}
void Gtk2EventLoop::DispatchGdkEvent(GdkEvent* gdk_event) {
switch (gdk_event->type) { switch (gdk_event->type) {
case GDK_KEY_PRESS: case GDK_KEY_PRESS:
case GDK_KEY_RELEASE: case GDK_KEY_RELEASE:
...@@ -47,6 +42,7 @@ void Gtk2EventLoop::DispatchGdkEvent(GdkEvent* gdk_event) { ...@@ -47,6 +42,7 @@ void Gtk2EventLoop::DispatchGdkEvent(GdkEvent* gdk_event) {
gtk_main_do_event(gdk_event); gtk_main_do_event(gdk_event);
} }
// static
void Gtk2EventLoop::ProcessGdkEventKey(const GdkEventKey& gdk_event_key) { void Gtk2EventLoop::ProcessGdkEventKey(const GdkEventKey& gdk_event_key) {
// This function translates GdkEventKeys into XKeyEvents and puts them to // This function translates GdkEventKeys into XKeyEvents and puts them to
// the X event queue. // the X event queue.
......
...@@ -25,10 +25,8 @@ class Gtk2EventLoop { ...@@ -25,10 +25,8 @@ class Gtk2EventLoop {
Gtk2EventLoop(); Gtk2EventLoop();
~Gtk2EventLoop(); ~Gtk2EventLoop();
static void GdkEventTrampoline(GdkEvent* event, gpointer data); static void DispatchGdkEvent(GdkEvent* gdk_event, gpointer);
static void ProcessGdkEventKey(const GdkEventKey& gdk_event_key);
void DispatchGdkEvent(GdkEvent* gdk_event);
void ProcessGdkEventKey(const GdkEventKey& gdk_event_key);
DISALLOW_COPY_AND_ASSIGN(Gtk2EventLoop); DISALLOW_COPY_AND_ASSIGN(Gtk2EventLoop);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment