client: Remove struct wl_thread_data 99/288699/9
authorSeunghun Lee <shiin.lee@samsung.com>
Mon, 13 Feb 2023 23:27:51 +0000 (08:27 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Wed, 22 Feb 2023 05:26:25 +0000 (14:26 +0900)
commit6e303ecd5c604b4dc1d09c5123adc3465e581079
treec7b20e667e573cc41a9cc96b80fe597c1a0309aa
parent1aa8f8ee919160f33da7248ea7ebd6cba571d930
client: Remove struct wl_thread_data

The wl_thread_data was introduced to prevent deadlock as explained by
the following commit message.

Since the problem described by the commit message seems to have
disappeared, let's remove it and observe the results.
If we decided to keep this code, we will need to add a reference count
mechanism or something to prevent use after free and memory leaks. I
believe this code will only add complexity and increase the likelihood
of errors.

Wayland specification says clearly that if a thread successfully calls
wl_display_prepare_read_queue(), it must either call
wl_display_read_events() when it's ready or cancel the read intention by
calling wl_display_cancel_read().

So even if a deadlock occur again around this APIs, I believe we should
still handle it as the application's responsibility.

commit 409d548f6d3b43b8a4991619c3effeeed809f789
Author: Boram Park <boram1288.park@samsung.com>
Date:   Fri Apr 8 08:14:42 2016 +0900

    client: use the thread reader_count to fix deadlock.

        Let's see the below scenario.

          1. A thread polls several fds including the wayland's fd.
          2. This thread probably calls wl_display_prepare_read()
             before polling fds.
          3. This thread could be awake by other event source which
             isn't related with wayland fd.
          4. After wake up, this thread could call wl_display_dispatch
             or wl_display_roundtrip for sync operation.

        Then, when this thread got a done event. this thread will fall
        in deadlock because this thread increases +2 reader_count in the
        sam thread. The read_event or cancel_read for the first
        prepare_read is not going to happen because this thread sleeps
        in pthread_cond_wait() line of read_event.

        This problem can be solved by using the reader_count per thread.

        The reader_count of thread will be increased/decreased whenever
        prepare_read, cancel_read and read_event are called.

        However, the original reader_count of display will be increased
        only once per thread. And, when cancel_read and read_event are
        called, it will be decreased to read event from fd and wake up
        other threads. And that, if the thread reader_count is still
        more than 0, it will be increased because it means the thread
        is still polling in somewhere.

    Change-Id: I2e881a6222e5ad380ace7a6d9571d5463cf701d9

Change-Id: Id77a4468fafaafe0fa79fbe186767adb8b09cde1
src/wayland-client.c