Author: abrander
Date: 2013-06-04 21:20:16 +0200 (Tue, 04 Jun 2013)
New Revision: 4407

Modified:
   trunk/librawstudio/rs-debug.c
   trunk/librawstudio/rs-debug.h
   trunk/librawstudio/rs-io.c
   trunk/librawstudio/rs-io.h
Log:
Added simple debug printing for IO lock.

Modified: trunk/librawstudio/rs-debug.c
===================================================================
--- trunk/librawstudio/rs-debug.c       2013-06-04 19:06:42 UTC (rev 4406)
+++ trunk/librawstudio/rs-debug.c       2013-06-04 19:20:16 UTC (rev 4407)
@@ -28,6 +28,7 @@
        { "performance", RS_DEBUG_PERFORMANCE },
        { "processing", RS_DEBUG_PROCESSING },
        { "library", RS_DEBUG_LIBRARY },
+       { "locking", RS_DEBUG_LOCKING },
 };
 
 void

Modified: trunk/librawstudio/rs-debug.h
===================================================================
--- trunk/librawstudio/rs-debug.h       2013-06-04 19:06:42 UTC (rev 4406)
+++ trunk/librawstudio/rs-debug.h       2013-06-04 19:20:16 UTC (rev 4407)
@@ -31,6 +31,7 @@
        RS_DEBUG_PERFORMANCE = 1 << 2,
        RS_DEBUG_PROCESSING  = 1 << 3,
        RS_DEBUG_LIBRARY     = 1 << 4,
+       RS_DEBUG_LOCKING     = 1 << 5,
 } RSDebugFlag;
 
 #define RS_DEBUG(type,x,a...) \

Modified: trunk/librawstudio/rs-io.c
===================================================================
--- trunk/librawstudio/rs-io.c  2013-06-04 19:06:42 UTC (rev 4406)
+++ trunk/librawstudio/rs-io.c  2013-06-04 19:20:16 UTC (rev 4407)
@@ -22,6 +22,7 @@
 static GStaticMutex init_lock = G_STATIC_MUTEX_INIT;
 static GAsyncQueue *queue = NULL;
 static GStaticRecMutex io_lock = G_STATIC_REC_MUTEX_INIT;
+static GTimer *io_lock_timer = NULL;
 static gboolean pause_queue = FALSE;
 static gint queue_active_count = 0;
 static GStaticMutex count_lock = G_STATIC_MUTEX_INIT;
@@ -89,6 +90,8 @@
                queue = g_async_queue_new();
                for (i = 0; i < rs_get_number_of_processor_cores(); i++)
                        g_thread_create(queue_worker, queue, FALSE, NULL);
+
+               io_lock_timer = g_timer_new();
        }
        g_static_mutex_unlock(&init_lock);
 }
@@ -297,29 +300,45 @@
  * Aquire the IO lock
  */
 void
-rs_io_lock(void)
+rs_io_lock_real(const gchar *source_file, gint line, const gchar *caller)
 {
-       if (g_static_rec_mutex_trylock(&io_lock))
-               return;
+       RS_DEBUG(LOCKING, "[%s:%d %s()] \033[33mrequesting\033[0m IO lock 
(thread %p)",
+               source_file, line, caller,
+               (g_timer_start(io_lock_timer), g_thread_self()));
 
        /* Each loop tries approx every millisecond, so we wait 10 secs */
        int tries_left = 10*1000;
-       do {
+
+       while (FALSE == g_static_rec_mutex_trylock(&io_lock));
+       {
                g_usleep(1000);
                if (--tries_left <= 0)
                {
-                       g_warning("IO Lock was not released after 10 seconds, 
ignoring IO lock");
+                       RS_DEBUG(LOCKING, "[%s:%d %s()] \033[31mIO Lock was not 
released after \033[36m%.2f\033[0mms\033[0m, ignoring IO lock (thread %p)",
+                               source_file, line, caller,
+                               g_timer_elapsed(io_lock_timer, NULL)*1000.0,
+                               (g_timer_start(io_lock_timer), 
g_thread_self()));
                        return;
                }
-       } while (FALSE == g_static_rec_mutex_trylock(&io_lock));
+       }
+
+       RS_DEBUG(LOCKING, "[%s:%d %s()] \033[32mgot\033[0m IO lock after 
\033[36m%.2f\033[0mms (thread %p)",
+               source_file, line, caller,
+               g_timer_elapsed(io_lock_timer, NULL)*1000.0,
+               (g_timer_start(io_lock_timer), g_thread_self()));
 }
 
 /**
  * Release the IO lock
  */
 void
-rs_io_unlock(void)
+rs_io_unlock_real(const gchar *source_file, gint line, const gchar *caller)
 {
+       RS_DEBUG(LOCKING, "[%s:%d %s()] releasing IO lock after 
\033[36m%.2f\033[0mms (thread %p)",
+               source_file, line, caller,
+               g_timer_elapsed(io_lock_timer, NULL)*1000.0,
+               g_thread_self());
+
        g_static_rec_mutex_unlock(&io_lock);
 }
 

Modified: trunk/librawstudio/rs-io.h
===================================================================
--- trunk/librawstudio/rs-io.h  2013-06-04 19:06:42 UTC (rev 4406)
+++ trunk/librawstudio/rs-io.h  2013-06-04 19:20:16 UTC (rev 4407)
@@ -109,17 +109,20 @@
 void
 rs_io_idle_unpause(void);
 
+#define rs_io_lock() rs_io_lock_real(__FILE__, __LINE__, __FUNCTION__)
+#define rs_io_unlock() rs_io_unlock_real(__FILE__, __LINE__, __FUNCTION__)
+
 /**
  * Aquire the IO lock
  */
 void
-rs_io_lock(void);
+rs_io_lock_real(const gchar *source_file, gint line, const gchar *caller);
 
 /**
  * Release the IO lock
  */
 void
-rs_io_unlock(void);
+rs_io_unlock_real(const gchar *source_file, gint line, const gchar *caller);
 
 /**
  * Returns the number of jobs left


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to