client: add display_wakeup_threads function

This helper function wraps the always-repeated pattern:

  display->read_serial++;
  pthread_cond_broadcast(&display->reader_cond);

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
display-test: make use of create_thread function

This function is used in one test only, but its functionality can be
used in another tests to (create thread and wait until it is sleeping).
We just need to pass the starting function for the thread as an argument.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
tests: add display test that highlights another bug in read_events

When wl_display_read_events() returns with errno == EAGAIN, we
naturally try to call it again. But this next call results in deadlock.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
test-compositor: let test reach display_destroy

REALLY LIKE THIS? MAYBE TRY
if (all_clients_exited)
    display_destroy()

or similar...

When a all clients exit (with an error) before all of them sent request to stop
display (usually we have one client and one request), display_resume() will fail
on assert. Instead of that, return and let the test to reach
display_destroy so that it will write out the results.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>
client: fix bug with display->reader_count < 0

If we will try call wl_display_read_events() again,
after we got EAGAIN from previous call, we get deadlock
as shown in test. The bug works like this: after first call
to wl_display_read_events() the display->reader_count is 0
and next call will decrease it to -1 so the thread will make
sleeping itself and we have a deadlock.

We have two options here:

Either we can wake up all threads before returning from
read_events() and thus force the programmer to do the whole
prepare+read loop again. Waking up all the threads could bring
unnecessary overhead.

The other solution, that I chose, is to return without waking up
the threads, so that programmer can try read again
- it feels natural after getting EAGAIN. Thus the proper use
of wl_display_read_events should look like:

    do {
        ret = wl_display_read_events(display);
    } while (ret == 0 && errno == EAGAIN);

The solution is simple. Before returning from read_events under
these circumstances, increase the display->reader_count back to 1,
so that next trial will have the same execution path as the one
before.

Signed-off-by: Marek Chalupa <mchqwerty@gmail.com>