diff options
author | Simon Ser <simon.ser@intel.com> | 2019-06-05 13:27:37 +0300 |
---|---|---|
committer | Simon Ser <simon.ser@intel.com> | 2019-06-07 13:55:56 +0300 |
commit | 1a34b94f1ce07ac5978fe7893a17e8732d467868 (patch) | |
tree | c79d0de7724920829836bd676f1f683822dfd128 /lib/igt_chamelium.c | |
parent | 8bc590d578e2178c0f372d1762716aa74d1f6f41 (diff) |
lib/igt_chamelium: wait for worker thread to finish
Whenever we change a pipe's resolution, we need to perform a FSM on the
Chamelium: the video receiver will be restarted and the Chamelium device will
send a hotplug event. All of this happens during the XML-RPC call.
To handle the hotplug event, we start a new thread (and execute the XML-RPC
request in the main thread in a blocking fashion). Some state is associated
with the hotplug thread and stored in fsm_monitor_args. We initialize this
state before starting the thread, and perform cleanup after cancelling it.
However pthread_cancel is asynchronous: it merely queues a cancellation request
for the thread. Thus cleaning up after pthread_cancel is racy: the thread might
still be running and using fsm_monitor_args.mon. Since this is shared memory,
this can lead to segmentation faults or strange behaviour.
This commit fixes the race by calling pthread_join before cleaning up the
state. This ensures that either the thread has been successfully cancelled,
either it has terminated.
This is an attempt to fix this bug:
https://bugs.freedesktop.org/show_bug.cgi?id=110730
Signed-off-by: Simon Ser <simon.ser@intel.com>
Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Diffstat (limited to 'lib/igt_chamelium.c')
-rw-r--r-- | lib/igt_chamelium.c | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/lib/igt_chamelium.c b/lib/igt_chamelium.c index 75f03d846..eaf3b5b07 100644 --- a/lib/igt_chamelium.c +++ b/lib/igt_chamelium.c @@ -302,6 +302,7 @@ static xmlrpc_value *__chamelium_rpc_va(struct chamelium *chamelium, if (fsm_port) { pthread_cancel(fsm_thread_id); + pthread_join(fsm_thread_id, NULL); igt_cleanup_hotplug(monitor_args.mon); } |