mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-21 22:59:16 +02:00
Merge branch 'gwakeup-cleanups' into 'main'
gwakeuptest: Do not rely on alarm() to stop tests on timeout See merge request GNOME/glib!3108
This commit is contained in:
commit
2ca08bde4f
@ -206,10 +206,20 @@ g_wakeup_get_pollfd (GWakeup *wakeup,
|
|||||||
void
|
void
|
||||||
g_wakeup_acknowledge (GWakeup *wakeup)
|
g_wakeup_acknowledge (GWakeup *wakeup)
|
||||||
{
|
{
|
||||||
char buffer[16];
|
|
||||||
|
|
||||||
/* read until it is empty */
|
/* read until it is empty */
|
||||||
while (read (wakeup->fds[0], buffer, sizeof buffer) == sizeof buffer);
|
|
||||||
|
if (wakeup->fds[1] == -1)
|
||||||
|
{
|
||||||
|
uint64_t value;
|
||||||
|
|
||||||
|
while (read (wakeup->fds[0], &value, sizeof (value)) == sizeof (value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uint8_t value;
|
||||||
|
|
||||||
|
while (read (wakeup->fds[0], &value, sizeof (value)) == sizeof (value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -233,7 +243,7 @@ g_wakeup_signal (GWakeup *wakeup)
|
|||||||
|
|
||||||
if (wakeup->fds[1] == -1)
|
if (wakeup->fds[1] == -1)
|
||||||
{
|
{
|
||||||
guint64 one = 1;
|
uint64_t one = 1;
|
||||||
|
|
||||||
/* eventfd() case. It requires a 64-bit counter increment value to be
|
/* eventfd() case. It requires a 64-bit counter increment value to be
|
||||||
* written. */
|
* written. */
|
||||||
@ -243,7 +253,7 @@ g_wakeup_signal (GWakeup *wakeup)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
guint8 one = 1;
|
uint8_t one = 1;
|
||||||
|
|
||||||
/* Non-eventfd() case. Only a single byte needs to be written, and it can
|
/* Non-eventfd() case. Only a single byte needs to be written, and it can
|
||||||
* have an arbitrary value. */
|
* have an arbitrary value. */
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gwakeup.h>
|
#include <glib/gwakeup.h>
|
||||||
#ifdef G_OS_UNIX
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
static void alarm (int sec) { }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
check_signaled (GWakeup *wakeup)
|
check_signaled (GWakeup *wakeup)
|
||||||
@ -32,9 +25,6 @@ test_semantics (void)
|
|||||||
GWakeup *wakeup;
|
GWakeup *wakeup;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
/* prevent the test from deadlocking */
|
|
||||||
alarm (60);
|
|
||||||
|
|
||||||
wakeup = g_wakeup_new ();
|
wakeup = g_wakeup_new ();
|
||||||
g_assert (!check_signaled (wakeup));
|
g_assert (!check_signaled (wakeup));
|
||||||
|
|
||||||
@ -66,9 +56,6 @@ test_semantics (void)
|
|||||||
g_assert (!check_signaled (wakeup));
|
g_assert (!check_signaled (wakeup));
|
||||||
|
|
||||||
g_wakeup_free (wakeup);
|
g_wakeup_free (wakeup);
|
||||||
|
|
||||||
/* cancel the alarm */
|
|
||||||
alarm (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct token
|
struct token
|
||||||
@ -213,9 +200,6 @@ test_threaded (void)
|
|||||||
{
|
{
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
/* make sure we don't block forever */
|
|
||||||
alarm (60);
|
|
||||||
|
|
||||||
/* simple mainloop test based on GWakeup.
|
/* simple mainloop test based on GWakeup.
|
||||||
*
|
*
|
||||||
* create a bunch of contexts and a thread to 'run' each one. create
|
* create a bunch of contexts and a thread to 'run' each one. create
|
||||||
@ -252,9 +236,6 @@ test_threaded (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_wakeup_free (last_token_wakeup);
|
g_wakeup_free (last_token_wakeup);
|
||||||
|
|
||||||
/* cancel alarm */
|
|
||||||
alarm (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user