X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=glib%2Fgmain.c;h=6bb726e169735a3d33203a4f28bf3113b175ab94;hb=bc6ee788b4ff6590513da6ab657448885e92b20b;hp=38feb2cf85a29086aca2112d7ec0eb3338db9038;hpb=85d612a968c1d02a958f57c38d1ce90ceea4afc9;p=platform%2Fupstream%2Fglib.git
diff --git a/glib/gmain.c b/glib/gmain.c
index 38feb2c..6bb726e 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -136,42 +136,46 @@
* GTK+ contains wrappers of some of these functions, e.g. gtk_main(),
* gtk_main_quit() and gtk_events_pending().
*
- * Creating new source types
- * One of the unusual features of the #GMainLoop functionality
+ * ## Creating new source types
+ *
+ * One of the unusual features of the #GMainLoop functionality
* is that new types of event source can be created and used in
* addition to the builtin type of event source. A new event source
* type is used for handling GDK events. A new source type is created
- * by deriving from the #GSource structure.
- * The derived type of source is represented by a structure that has
- * the #GSource structure as a first element, and other elements specific
- * to the new source type. To create an instance of the new source type,
- * call g_source_new() passing in the size of the derived structure and
+ * by "deriving" from the #GSource structure. The derived type of
+ * source is represented by a structure that has the #GSource structure
+ * as a first element, and other elements specific to the new source
+ * type. To create an instance of the new source type, call
+ * g_source_new() passing in the size of the derived structure and
* a table of functions. These #GSourceFuncs determine the behavior of
- * the new source type.
- * New source types basically interact with the main context
+ * the new source type.
+ *
+ * New source types basically interact with the main context
* in two ways. Their prepare function in #GSourceFuncs can set a timeout
* to determine the maximum amount of time that the main loop will sleep
* before checking the source again. In addition, or as well, the source
* can add file descriptors to the set that the main context checks using
- * g_source_add_poll().
- *
- * Customizing the main loop iteration
- * Single iterations of a #GMainContext can be run with
+ * g_source_add_poll().
+ *
+ * ## Customizing the main loop iteration
+ *
+ * Single iterations of a #GMainContext can be run with
* g_main_context_iteration(). In some cases, more detailed control
* of exactly how the details of the main loop work is desired, for
* instance, when integrating the #GMainLoop with an external main loop.
* In such cases, you can call the component functions of
* g_main_context_iteration() directly. These functions are
* g_main_context_prepare(), g_main_context_query(),
- * g_main_context_check() and g_main_context_dispatch().
- * The operation of these functions can best be seen in terms
- * of a state diagram, as shown in .
- *
- *
- *
- * On Unix, the GLib mainloop is incompatible with fork(). Any program
+ * g_main_context_check() and g_main_context_dispatch().
+ *
+ * ## State of a Main Context # {#mainloop-states}
+ *
+ * The operation of these functions can best be seen in terms
+ * of a state diagram, as shown in this image.
+ *
+ * ![](mainloop-states.gif)
+ *
+ * On UNIX, the GLib mainloop is incompatible with fork(). Any program
* using the mainloop must either exec() or exit() from the child
* without returning to the mainloop.
*/
@@ -684,7 +688,7 @@ static GPrivate thread_context_stack = G_PRIVATE_INIT (free_context_stack);
*
* Acquires @context and sets it as the thread-default context for the
* current thread. This will cause certain asynchronous operations
- * (such as most gio-based I/O) which are
+ * (such as most [gio][gio]-based I/O) which are
* started in this thread to run under @context and deliver their
* results to its main loop, rather than running under the global
* default context in the main thread. Note that calling this function
@@ -772,7 +776,7 @@ g_main_context_pop_thread_default (GMainContext *context)
* operations that want to be able to be run in contexts other than
* the default one should call this method or
* g_main_context_ref_thread_default() to get a #GMainContext to add
- * their #GSources to. (Note that even in single-threaded
+ * their #GSources to. (Note that even in single-threaded
* programs applications may sometimes want to temporarily push a
* non-default context, so it is not safe to assume that this will
* always return %NULL if you are running in the default thread.)
@@ -834,7 +838,7 @@ g_main_context_ref_thread_default (void)
* Creates a new #GSource structure. The size is specified to
* allow creating structures derived from #GSource that contain
* additional data. The size passed in must be at least
- * sizeof (GSource).
+ * `sizeof (GSource)`.
*
* The source will not initially be associated with any #GMainContext
* and must be added to one with g_source_attach() before it will be
@@ -1246,7 +1250,8 @@ g_source_destroy_internal (GSource *source,
*
* Removes a source from its #GMainContext, if any, and mark it as
* destroyed. The source cannot be subsequently added to another
- * context.
+ * context. It is safe to call this on sources which have already been
+ * removed from their context.
**/
void
g_source_destroy (GSource *source)
@@ -2527,12 +2532,12 @@ g_clock_win32_init (void)
*
* Queries the system monotonic time, if available.
*
- * On POSIX systems with clock_gettime() and CLOCK_MONOTONIC this call
+ * On POSIX systems with clock_gettime() and `CLOCK_MONOTONIC` this call
* is a very shallow wrapper for that. Otherwise, we make a best effort
* that probably involves returning the wall clock time (with at least
* microsecond accuracy, subject to the limitations of the OS kernel).
*
- * It's important to note that POSIX CLOCK_MONOTONIC does
+ * It's important to note that POSIX `CLOCK_MONOTONIC` does
* not count time spent while the machine is suspended.
*
* On Windows, "limitations of the OS kernel" is a rather substantial
@@ -2741,7 +2746,7 @@ get_dispatch (void)
* This function is useful in a situation like the following:
* Imagine an extremely simple "garbage collected" system.
*
- * |[
+ * |[
* static GList *free_list;
*
* gpointer
@@ -2778,7 +2783,7 @@ get_dispatch (void)
* doesn't work, since the idle function could be called from a
* recursive callback. This can be fixed by using g_main_depth()
*
- * |[
+ * |[
* gpointer
* allocate_memory (gsize size)
* {
@@ -2867,16 +2872,16 @@ g_main_current_source (void)
* from within idle handlers, but may have freed the object
* before the dispatch of your idle handler.
*
- * |[
+ * |[
* static gboolean
* idle_callback (gpointer data)
* {
* SomeWidget *self = data;
*
- * GDK_THREADS_ENTER ();
- * /* do stuff with self */
+ * GDK_THREADS_ENTER ();
+ * // do stuff with self
* self->idle_id = 0;
- * GDK_THREADS_LEAVE ();
+ * GDK_THREADS_LEAVE ();
*
* return G_SOURCE_REMOVE;
* }
@@ -2905,7 +2910,7 @@ g_main_current_source (void)
* this particular problem, is to check to if the source
* has already been destroy within the callback.
*
- * |[
+ * |[
* static gboolean
* idle_callback (gpointer data)
* {
@@ -2914,7 +2919,7 @@ g_main_current_source (void)
* GDK_THREADS_ENTER ();
* if (!g_source_is_destroyed (g_main_current_source ()))
* {
- * /* do stuff with self */
+ * // do stuff with self
* }
* GDK_THREADS_LEAVE ();
*
@@ -4321,7 +4326,7 @@ g_main_context_get_poll_func (GMainContext *context)
* Another related use for this function is when implementing a main
* loop with a termination condition, computed from multiple threads:
*
- * |[
+ * |[
* #define NUM_TASKS 10
* static volatile gint tasks_remaining = NUM_TASKS;
* ...
@@ -4331,7 +4336,7 @@ g_main_context_get_poll_func (GMainContext *context)
* ]|
*
* Then in a thread:
- * |[
+ * |[
* perform_work();
*
* if (g_atomic_int_dec_and_test (&tasks_remaining))
@@ -4863,6 +4868,8 @@ dispatch_unix_signals_unlocked (void)
pid_t pid;
do
{
+ g_assert (source->pid > 0);
+
pid = waitpid (source->pid, &source->child_status, WNOHANG);
if (pid > 0)
{
@@ -5091,7 +5098,7 @@ g_unix_signal_handler (int signum)
/**
* g_child_watch_source_new:
- * @pid: process to watch. On POSIX the pid of a child process. On
+ * @pid: process to watch. On POSIX the positive pid of a child process. On
* Windows a handle for a process (which doesn't have to be a child).
*
* Creates a new child_watch source.
@@ -5101,8 +5108,7 @@ g_unix_signal_handler (int signum)
* executed.
*
* Note that child watch sources can only be used in conjunction with
- * g_spawn... when the %G_SPAWN_DO_NOT_REAP_CHILD
- * flag is used.
+ * `g_spawn...` when the %G_SPAWN_DO_NOT_REAP_CHILD flag is used.
*
* Note that on platforms where #GPid must be explicitly closed
* (see g_spawn_close_pid()) @pid must not be closed while the
@@ -5110,10 +5116,14 @@ g_unix_signal_handler (int signum)
* g_spawn_close_pid() in the callback function for the source.
*
* Note further that using g_child_watch_source_new() is not
- * compatible with calling waitpid with a
- * nonpositive first argument in the application. Calling waitpid()
- * for individual pids will still work fine.
- *
+ * compatible with calling `waitpid` with a nonpositive first
+ * argument in the application. Calling waitpid() for individual
+ * pids will still work fine.
+ *
+ * Similarly, on POSIX platforms, the @pid passed to this function must
+ * be greater than 0 (i.e. this function must wait for a specific child,
+ * and cannot wait for one of many children by using a nonpositive argument).
+ *
* Return value: the newly-created child watch source
*
* Since: 2.4
@@ -5121,8 +5131,15 @@ g_unix_signal_handler (int signum)
GSource *
g_child_watch_source_new (GPid pid)
{
- GSource *source = g_source_new (&g_child_watch_funcs, sizeof (GChildWatchSource));
- GChildWatchSource *child_watch_source = (GChildWatchSource *)source;
+ GSource *source;
+ GChildWatchSource *child_watch_source;
+
+#ifndef G_OS_WIN32
+ g_return_val_if_fail (pid > 0, NULL);
+#endif
+
+ source = g_source_new (&g_child_watch_funcs, sizeof (GChildWatchSource));
+ child_watch_source = (GChildWatchSource *)source;
child_watch_source->pid = pid;
@@ -5147,7 +5164,7 @@ g_child_watch_source_new (GPid pid)
* g_child_watch_add_full:
* @priority: the priority of the idle source. Typically this will be in the
* range between #G_PRIORITY_DEFAULT_IDLE and #G_PRIORITY_HIGH_IDLE.
- * @pid: process to watch. On POSIX the pid of a child process. On
+ * @pid: process to watch. On POSIX the positive pid of a child process. On
* Windows a handle for a process (which doesn't have to be a child).
* @function: function to call
* @data: data to pass to @function
@@ -5192,6 +5209,9 @@ g_child_watch_add_full (gint priority,
guint id;
g_return_val_if_fail (function != NULL, 0);
+#ifndef G_OS_WIN32
+ g_return_val_if_fail (pid > 0, 0);
+#endif
source = g_child_watch_source_new (pid);
@@ -5207,8 +5227,9 @@ g_child_watch_add_full (gint priority,
/**
* g_child_watch_add:
- * @pid: process id to watch. On POSIX the pid of a child process. On
- * Windows a handle for a process (which doesn't have to be a child).
+ * @pid: process id to watch. On POSIX the positive pid of a child
+ * process. On Windows a handle for a process (which doesn't have to be
+ * a child).
* @function: function to call
* @data: data to pass to @function
*