Added g_static_mutex_init to allow initialization of a GStaticMutex, that
authorSebastian Wilhelmi <wilhelmi@ira.uka.de>
Thu, 1 Feb 2001 09:37:28 +0000 (09:37 +0000)
committerSebastian Wilhelmi <wilhelmi@src.gnome.org>
Thu, 1 Feb 2001 09:37:28 +0000 (09:37 +0000)
2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

* gthread.c, gthread.h: Added g_static_mutex_init to allow
initialization of a GStaticMutex, that can not be initialized with
G_STATIC_MUTEX_INIT, for example in allocated structures.

* glib/tmpl/threads.sgml, glib/glib-sections.txt: Added
documentation for g_static_mutex_init().

WCVS: ----------------------------------------------------------------------

15 files changed:
ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-12
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/glib/glib-sections.txt
docs/reference/glib/tmpl/threads.sgml
glib/gthread.c
glib/gthread.h
gthread.c
gthread.h

index 14de7e9..ad1a004 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gthread.c, gthread.h: Added g_static_mutex_init to allow
+       initialization of a GStaticMutex, that can not be initialized with
+       G_STATIC_MUTEX_INIT, for example in allocated structures.
+
 Wed Jan 31 13:46:58 2001  Owen Taylor  <otaylor@redhat.com>
 
        * acinclude.m4 glib-gettext.m4: Fix problem with --disable-nls.
index 14de7e9..ad1a004 100644 (file)
@@ -1,3 +1,9 @@
+2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gthread.c, gthread.h: Added g_static_mutex_init to allow
+       initialization of a GStaticMutex, that can not be initialized with
+       G_STATIC_MUTEX_INIT, for example in allocated structures.
+
 Wed Jan 31 13:46:58 2001  Owen Taylor  <otaylor@redhat.com>
 
        * acinclude.m4 glib-gettext.m4: Fix problem with --disable-nls.
index 14de7e9..ad1a004 100644 (file)
@@ -1,3 +1,9 @@
+2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gthread.c, gthread.h: Added g_static_mutex_init to allow
+       initialization of a GStaticMutex, that can not be initialized with
+       G_STATIC_MUTEX_INIT, for example in allocated structures.
+
 Wed Jan 31 13:46:58 2001  Owen Taylor  <otaylor@redhat.com>
 
        * acinclude.m4 glib-gettext.m4: Fix problem with --disable-nls.
index 14de7e9..ad1a004 100644 (file)
@@ -1,3 +1,9 @@
+2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gthread.c, gthread.h: Added g_static_mutex_init to allow
+       initialization of a GStaticMutex, that can not be initialized with
+       G_STATIC_MUTEX_INIT, for example in allocated structures.
+
 Wed Jan 31 13:46:58 2001  Owen Taylor  <otaylor@redhat.com>
 
        * acinclude.m4 glib-gettext.m4: Fix problem with --disable-nls.
index 14de7e9..ad1a004 100644 (file)
@@ -1,3 +1,9 @@
+2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gthread.c, gthread.h: Added g_static_mutex_init to allow
+       initialization of a GStaticMutex, that can not be initialized with
+       G_STATIC_MUTEX_INIT, for example in allocated structures.
+
 Wed Jan 31 13:46:58 2001  Owen Taylor  <otaylor@redhat.com>
 
        * acinclude.m4 glib-gettext.m4: Fix problem with --disable-nls.
index 14de7e9..ad1a004 100644 (file)
@@ -1,3 +1,9 @@
+2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gthread.c, gthread.h: Added g_static_mutex_init to allow
+       initialization of a GStaticMutex, that can not be initialized with
+       G_STATIC_MUTEX_INIT, for example in allocated structures.
+
 Wed Jan 31 13:46:58 2001  Owen Taylor  <otaylor@redhat.com>
 
        * acinclude.m4 glib-gettext.m4: Fix problem with --disable-nls.
index 14de7e9..ad1a004 100644 (file)
@@ -1,3 +1,9 @@
+2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gthread.c, gthread.h: Added g_static_mutex_init to allow
+       initialization of a GStaticMutex, that can not be initialized with
+       G_STATIC_MUTEX_INIT, for example in allocated structures.
+
 Wed Jan 31 13:46:58 2001  Owen Taylor  <otaylor@redhat.com>
 
        * acinclude.m4 glib-gettext.m4: Fix problem with --disable-nls.
index 14de7e9..ad1a004 100644 (file)
@@ -1,3 +1,9 @@
+2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * gthread.c, gthread.h: Added g_static_mutex_init to allow
+       initialization of a GStaticMutex, that can not be initialized with
+       G_STATIC_MUTEX_INIT, for example in allocated structures.
+
 Wed Jan 31 13:46:58 2001  Owen Taylor  <otaylor@redhat.com>
 
        * acinclude.m4 glib-gettext.m4: Fix problem with --disable-nls.
index a385889..57f908d 100644 (file)
@@ -1,3 +1,8 @@
+2001-02-01  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>
+
+       * glib/tmpl/threads.sgml, glib/glib-sections.txt: Added
+       documentation for g_static_mutex_init().
+
 Wed Jan 31 07:14:22 2001  Tim Janik  <timj@gtk.org>
 
        * gobject/Makefile.am: adapt to work with new CVS gtk-doc, leaving the old
index 4fdbf90..53c3c3f 100644 (file)
@@ -461,6 +461,7 @@ g_mutex_free
 <SUBSECTION>
 GStaticMutex
 G_STATIC_MUTEX_INIT
+g_static_mutex_init
 g_static_mutex_lock
 g_static_mutex_trylock
 g_static_mutex_unlock
index 10fbee4..9a7cb14 100644 (file)
@@ -371,6 +371,12 @@ not use such constructs in your own programs. One working solution is:
 </para>
 
 <para>
+If you want to use a mutex, but your code should also work without
+calling g_thread_init() first, you can not use a #GMutex, as
+g_mutex_new() requires that. Use a #GStaticMutex instead.
+</para>
+
+<para>
 A #GMutex should only be accessed via the following functions.
 </para>
 
@@ -473,10 +479,10 @@ Sometimes you would like to dynamically create a mutex. If you don't
 want to require prior calling to g_thread_init(), because your code
 should also be usable in non-threaded programs, you are not able to
 use g_mutex_new() and thus #GMutex, as that requires a prior call to
-g_thread_init(). In theses cases you can also use a #GStaticMutex, but
-you should remember to free the #GStaticMutex with
-g_static_mutex_free() when not needed anymore to free up any
-allocated recourses.
+g_thread_init(). In theses cases you can also use a #GStaticMutex. It
+must be initialized with g_static_mutex_init() before using it and
+freed with with g_static_mutex_free() when not needed anymore to free
+up any allocated recourses.
 </para>
 
 <para>
@@ -520,8 +526,10 @@ functions.
 <!-- ##### MACRO G_STATIC_MUTEX_INIT ##### -->
 
 <para>
-Every #GStaticMutex must be initialized with this macro, before it can
-be used.
+A #GStaticMutex must be initialized with this macro, before it can be
+used. This macro can used be to initialize a variable, but it cannot
+be assigned to a variable. In that case you have to use
+g_static_mutex_init().
 </para>
 
 <para>
@@ -535,6 +543,16 @@ GStaticMutex my_mutex = G_STATIC_MUTEX_INIT;
 
 
 
+<!-- ##### FUNCTION g_static_mutex_init ##### -->
+<para>
+A #GStaticMutex must be initialized with this function, before it can
+be used. Alternatively you can initialize it with
+#G_STATIC_MUTEX_INIT.
+</para>
+
+@mutex: a #GStaticMutex to be initialized.
+
+
 <!-- ##### FUNCTION g_static_mutex_lock ##### -->
 <para>
 works like g_mutex_lock(), but for a #GStaticMutex.
index 4e94474..71b5627 100644 (file)
@@ -159,6 +159,16 @@ g_static_mutex_get_mutex_impl (GMutex** mutex)
   return *mutex;
 }
 
+void 
+g_static_mutex_init (GStaticMutex *mutex)
+{
+  static GStaticMutex init_mutex = G_STATIC_MUTEX_INIT;
+
+  g_return_if_fail (mutex);
+
+  memcpy (mutex, &init_mutex, sizeof (GStaticMutex));
+}
+
 void
 g_static_mutex_free (GStaticMutex* mutex)
 {
index 303c441..1f86418 100644 (file)
@@ -227,6 +227,7 @@ void g_thread_set_priority (GThread         *thread,
     g_mutex_trylock (g_static_mutex_get_mutex (mutex))
 #define g_static_mutex_unlock(mutex) \
     g_mutex_unlock (g_static_mutex_get_mutex (mutex))
+void g_static_mutex_init (GStaticMutex *mutex);
 void g_static_mutex_free (GStaticMutex *mutex);
 
 struct _GStaticPrivate
index 4e94474..71b5627 100644 (file)
--- a/gthread.c
+++ b/gthread.c
@@ -159,6 +159,16 @@ g_static_mutex_get_mutex_impl (GMutex** mutex)
   return *mutex;
 }
 
+void 
+g_static_mutex_init (GStaticMutex *mutex)
+{
+  static GStaticMutex init_mutex = G_STATIC_MUTEX_INIT;
+
+  g_return_if_fail (mutex);
+
+  memcpy (mutex, &init_mutex, sizeof (GStaticMutex));
+}
+
 void
 g_static_mutex_free (GStaticMutex* mutex)
 {
index 303c441..1f86418 100644 (file)
--- a/gthread.h
+++ b/gthread.h
@@ -227,6 +227,7 @@ void g_thread_set_priority (GThread         *thread,
     g_mutex_trylock (g_static_mutex_get_mutex (mutex))
 #define g_static_mutex_unlock(mutex) \
     g_mutex_unlock (g_static_mutex_get_mutex (mutex))
+void g_static_mutex_init (GStaticMutex *mutex);
 void g_static_mutex_free (GStaticMutex *mutex);
 
 struct _GStaticPrivate