+#undef G_DISABLE_ASSERT
+#undef G_LOG_DOMAIN
+
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
-#include <sys/resource.h>
#include <sys/time.h>
+#include <sys/resource.h>
#include <glib.h>
static int n_iters = 10000;
static GMainLoop *loop;
-void
+static void
io_pipe (GIOChannel **channels)
{
int fds[2];
channels[1] = g_io_channel_unix_new (fds[1]);
}
-gboolean
+static gboolean
read_all (GIOChannel *channel, char *buf, int len)
{
- int bytes_read = 0;
- int count;
+ gsize bytes_read = 0;
+ gsize count;
GIOError err;
while (bytes_read < len)
return TRUE;
}
-gboolean
+static gboolean
write_all (GIOChannel *channel, char *buf, int len)
{
- int bytes_written = 0;
- int count;
+ gsize bytes_written = 0;
+ gsize count;
GIOError err;
while (bytes_written < len)
return TRUE;
}
-void
+static void
run_child (GIOChannel *in_channel, GIOChannel *out_channel)
{
int i;
exit (0);
}
-gboolean
+static gboolean
input_callback (GIOChannel *source,
GIOCondition condition,
gpointer data)
n_active_children--;
if (n_active_children == 0)
- g_main_quit (loop);
+ g_main_loop_quit (loop);
return FALSE;
}
}
-void
-create_child ()
+static void
+create_child (void)
{
int pid;
GIOChannel *in_channels[2];
if (pid > 0) /* Parent */
{
g_io_channel_close (in_channels[0]);
+ g_io_channel_unref (in_channels[0]);
g_io_channel_close (out_channels[1]);
+ g_io_channel_unref (out_channels[1]);
g_io_add_watch (out_channels[0], G_IO_IN | G_IO_HUP,
input_callback, in_channels[1]);
create_child ();
getrusage (RUSAGE_SELF, &old_usage);
- loop = g_main_new (FALSE);
- g_main_run (loop);
+ loop = g_main_loop_new (NULL, FALSE);
+ g_main_loop_run (loop);
getrusage (RUSAGE_SELF, &new_usage);
printf ("Elapsed user: %g\n",
difftimeval (&old_usage.ru_stime, &new_usage.ru_stime)) /
(n_iters * n_children));
+ g_main_loop_unref (loop);
return 0;
}