[PATCH 1/1] dix: Hold the input_lock() when accessing the miEventQueue through checkForInput
Jeremy Huddleston Sequoia
jeremyhu at apple.com
Mon Sep 19 08:31:48 UTC 2016
==================
WARNING: ThreadSanitizer: data race (pid=4943)
Read of size 4 at 0x00010c4e3854 by thread T8:
#0 WaitForSomething WaitFor.c:237 (X11.bin+0x00010049216c)
#1 Dispatch dispatch.c:413 (X11.bin+0x000100352ed9)
#2 dix_main main.c:287 (X11.bin+0x00010036e894)
#3 server_thread quartzStartup.c:66 (X11.bin+0x000100039e63)
Previous write of size 4 at 0x00010c4e3854 by thread T12 (mutexes: write M856, write M1976):
#0 mieqEnqueue mieq.c:263 (X11.bin+0x000100448d14)
#1 DarwinSendDDXEvent darwinEvents.c:641 (X11.bin+0x000100033613)
#2 DarwinProcessFDAdditionQueue_thread darwinEvents.c:338 (X11.bin+0x000100032039)
Location is global 'miEventQueue' at 0x00010c4e3850 (X11.bin+0x0001005ab854)
Mutex M856 (0x00010c4c8c80) created at:
#0 pthread_mutex_lock <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x0000000321fe)
#1 DarwinListenOnOpenFD darwinEvents.c:300 (X11.bin+0x000100031607)
#2 socket_handoff bundle-main.c:288 (X11.bin+0x000100002b40)
#3 __do_request_fd_handoff_socket_block_invoke bundle-main.c:379 (X11.bin+0x0001000029ba)
#4 __tsan::invoke_and_release_block(void*) <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x00000005d97b)
#5 _dispatch_client_callout <null>:33 (libdispatch.dylib+0x0000000020ef)
Mutex M1976 (0x00010c4e3d68) created at:
#0 pthread_mutex_init <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x0000000253c3)
#1 input_lock inputthread.c:103 (X11.bin+0x00010049fd10)
#2 TimerSet WaitFor.c:343 (X11.bin+0x0001004926c2)
#3 RootlessQueueRedisplay rootlessScreen.c:594 (X11.bin+0x000100065d7f)
#4 RootlessInstallColormap rootlessScreen.c:514 (X11.bin+0x000100069f1a)
#5 miSpriteInstallColormap misprite.c:562 (X11.bin+0x000100467095)
#6 miCreateDefColormap micmap.c:270 (X11.bin+0x000100440399)
#7 DarwinScreenInit darwin.c:285 (X11.bin+0x0001000303bb)
#8 AddScreen dispatch.c:3908 (X11.bin+0x00010036c417)
#9 InitOutput darwin.c:671 (X11.bin+0x00010002fdeb)
#10 dix_main main.c:197 (X11.bin+0x00010036e228)
#11 server_thread quartzStartup.c:66 (X11.bin+0x000100039e63)
Thread T8 (tid=4198779, running) created by main thread at:
#0 pthread_create <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x000000024490)
#1 create_thread quartzStartup.c:78 (X11.bin+0x000100039dad)
#2 QuartzInitServer quartzStartup.c:95 (X11.bin+0x000100039c16)
#3 X11ApplicationMain X11Application.m:1238 (X11.bin+0x00010001cde4)
#4 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a642)
#5 server_main quartzStartup.c:136 (X11.bin+0x00010003a03b)
#6 do_start_x11_server bundle-main.c:436 (X11.bin+0x000100002eb5)
#7 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x000100004e99)
#8 mach_startup_server mach_startupServer.c:399 (X11.bin+0x000100005734)
#9 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
#10 start <null>:29 (libdyld.dylib+0x000000005254)
Thread T12 (tid=4198797, running) created by thread T8 at:
#0 pthread_create <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x000000024490)
#1 create_thread darwinEvents.c:121 (X11.bin+0x000100031ecf)
#2 DarwinEQInit darwinEvents.c:365 (X11.bin+0x000100031860)
#3 InitInput darwin.c:571 (X11.bin+0x00010002ea09)
#4 dix_main main.c:261 (X11.bin+0x00010036e7ce)
#5 server_thread quartzStartup.c:66 (X11.bin+0x000100039e63)
SUMMARY: ThreadSanitizer: data race WaitFor.c:237 in WaitForSomething
==================
==================
WARNING: ThreadSanitizer: data race (pid=22841)
Write of size 4 at 0x000105bbd864 by main thread (mutexes: write M1945):
#0 mieqEnqueue mieq.c:263 (X11.bin+0x000100448cf4)
#1 DarwinSendDDXEvent darwinEvents.c:642 (X11.bin+0x000100033693)
#2 -[X11Controller set_window_menu:] X11Controller.m:275 (X11.bin+0x0001000222fd)
#3 -[X11Application set_window_menu:] X11Application.m:486 (X11.bin+0x000100018b44)
#4 -[X11Application handleMachMessage:] X11Application.m:177 (X11.bin+0x000100016678)
#5 __NSFireMachPort <null>:69 (Foundation+0x00000009b62b)
#6 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a5f2)
#7 server_main quartzStartup.c:136 (X11.bin+0x000100039ffb)
#8 do_start_x11_server bundle-main.c:436 (X11.bin+0x000100002e65)
#9 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x000100004e49)
#10 mach_startup_server mach_startupServer.c:399 (X11.bin+0x0001000056e4)
#11 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
#12 start <null>:29 (libdyld.dylib+0x000000005254)
Previous read of size 4 at 0x000105bbd864 by thread T7:
#0 Dispatch dispatch.c:434 (X11.bin+0x000100352fc8)
#1 dix_main main.c:287 (X11.bin+0x00010036e874)
#2 server_thread quartzStartup.c:66 (X11.bin+0x000100039e23)
Location is global 'miEventQueue' at 0x000105bbd860 (X11.bin+0x0001005ab864)
Mutex M1945 (0x000105bbdd78) created at:
#0 pthread_mutex_init <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x0000000253c3)
#1 input_lock inputthread.c:103 (X11.bin+0x00010049fd10)
#2 TimerSet WaitFor.c:348 (X11.bin+0x0001004926c2)
#3 RootlessQueueRedisplay rootlessScreen.c:594 (X11.bin+0x000100065d3f)
#4 RootlessInstallColormap rootlessScreen.c:514 (X11.bin+0x000100069eda)
#5 miSpriteInstallColormap misprite.c:562 (X11.bin+0x000100467075)
#6 miCreateDefColormap micmap.c:270 (X11.bin+0x000100440379)
#7 DarwinScreenInit darwin.c:285 (X11.bin+0x00010003036b)
#8 AddScreen dispatch.c:3914 (X11.bin+0x00010036c3f7)
#9 InitOutput darwin.c:671 (X11.bin+0x00010002fd9b)
#10 dix_main main.c:197 (X11.bin+0x00010036e208)
#11 server_thread quartzStartup.c:66 (X11.bin+0x000100039e23)
Thread T7 (tid=4257217, running) created by main thread at:
#0 pthread_create <null>:144 (libclang_rt.tsan_osx_dynamic.dylib+0x000000024490)
#1 create_thread quartzStartup.c:78 (X11.bin+0x000100039d6d)
#2 QuartzInitServer quartzStartup.c:95 (X11.bin+0x000100039bd6)
#3 X11ApplicationMain X11Application.m:1238 (X11.bin+0x00010001cd94)
#4 X11ControllerMain X11Controller.m:984 (X11.bin+0x00010002a5f2)
#5 server_main quartzStartup.c:136 (X11.bin+0x000100039ffb)
#6 do_start_x11_server bundle-main.c:436 (X11.bin+0x000100002e65)
#7 _Xstart_x11_server mach_startupServer.c:189 (X11.bin+0x000100004e49)
#8 mach_startup_server mach_startupServer.c:399 (X11.bin+0x0001000056e4)
#9 mach_msg_server mach_msg.c:563 (libsystem_kernel.dylib+0x000000012186)
#10 start <null>:29 (libdyld.dylib+0x000000005254)
SUMMARY: ThreadSanitizer: data race mieq.c:263 in mieqEnqueue
==================
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu at apple.com>
---
dix/dispatch.c | 21 ++++++++++++++++++---
os/WaitFor.c | 7 ++++++-
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/dix/dispatch.c b/dix/dispatch.c
index 26a461b..dbf7f97 100644
--- a/dix/dispatch.c
+++ b/dix/dispatch.c
@@ -186,6 +186,7 @@ SetInputCheck(HWEventQueuePtr c0, HWEventQueuePtr c1)
void
UpdateCurrentTime(void)
{
+ Bool input_pending;
TimeStamp systime;
/* To avoid time running backwards, we must call GetTimeInMillis before
@@ -195,7 +196,12 @@ UpdateCurrentTime(void)
systime.milliseconds = GetTimeInMillis();
if (systime.milliseconds < currentTime.milliseconds)
systime.months++;
- if (*checkForInput[0] != *checkForInput[1])
+
+ input_lock();
+ input_pending = (*checkForInput[0] != *checkForInput[1]);
+ input_unlock();
+
+ if (input_pending)
ProcessInputEvents();
if (CompareTimeStamps(systime, currentTime) == LATER)
currentTime = systime;
@@ -397,6 +403,7 @@ Dispatch(void)
ClientPtr client;
HWEventQueuePtr *icheck = checkForInput;
long start_tick;
+ Bool input_pending;
nextFreeClientID = 1;
nClients = 0;
@@ -405,7 +412,11 @@ Dispatch(void)
init_client_ready();
while (!dispatchException) {
- if (*icheck[0] != *icheck[1]) {
+ input_lock();
+ input_pending = (*icheck[0] != *icheck[1]);
+ input_unlock();
+
+ if (input_pending) {
ProcessInputEvents();
FlushIfCriticalOutputPending();
}
@@ -425,7 +436,11 @@ Dispatch(void)
start_tick = SmartScheduleTime;
while (!isItTimeToYield) {
- if (*icheck[0] != *icheck[1])
+ input_lock();
+ input_pending = (*icheck[0] != *icheck[1]);
+ input_unlock();
+
+ if (input_pending)
ProcessInputEvents();
FlushIfCriticalOutputPending();
diff --git a/os/WaitFor.c b/os/WaitFor.c
index cde2c8c..a559ec3 100644
--- a/os/WaitFor.c
+++ b/os/WaitFor.c
@@ -186,6 +186,7 @@ WaitForSomething(Bool are_ready)
int pollerr;
static Bool were_ready;
Bool timer_is_running;
+ Bool input_pending;
timer_is_running = were_ready;
@@ -234,7 +235,11 @@ WaitForSomething(Bool are_ready)
} else
are_ready = clients_are_ready();
- if (*checkForInput[0] != *checkForInput[1])
+ input_lock();
+ input_pending = (*checkForInput[0] != *checkForInput[1]);
+ input_unlock();
+
+ if (input_pending)
return FALSE;
if (are_ready) {
--
2.10.0 (Apple Git-77)
More information about the xorg-devel
mailing list