making GStaticMutexes faster



Hi all,

recently I had an email discussion with Tim about GStaticMutexes, which now
have a really big overhead, because before every access to them (locking,
unlocking) another mutex has to be locked. This is super paranoid, as the only
case it might fail without this additional lock is on an MP-machine without
cache coherence, which should not only be very rare. Additionally I doubt GLib
has been ported to such a machine yet. IOW I would vote for a speed up, by
just returning *mutex in g_static_mutex_get_mutex_impl, if it is non-zero.
This leaves the lock only for the initial calls to
g_static_mutex_get_mutex_impl and there it of course has to be. 

So the change would be:

Index: gthread.c
===================================================================
RCS file: /cvs/gnome/glib/gthread.c,v
retrieving revision 1.23
diff -u -b -B -r1.23 gthread.c
--- gthread.c	2001/05/09 12:51:21	1.23
+++ gthread.c	2001/05/09 13:17:15
@@ -182,6 +182,9 @@
 GMutex *
 g_static_mutex_get_mutex_impl (GMutex** mutex)
 {
+  if (*mutex)
+    return *mutex;
+
   if (!g_thread_supported ())
     return NULL;


We could as well put that into g_static_mutex_get_mutex to also save the
function call.

And yes, this makes a difference, GStaticMutex suddenly becomes ~ 3 times
faster on platforms without native static mutexes.

Bye,
Sebastian
-- 
Sebastian Wilhelmi
mailto:wilhelmi ira uka de
http://goethe.ira.uka.de/~wilhelmi




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