[GNOME VFS] patch for cancellation's 'fd' consumption,
Michael Meeks <[email protected]> 12 Jul 2002 13:02:16 +0100
| Newsgroups | gmane.comp.gnome.vfs |
|---|---|
| Message-ID | <[email protected]> |
May I commit to stable and HEAD ? we should also enable this regression test by default to run at 'make check' time IMHO, the more of those the better - and the less likely for bit-rot to set in. Regards, Michael. Index: ChangeLog =================================================================== RCS file: /cvs/gnome/gnome-vfs/ChangeLog,v retrieving revision 1.1334.2.14 diff -u -p -u -r1.1334.2.14 ChangeLog --- ChangeLog 12 Jul 2002 08:07:54 -0000 1.1334.2.14 +++ ChangeLog 12 Jul 2002 11:57:08 -0000 @@ -1,3 +1,28 @@ +2002-07-12 Michael Meeks <[email protected]> + + * libgnomevfs/gnome-vfs-cancellation.c + (gnome_vfs_cancellation_cancel), + (gnome_vfs_cancellation_ack): only write if we have a pipe. + (gnome_vfs_cancellation_get_fd): idly create the pipes, + return -1 on error. + (gnome_vfs_cancellation_new): init the pipe fds to -1 + + * libgnomevfs/gnome-vfs-init.c (gnome_vfs_init): + move pthread_init up the order. If we don't do this + we create a default main context, without the + 'wake_up_pipe' initialized, which means that anyone + doing a plain gnome-init has a '0' wake_up_pipe by + the time they need to write / read to it. This means + you see an 'A' on the console and have to hit enter + before getting any async callbacks. + + * libgnomevfs/gnome-vfs-job.h (JOB_DEBUG_PRINT): + make more standard. + + * test/test-async.c (async_queue_callback): impl. + (main): hammer the async queue to test efficiency. + re-hash lots of this. + 2002-07-11 Michael Meeks <[email protected]> * libgnomevfs/gnome-vfs-mime-info.c Index: libgnomevfs/gnome-vfs-cancellation.c =================================================================== RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-cancellation.c,v retrieving revision 1.12 diff -u -p -u -r1.12 gnome-vfs-cancellation.c --- libgnomevfs/gnome-vfs-cancellation.c 3 Aug 2001 19:03:19 -0000 1.12 +++ libgnomevfs/gnome-vfs-cancellation.c 12 Jul 2002 11:57:09 -0000 @@ -53,15 +53,11 @@ GnomeVFSCancellation * gnome_vfs_cancellation_new (void) { GnomeVFSCancellation *new; - gint pipefd[2]; - - if (pipe (pipefd) == -1) - return NULL; new = g_new (GnomeVFSCancellation, 1); new->cancelled = FALSE; - new->pipe_in = pipefd[0]; - new->pipe_out = pipefd[1]; + new->pipe_in = -1; + new->pipe_out = -1; return new; } @@ -77,8 +73,10 @@ gnome_vfs_cancellation_destroy (GnomeVFS { g_return_if_fail (cancellation != NULL); - close (cancellation->pipe_in); - close (cancellation->pipe_out); + if (cancellation->pipe_in >= 0) { + close (cancellation->pipe_in); + close (cancellation->pipe_out); + } g_free (cancellation); } @@ -98,7 +96,9 @@ gnome_vfs_cancellation_cancel (GnomeVFSC if (cancellation->cancelled) return; - write (cancellation->pipe_out, "c", 1); + if (cancellation->pipe_out >= 0) + write (cancellation->pipe_out, "c", 1); + cancellation->cancelled = TRUE; } @@ -136,7 +136,9 @@ gnome_vfs_cancellation_ack (GnomeVFSCanc if (cancellation == NULL) return; - read (cancellation->pipe_in, &c, 1); + if (cancellation->pipe_in >= 0) + read (cancellation->pipe_in, &c, 1); + cancellation->cancelled = FALSE; } @@ -154,12 +156,23 @@ gnome_vfs_cancellation_ack (GnomeVFSCanc * same time. If a data is available on the notificator's file descriptor, you * know you have to cancel the read/write operation. * - * Return value: the notificator's file descriptor. + * Return value: the notificator's file descriptor, or -1 if starved of + * file descriptors. **/ gint gnome_vfs_cancellation_get_fd (GnomeVFSCancellation *cancellation) { g_return_val_if_fail (cancellation != NULL, -1); + + if (cancellation->pipe_in <= 0) { + gint pipefd [2]; + + if (pipe (pipefd) == -1) + return -1; + + cancellation->pipe_in = pipefd [0]; + cancellation->pipe_out = pipefd [1]; + } return cancellation->pipe_in; } Index: libgnomevfs/gnome-vfs-init.c =================================================================== RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-init.c,v retrieving revision 1.22.2.1 diff -u -p -u -r1.22.2.1 gnome-vfs-init.c --- libgnomevfs/gnome-vfs-init.c 14 Jun 2002 01:13:55 -0000 1.22.2.1 +++ libgnomevfs/gnome-vfs-init.c 12 Jul 2002 11:57:09 -0000 @@ -85,21 +85,22 @@ gnome_vfs_init (void) bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); #endif - if (bonobo_activation_orb_get() == NULL) { + retval = gnome_vfs_pthread_init (TRUE); + + if (retval && bonobo_activation_orb_get() == NULL) { bonobo_activation_init (0, bogus_argv); } gnome_vfs_ssl_init (); - retval = gnome_vfs_method_init (); if (retval) { - retval = gnome_vfs_process_init (); + retval = gnome_vfs_method_init (); } if (retval) { - retval = gnome_vfs_configuration_init (); + retval = gnome_vfs_process_init (); } if (retval) { - retval = gnome_vfs_pthread_init (TRUE); + retval = gnome_vfs_configuration_init (); } if (retval) { signal (SIGPIPE, SIG_IGN); Index: libgnomevfs/gnome-vfs-job.h =================================================================== RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-job.h,v retrieving revision 1.43 diff -u -p -u -r1.43 gnome-vfs-job.h --- libgnomevfs/gnome-vfs-job.h 12 Feb 2002 14:33:43 -0000 1.43 +++ libgnomevfs/gnome-vfs-job.h 12 Jul 2002 11:57:09 -0000 @@ -52,8 +52,8 @@ extern GStaticMutex debug_mutex; #define JOB_DEBUG_PRINT(x) \ G_STMT_START{ \ g_static_mutex_lock (&debug_mutex); \ + fputs (__FUNCTION__ ":", stdout); \ printf ("%d ", __LINE__); \ - fputs (__FUNCTION__ ": ", stdout); \ printf x; \ fputc ('\n', stdout); \ fflush (stdout); \ Index: test/test-async.c =================================================================== RCS file: /cvs/gnome/gnome-vfs/test/test-async.c,v retrieving revision 1.17 diff -u -p -u -r1.17 test-async.c --- test/test-async.c 22 Mar 2002 19:12:07 -0000 1.17 +++ test/test-async.c 12 Jul 2002 11:57:09 -0000 @@ -28,6 +28,8 @@ #include <libgnomevfs/gnome-vfs-init.h> #include <stdio.h> +#define QUEUE_LENGTH 4000 + static GMainLoop *main_loop; /* Callbacks. */ @@ -36,7 +38,7 @@ close_callback (GnomeVFSAsyncHandle *han GnomeVFSResult result, gpointer callback_data) { - printf ("Close: %s.\n", gnome_vfs_result_to_string (result)); + fprintf (stderr, "Close: %s.\n", gnome_vfs_result_to_string (result)); g_main_loop_quit (main_loop); } @@ -49,19 +51,20 @@ read_callback (GnomeVFSAsyncHandle *hand gpointer callback_data) { if (result != GNOME_VFS_OK) { - printf ("Read failed: %s", gnome_vfs_result_to_string (result)); + fprintf (stderr, "Read failed: %s\n", + gnome_vfs_result_to_string (result)); } else { printf ("%"GNOME_VFS_SIZE_FORMAT_STR"/" "%"GNOME_VFS_SIZE_FORMAT_STR" " "byte(s) read, callback data `%s'\n", - bytes_read, bytes_requested, (gchar *) callback_data); + bytes_read, bytes_requested, + (gchar *) callback_data); *((gchar *) buffer + bytes_read) = 0; - puts (buffer); + fprintf (stderr, "%s", (char *) buffer); } - printf ("Now closing the file.\n"); + fprintf (stderr, "Now closing the file.\n"); gnome_vfs_async_close (handle, close_callback, "close"); - g_main_loop_quit (main_loop); } static void @@ -70,15 +73,15 @@ open_callback (GnomeVFSAsyncHandle *han gpointer callback_data) { if (result != GNOME_VFS_OK) { - printf ("Open failed: %s.\n", - gnome_vfs_result_to_string (result)); + fprintf (stderr, "Open failed: %s.\n", + gnome_vfs_result_to_string (result)); g_main_loop_quit (main_loop); } else { gchar *buffer; const gulong buffer_size = 1024; - printf ("File opened correctly, data `%s'.\n", - (gchar *) callback_data); + fprintf (stderr, "File opened correctly, data `%s'.\n", + (gchar *) callback_data); buffer = g_malloc (buffer_size); gnome_vfs_async_read (handle, @@ -89,37 +92,70 @@ open_callback (GnomeVFSAsyncHandle *han } } +static void +dummy_close_callback (GnomeVFSAsyncHandle *handle, + GnomeVFSResult result, + gpointer callback_data) +{ +} + +static void +async_queue_callback (GnomeVFSAsyncHandle *handle, + GnomeVFSResult result, + gpointer callback_data) +{ + int *completed = callback_data; + + (*completed)++; + + if (result == GNOME_VFS_OK) + gnome_vfs_async_close (handle, dummy_close_callback, NULL); +} + int main (int argc, char **argv) { + int completed, i; GnomeVFSAsyncHandle *handle; if (argc < 2) { - fprintf (stderr, "Usage: %s <uri>\n", argv[0]); + fprintf (stderr, "Usage: %s <uri of text file>\n", argv[0]); return 1; } - puts ("Initializing gnome-vfs..."); + fprintf (stderr, "Initializing gnome-vfs...\n"); gnome_vfs_init (); - puts ("Creating async context..."); + fprintf (stderr, "Creating async context...\n"); - printf ("Starting open for `%s'...\n", argv[1]); + fprintf (stderr, "Starting open for `%s'...\n", argv[1]); gnome_vfs_async_open (&handle, argv[1], GNOME_VFS_OPEN_READ, - 0, + GNOME_VFS_PRIORITY_MIN, open_callback, "open_callback"); - puts ("Main loop running."); + fprintf (stderr, "Main loop running.\n"); main_loop = g_main_loop_new (NULL, TRUE); g_main_loop_run (main_loop); - g_main_loop_unref (main_loop); - puts ("Main loop finished."); + fprintf (stderr, "Main loop finished.\n"); + + fprintf (stderr, "Test async queue efficiency ..."); + + for (completed = i = 0; i < QUEUE_LENGTH; i++) { + gnome_vfs_async_open (&handle, argv [1], GNOME_VFS_OPEN_READ, 0, + async_queue_callback, &completed); + } + + while (completed < QUEUE_LENGTH) + g_main_context_iteration (NULL, TRUE); + + fprintf (stderr, "Passed\n"); + + g_main_loop_unref (main_loop); - puts ("All done"); + fprintf (stderr, "All done\n"); - while (1) - ; + gnome_vfs_shutdown (); return 0; } -- [email protected] <><, Pseudo Engineer, itinerant idiot _______________________________________________ gnome-vfs maillist - [email protected] http://lists.ximian.com/mailman/listinfo/gnome-vfs