[glib/gmain: 2/5] gmain: always compile with threads support



commit 408a1b8da32c1b6f3294085683cdfdaf23ae26f5
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Jul 27 11:32:27 2011 +0200

    gmain: always compile with threads support
    
    Remove the option for a version of GMainLoop with support for threads disabled
    at compile time.

 glib/gmain.c |   60 ----------------------------------------------------------
 1 files changed, 0 insertions(+), 60 deletions(-)
---
diff --git a/glib/gmain.c b/glib/gmain.c
index 41af376..5680d66 100644
--- a/glib/gmain.c
+++ b/glib/gmain.c
@@ -185,7 +185,6 @@ typedef enum
   G_SOURCE_CAN_RECURSE = 1 << (G_HOOK_FLAG_USER_SHIFT + 1)
 } GSourceFlags;
 
-#ifdef G_THREADS_ENABLED
 typedef struct _GMainWaiter GMainWaiter;
 
 struct _GMainWaiter
@@ -193,7 +192,6 @@ struct _GMainWaiter
   GCond *cond;
   GMutex *mutex;
 };
-#endif  
 
 typedef struct _GMainDispatch GMainDispatch;
 
@@ -209,7 +207,6 @@ gboolean _g_main_poll_debug = FALSE;
 
 struct _GMainContext
 {
-#ifdef G_THREADS_ENABLED
   /* The following lock is used for both the list of sources
    * and the list of poll records
    */
@@ -218,7 +215,6 @@ struct _GMainContext
   GThread *owner;
   guint owner_count;
   GSList *waiters;
-#endif  
 
   gint ref_count;
 
@@ -234,7 +230,6 @@ struct _GMainContext
   GPollFD *cached_poll_array;
   guint cached_poll_array_size;
 
-#ifdef G_THREADS_ENABLED
   GWakeup *wakeup;
 
   GPollFD wake_up_rec;
@@ -242,7 +237,6 @@ struct _GMainContext
 
 /* Flag indicating whether the set of fd's changed during a poll */
   gboolean poll_changed;
-#endif /* G_THREADS_ENABLED */
 
   GPollFunc poll_func;
 
@@ -309,15 +303,9 @@ struct _GSourcePrivate
   GSource *parent_source;
 };
 
-#ifdef G_THREADS_ENABLED
 #define LOCK_CONTEXT(context) g_static_mutex_lock (&context->mutex)
 #define UNLOCK_CONTEXT(context) g_static_mutex_unlock (&context->mutex)
 #define G_THREAD_SELF g_thread_self ()
-#else
-#define LOCK_CONTEXT(context) (void)0
-#define UNLOCK_CONTEXT(context) (void)0
-#define G_THREAD_SELF NULL
-#endif
 
 #define SOURCE_DESTROYED(source) (((source)->flags & G_HOOK_FLAG_ACTIVE) == 0)
 #define SOURCE_BLOCKED(source) (((source)->flags & G_HOOK_FLAG_IN_CALL) != 0 && \
@@ -512,16 +500,13 @@ g_main_context_unref (GMainContext *context)
       source = next;
     }
 
-#ifdef G_THREADS_ENABLED  
   g_static_mutex_free (&context->mutex);
-#endif
 
   g_ptr_array_free (context->pending_dispatches, TRUE);
   g_free (context->cached_poll_array);
 
   poll_rec_list_free (context, context->poll_records);
   
-#ifdef G_THREADS_ENABLED
   if (g_thread_supported())
     g_wakeup_free (context->wakeup);
 
@@ -531,12 +516,10 @@ g_main_context_unref (GMainContext *context)
 
   if (context->cond != NULL)
     g_cond_free (context->cond);
-#endif
 
   g_free (context);
 }
 
-#ifdef G_THREADS_ENABLED
 static void
 g_main_context_init_pipe (GMainContext *context)
 {
@@ -559,7 +542,6 @@ _g_main_thread_init (void)
   g_slist_free (main_contexts_without_pipe);
   main_contexts_without_pipe = NULL;  
 }
-#endif /* G_THREADS_ENABLED */
 
 /**
  * g_main_context_new:
@@ -586,12 +568,10 @@ g_main_context_new (void)
   }
 #endif
 
-#ifdef G_THREADS_ENABLED
   g_static_mutex_init (&context->mutex);
 
   context->owner = NULL;
   context->waiters = NULL;
-#endif
 
   context->ref_count = 1;
 
@@ -609,13 +589,11 @@ g_main_context_new (void)
   context->time_is_fresh = FALSE;
   context->real_time_is_fresh = FALSE;
   
-#ifdef G_THREADS_ENABLED
   if (g_thread_supported ())
     g_main_context_init_pipe (context);
   else
     main_contexts_without_pipe = g_slist_prepend (main_contexts_without_pipe, 
 						  context);
-#endif
 
   G_LOCK (main_context_list);
   main_context_list = g_slist_append (main_context_list, context);
@@ -952,10 +930,8 @@ g_source_attach (GSource      *source,
 
   result = g_source_attach_unlocked (source, context);
 
-#ifdef G_THREADS_ENABLED
   /* Now wake up the main loop if it is waiting in the poll() */
   g_main_context_wakeup_unlocked (context);
-#endif
 
   UNLOCK_CONTEXT (context);
 
@@ -2513,7 +2489,6 @@ next_valid_source (GMainContext *context,
 gboolean 
 g_main_context_acquire (GMainContext *context)
 {
-#ifdef G_THREADS_ENABLED
   gboolean result = FALSE;
   GThread *self = G_THREAD_SELF;
 
@@ -2537,9 +2512,6 @@ g_main_context_acquire (GMainContext *context)
   UNLOCK_CONTEXT (context); 
   
   return result;
-#else /* !G_THREADS_ENABLED */
-  return TRUE;
-#endif /* G_THREADS_ENABLED */
 }
 
 /**
@@ -2554,7 +2526,6 @@ g_main_context_acquire (GMainContext *context)
 void
 g_main_context_release (GMainContext *context)
 {
-#ifdef G_THREADS_ENABLED
   if (context == NULL)
     context = g_main_context_default ();
   
@@ -2583,7 +2554,6 @@ g_main_context_release (GMainContext *context)
     }
 
   UNLOCK_CONTEXT (context); 
-#endif /* G_THREADS_ENABLED */
 }
 
 /**
@@ -2606,7 +2576,6 @@ g_main_context_wait (GMainContext *context,
 		     GCond        *cond,
 		     GMutex       *mutex)
 {
-#ifdef G_THREADS_ENABLED
   gboolean result = FALSE;
   GThread *self = G_THREAD_SELF;
   gboolean loop_internal_waiter;
@@ -2653,9 +2622,6 @@ g_main_context_wait (GMainContext *context,
     UNLOCK_CONTEXT (context); 
   
   return result;
-#else /* !G_THREADS_ENABLED */
-  return TRUE;
-#endif /* G_THREADS_ENABLED */
 }
 
 /**
@@ -2695,7 +2661,6 @@ g_main_context_prepare (GMainContext *context,
       return FALSE;
     }
 
-#ifdef G_THREADS_ENABLED
   if (context->poll_waiting)
     {
       g_warning("g_main_context_prepare(): main loop already active in another thread");
@@ -2704,7 +2669,6 @@ g_main_context_prepare (GMainContext *context,
     }
   
   context->poll_waiting = TRUE;
-#endif /* G_THREADS_ENABLED */
 
 #if 0
   /* If recursing, finish up current dispatch, before starting over */
@@ -2849,9 +2813,7 @@ g_main_context_query (GMainContext *context,
       n_poll++;
     }
 
-#ifdef G_THREADS_ENABLED
   context->poll_changed = FALSE;
-#endif
   
   if (timeout)
     {
@@ -2901,7 +2863,6 @@ g_main_context_check (GMainContext *context,
       return FALSE;
     }
   
-#ifdef G_THREADS_ENABLED
   if (!context->poll_waiting)
     g_wakeup_acknowledge (context->wakeup);
 
@@ -2916,7 +2877,6 @@ g_main_context_check (GMainContext *context,
       UNLOCK_CONTEXT (context);
       return FALSE;
     }
-#endif /* G_THREADS_ENABLED */
   
   pollrec = context->poll_records;
   i = 0;
@@ -3023,7 +2983,6 @@ g_main_context_iterate (GMainContext *context,
 
   UNLOCK_CONTEXT (context);
 
-#ifdef G_THREADS_ENABLED
   if (!g_main_context_acquire (context))
     {
       gboolean got_ownership;
@@ -3047,7 +3006,6 @@ g_main_context_iterate (GMainContext *context,
     }
   else
     LOCK_CONTEXT (context);
-#endif /* G_THREADS_ENABLED */
   
   if (!context->cached_poll_array)
     {
@@ -3082,9 +3040,7 @@ g_main_context_iterate (GMainContext *context,
   if (dispatch)
     g_main_context_dispatch (context);
   
-#ifdef G_THREADS_ENABLED
   g_main_context_release (context);
-#endif /* G_THREADS_ENABLED */    
 
   LOCK_CONTEXT (context);
 
@@ -3235,7 +3191,6 @@ g_main_loop_run (GMainLoop *loop)
   g_return_if_fail (loop != NULL);
   g_return_if_fail (g_atomic_int_get (&loop->ref_count) > 0);
 
-#ifdef G_THREADS_ENABLED
   if (!g_main_context_acquire (loop->context))
     {
       gboolean got_ownership = FALSE;
@@ -3276,7 +3231,6 @@ g_main_loop_run (GMainLoop *loop)
     }
   else
     LOCK_CONTEXT (loop->context);
-#endif /* G_THREADS_ENABLED */ 
 
   if (loop->context->in_check_or_prepare)
     {
@@ -3292,9 +3246,7 @@ g_main_loop_run (GMainLoop *loop)
 
   UNLOCK_CONTEXT (loop->context);
   
-#ifdef G_THREADS_ENABLED
   g_main_context_release (loop->context);
-#endif /* G_THREADS_ENABLED */    
   
   g_main_loop_unref (loop);
 }
@@ -3319,10 +3271,8 @@ g_main_loop_quit (GMainLoop *loop)
   loop->is_running = FALSE;
   g_main_context_wakeup_unlocked (loop->context);
 
-#ifdef G_THREADS_ENABLED
   if (loop->context->cond)
     g_cond_broadcast (loop->context->cond);
-#endif /* G_THREADS_ENABLED */
 
   UNLOCK_CONTEXT (loop->context);
 }
@@ -3517,12 +3467,10 @@ g_main_context_add_poll_unlocked (GMainContext *context,
 
   context->n_poll_records++;
 
-#ifdef G_THREADS_ENABLED
   context->poll_changed = TRUE;
 
   /* Now wake up the main loop if it is waiting in the poll() */
   g_main_context_wakeup_unlocked (context);
-#endif
 }
 
 /**
@@ -3581,12 +3529,10 @@ g_main_context_remove_poll_unlocked (GMainContext *context,
       pollrec = nextrec;
     }
 
-#ifdef G_THREADS_ENABLED
   context->poll_changed = TRUE;
   
   /* Now wake up the main loop if it is waiting in the poll() */
   g_main_context_wakeup_unlocked (context);
-#endif
 }
 
 /**
@@ -3748,13 +3694,11 @@ _g_main_wake_up_all_contexts (void)
 static void
 g_main_context_wakeup_unlocked (GMainContext *context)
 {
-#ifdef G_THREADS_ENABLED
   if (g_thread_supported() && context->poll_waiting)
     {
       context->poll_waiting = FALSE;
       g_wakeup_signal (context->wakeup);
     }
-#endif
 }
 
 /**
@@ -3798,13 +3742,9 @@ g_main_context_is_owner (GMainContext *context)
   if (!context)
     context = g_main_context_default ();
 
-#ifdef G_THREADS_ENABLED
   LOCK_CONTEXT (context);
   is_owner = context->owner == G_THREAD_SELF;
   UNLOCK_CONTEXT (context);
-#else
-  is_owner = TRUE;
-#endif
 
   return is_owner;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]