summaryrefslogtreecommitdiffstats
path: root/tests/client-server.c
diff options
context:
space:
mode:
authorJulian Bouzas <julian.bouzas@collabora.com>2021-06-25 22:55:44 -0400
committerGeorge Kiagiadakis <george.kiagiadakis@collabora.com>2021-07-28 13:19:02 +0300
commit3fc57c841ff9bdae445b086755024b2fa2630808 (patch)
treec74f61639085ed9359a73fa76067f9c40cf00261 /tests/client-server.c
parent9948c10fc6594ce1076550a32067a17dd463eb84 (diff)
tests: wpipc: use GCond instead of while loop to wait for events
Fixes hanging issues when running test with valgrind. Signed-off-by: George Kiagiadakis <george.kiagiadakis@collabora.com>
Diffstat (limited to 'tests/client-server.c')
-rw-r--r--tests/client-server.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/tests/client-server.c b/tests/client-server.c
index 241804c..24f8cc1 100644
--- a/tests/client-server.c
+++ b/tests/client-server.c
@@ -36,19 +36,16 @@ struct reply_data {
const char *error;
int n_replies;
GMutex mutex;
+ GCond cond;
};
static void
wait_for_reply (struct reply_data *data, int n_replies)
{
- while (true) {
- g_mutex_lock (&data->mutex);
- if (data->n_replies == n_replies) {
- g_mutex_unlock (&data->mutex);
- break;
- }
- g_mutex_unlock (&data->mutex);
- }
+ g_mutex_lock (&data->mutex);
+ while (data->n_replies < n_replies)
+ g_cond_wait (&data->cond, &data->mutex);
+ g_mutex_unlock (&data->mutex);
}
static void
@@ -65,6 +62,7 @@ reply_handler (struct icipc_sender *self, const uint8_t *buffer, size_t size, vo
g_assert_true (spa_pod_get_int (pod, &data->incremented) == 0);
}
data->n_replies++;
+ g_cond_signal (&data->cond);
g_mutex_unlock (&data->mutex);
}
@@ -78,6 +76,7 @@ test_icipc_server_client ()
g_assert_nonnull (c);
struct reply_data data;
g_mutex_init (&data.mutex);
+ g_cond_init (&data.cond);
/* add request handlers */
g_assert_true (icipc_server_set_request_handler (s, "INCREMENT", increment_request_handler, NULL));
@@ -108,6 +107,7 @@ test_icipc_server_client ()
g_assert_cmpstr (data.error, ==, "request handler not found");
/* clean up */
+ g_cond_clear (&data.cond);
g_mutex_clear (&data.mutex);
icipc_client_free (c);
icipc_server_free (s);