mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-06-07 21:30:06 +02:00
Call g_thread_impl_init(), as g_thread_init won't call it.
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * gthread/gthread-impl.c (g_thread_init_with_errorcheck_mutexes): Call g_thread_impl_init(), as g_thread_init won't call it. * glib/glib-sections.txt, glib/tmpl/threads.sgml: Added g_static_mutex_free * gthread.c, gthread.h: Added g_static_mutex_free to allow using GStaticMutexes with limited lifetime without leaking. * configure.in: GStaticMutex doesn't have to provide extra space for debugging information for G_ERRORCHECK_MUTEXES, as then the non-default implementation (runtime_mutex) is used anyway.
This commit is contained in:
parent
1f46d9f68f
commit
f9dfcb27b7
@ -1,5 +1,12 @@
|
|||||||
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Added g_static_mutex_free to allow using
|
||||||
|
GStaticMutexes with limited lifetime without leaking.
|
||||||
|
|
||||||
|
* configure.in: GStaticMutex doesn't have to provide extra space
|
||||||
|
for debugging information for G_ERRORCHECK_MUTEXES, as then the
|
||||||
|
non-default implementation (runtime_mutex) is used anyway.
|
||||||
|
|
||||||
* gthread.h (g_cond_wait): Added debug information for
|
* gthread.h (g_cond_wait): Added debug information for
|
||||||
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Added g_static_mutex_free to allow using
|
||||||
|
GStaticMutexes with limited lifetime without leaking.
|
||||||
|
|
||||||
|
* configure.in: GStaticMutex doesn't have to provide extra space
|
||||||
|
for debugging information for G_ERRORCHECK_MUTEXES, as then the
|
||||||
|
non-default implementation (runtime_mutex) is used anyway.
|
||||||
|
|
||||||
* gthread.h (g_cond_wait): Added debug information for
|
* gthread.h (g_cond_wait): Added debug information for
|
||||||
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Added g_static_mutex_free to allow using
|
||||||
|
GStaticMutexes with limited lifetime without leaking.
|
||||||
|
|
||||||
|
* configure.in: GStaticMutex doesn't have to provide extra space
|
||||||
|
for debugging information for G_ERRORCHECK_MUTEXES, as then the
|
||||||
|
non-default implementation (runtime_mutex) is used anyway.
|
||||||
|
|
||||||
* gthread.h (g_cond_wait): Added debug information for
|
* gthread.h (g_cond_wait): Added debug information for
|
||||||
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Added g_static_mutex_free to allow using
|
||||||
|
GStaticMutexes with limited lifetime without leaking.
|
||||||
|
|
||||||
|
* configure.in: GStaticMutex doesn't have to provide extra space
|
||||||
|
for debugging information for G_ERRORCHECK_MUTEXES, as then the
|
||||||
|
non-default implementation (runtime_mutex) is used anyway.
|
||||||
|
|
||||||
* gthread.h (g_cond_wait): Added debug information for
|
* gthread.h (g_cond_wait): Added debug information for
|
||||||
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Added g_static_mutex_free to allow using
|
||||||
|
GStaticMutexes with limited lifetime without leaking.
|
||||||
|
|
||||||
|
* configure.in: GStaticMutex doesn't have to provide extra space
|
||||||
|
for debugging information for G_ERRORCHECK_MUTEXES, as then the
|
||||||
|
non-default implementation (runtime_mutex) is used anyway.
|
||||||
|
|
||||||
* gthread.h (g_cond_wait): Added debug information for
|
* gthread.h (g_cond_wait): Added debug information for
|
||||||
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Added g_static_mutex_free to allow using
|
||||||
|
GStaticMutexes with limited lifetime without leaking.
|
||||||
|
|
||||||
|
* configure.in: GStaticMutex doesn't have to provide extra space
|
||||||
|
for debugging information for G_ERRORCHECK_MUTEXES, as then the
|
||||||
|
non-default implementation (runtime_mutex) is used anyway.
|
||||||
|
|
||||||
* gthread.h (g_cond_wait): Added debug information for
|
* gthread.h (g_cond_wait): Added debug information for
|
||||||
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Added g_static_mutex_free to allow using
|
||||||
|
GStaticMutexes with limited lifetime without leaking.
|
||||||
|
|
||||||
|
* configure.in: GStaticMutex doesn't have to provide extra space
|
||||||
|
for debugging information for G_ERRORCHECK_MUTEXES, as then the
|
||||||
|
non-default implementation (runtime_mutex) is used anyway.
|
||||||
|
|
||||||
* gthread.h (g_cond_wait): Added debug information for
|
* gthread.h (g_cond_wait): Added debug information for
|
||||||
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
||||||
|
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gthread.c, gthread.h: Added g_static_mutex_free to allow using
|
||||||
|
GStaticMutexes with limited lifetime without leaking.
|
||||||
|
|
||||||
|
* configure.in: GStaticMutex doesn't have to provide extra space
|
||||||
|
for debugging information for G_ERRORCHECK_MUTEXES, as then the
|
||||||
|
non-default implementation (runtime_mutex) is used anyway.
|
||||||
|
|
||||||
* gthread.h (g_cond_wait): Added debug information for
|
* gthread.h (g_cond_wait): Added debug information for
|
||||||
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
g_mutex_free calls, if G_ERRORCHECK_MUTEXES is defined.
|
||||||
|
|
||||||
|
@ -1479,17 +1479,14 @@ typedef struct _GStaticMutex GStaticMutex;
|
|||||||
struct _GStaticMutex
|
struct _GStaticMutex
|
||||||
{
|
{
|
||||||
struct _GMutex *runtime_mutex;
|
struct _GMutex *runtime_mutex;
|
||||||
struct {
|
|
||||||
union {
|
union {
|
||||||
char pad[$g_mutex_sizeof];
|
char pad[$g_mutex_sizeof];
|
||||||
double dummy_double;
|
double dummy_double;
|
||||||
void *dummy_pointer;
|
void *dummy_pointer;
|
||||||
long dummy_long;
|
long dummy_long;
|
||||||
} mutex;
|
|
||||||
void *debug_info;
|
|
||||||
} static_mutex;
|
} static_mutex;
|
||||||
};
|
};
|
||||||
#define G_STATIC_MUTEX_INIT { NULL, { { { $g_mutex_contents} }, NULL } }
|
#define G_STATIC_MUTEX_INIT { NULL, { { $g_mutex_contents} } }
|
||||||
#define g_static_mutex_get_mutex(mutex) \
|
#define g_static_mutex_get_mutex(mutex) \
|
||||||
(g_thread_use_default_impl ? ((GMutex*) &((mutex)->static_mutex)) : \
|
(g_thread_use_default_impl ? ((GMutex*) &((mutex)->static_mutex)) : \
|
||||||
g_static_mutex_get_mutex_impl (&((mutex)->runtime_mutex)))
|
g_static_mutex_get_mutex_impl (&((mutex)->runtime_mutex)))
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* glib/glib-sections.txt, glib/tmpl/threads.sgml: Added
|
||||||
|
g_static_mutex_free
|
||||||
|
|
||||||
Tue Jan 9 03:10:38 2001 Tim Janik <timj@gtk.org>
|
Tue Jan 9 03:10:38 2001 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* gobject/tmpl/types.sgml: added some function documentations.
|
* gobject/tmpl/types.sgml: added some function documentations.
|
||||||
|
@ -465,6 +465,7 @@ g_static_mutex_lock
|
|||||||
g_static_mutex_trylock
|
g_static_mutex_trylock
|
||||||
g_static_mutex_unlock
|
g_static_mutex_unlock
|
||||||
g_static_mutex_get_mutex
|
g_static_mutex_get_mutex
|
||||||
|
g_static_mutex_free
|
||||||
|
|
||||||
<SUBSECTION>
|
<SUBSECTION>
|
||||||
G_LOCK_DEFINE
|
G_LOCK_DEFINE
|
||||||
|
@ -30,15 +30,6 @@ that every thread has a private instance of (#GPrivate,
|
|||||||
#GStaticPrivate).
|
#GStaticPrivate).
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
|
||||||
Currently there is only as much thread support included in GLib as is
|
|
||||||
necessary to make GLib itself multithread safe. Version 1.4 of GLib
|
|
||||||
will contain full thread support. For now the most portable way to
|
|
||||||
create threads is to require the macro #G_THREADS_IMPL_POSIX to be
|
|
||||||
defined and use POSIX threads then. This will work on almost all
|
|
||||||
platforms (except most notably Solaris and DCE threads.).
|
|
||||||
</para>
|
|
||||||
|
|
||||||
<!-- ##### SECTION See_Also ##### -->
|
<!-- ##### SECTION See_Also ##### -->
|
||||||
<para>
|
<para>
|
||||||
|
|
||||||
@ -51,7 +42,7 @@ This macro is defined, if GLib was compiled with thread support. This
|
|||||||
does not necessarily mean, that there is a thread implementation
|
does not necessarily mean, that there is a thread implementation
|
||||||
available, but the infrastructure is in place and once you provide a
|
available, but the infrastructure is in place and once you provide a
|
||||||
thread implementation to g_thread_init(), GLib will be multithread
|
thread implementation to g_thread_init(), GLib will be multithread
|
||||||
safe. It isn't and can't be, if #G_THREADS_ENABLED is not defined.
|
safe. It isn't and cannot be, if #G_THREADS_ENABLED is not defined.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
|
||||||
@ -343,7 +334,7 @@ access. A first naive implementation would be:
|
|||||||
|
|
||||||
<para>
|
<para>
|
||||||
This looks like it would work, but there is a race condition while
|
This looks like it would work, but there is a race condition while
|
||||||
constructing the mutex and this code can't work reliable. So please do
|
constructing the mutex and this code cannot work reliable. So please do
|
||||||
not use such constructs in your own programs. One working solution is:
|
not use such constructs in your own programs. One working solution is:
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
@ -477,6 +468,17 @@ but can be defined at compile-time. Here is a shorter, easier and
|
|||||||
safer version of our give_me_next_number() example:
|
safer version of our give_me_next_number() example:
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
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.
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
<example>
|
<example>
|
||||||
<title>Using GStaticMutex to simplify thread-safe programming</title>
|
<title>Using GStaticMutex to simplify thread-safe programming</title>
|
||||||
@ -572,6 +574,18 @@ corresponding #GMutex for every #GStaticMutex.
|
|||||||
@Returns: the corresponding #GMutex.
|
@Returns: the corresponding #GMutex.
|
||||||
|
|
||||||
|
|
||||||
|
<!-- ##### FUNCTION g_static_mutex_free ##### -->
|
||||||
|
<para>
|
||||||
|
Releases all resources allocated to a #GStaticMutex. You don't have to
|
||||||
|
call this functions for a #GStaticMutex with an unbounded lifetime,
|
||||||
|
i.e. objects declared 'static', but if you have a #GStaticMutex as a
|
||||||
|
member of a structure and the structure is freed, you should also free
|
||||||
|
the #GStaticMutex.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
@mutex: a #GStaticMutex.
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### MACRO G_LOCK_DEFINE ##### -->
|
<!-- ##### MACRO G_LOCK_DEFINE ##### -->
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -159,6 +159,23 @@ g_static_mutex_get_mutex_impl (GMutex** mutex)
|
|||||||
return *mutex;
|
return *mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
g_static_mutex_free (GStaticMutex* mutex)
|
||||||
|
{
|
||||||
|
GMutex **runtime_mutex;
|
||||||
|
|
||||||
|
g_return_if_fail (mutex);
|
||||||
|
|
||||||
|
/* The runtime_mutex is the first (or only) member of GStaticMutex,
|
||||||
|
* see both versions (of glibconfig.h) in configure.in */
|
||||||
|
runtime_mutex = ((GMutex**)mutex);
|
||||||
|
|
||||||
|
if (*runtime_mutex)
|
||||||
|
g_mutex_free (*runtime_mutex);
|
||||||
|
|
||||||
|
*runtime_mutex = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_static_rec_mutex_lock (GStaticRecMutex* mutex)
|
g_static_rec_mutex_lock (GStaticRecMutex* mutex)
|
||||||
{
|
{
|
||||||
|
@ -227,6 +227,7 @@ void g_thread_set_priority (GThread *thread,
|
|||||||
g_mutex_trylock (g_static_mutex_get_mutex (mutex))
|
g_mutex_trylock (g_static_mutex_get_mutex (mutex))
|
||||||
#define g_static_mutex_unlock(mutex) \
|
#define g_static_mutex_unlock(mutex) \
|
||||||
g_mutex_unlock (g_static_mutex_get_mutex (mutex))
|
g_mutex_unlock (g_static_mutex_get_mutex (mutex))
|
||||||
|
void g_static_mutex_free (GStaticMutex *mutex);
|
||||||
|
|
||||||
struct _GStaticPrivate
|
struct _GStaticPrivate
|
||||||
{
|
{
|
||||||
|
17
gthread.c
17
gthread.c
@ -159,6 +159,23 @@ g_static_mutex_get_mutex_impl (GMutex** mutex)
|
|||||||
return *mutex;
|
return *mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
g_static_mutex_free (GStaticMutex* mutex)
|
||||||
|
{
|
||||||
|
GMutex **runtime_mutex;
|
||||||
|
|
||||||
|
g_return_if_fail (mutex);
|
||||||
|
|
||||||
|
/* The runtime_mutex is the first (or only) member of GStaticMutex,
|
||||||
|
* see both versions (of glibconfig.h) in configure.in */
|
||||||
|
runtime_mutex = ((GMutex**)mutex);
|
||||||
|
|
||||||
|
if (*runtime_mutex)
|
||||||
|
g_mutex_free (*runtime_mutex);
|
||||||
|
|
||||||
|
*runtime_mutex = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
g_static_rec_mutex_lock (GStaticRecMutex* mutex)
|
g_static_rec_mutex_lock (GStaticRecMutex* mutex)
|
||||||
{
|
{
|
||||||
|
@ -227,6 +227,7 @@ void g_thread_set_priority (GThread *thread,
|
|||||||
g_mutex_trylock (g_static_mutex_get_mutex (mutex))
|
g_mutex_trylock (g_static_mutex_get_mutex (mutex))
|
||||||
#define g_static_mutex_unlock(mutex) \
|
#define g_static_mutex_unlock(mutex) \
|
||||||
g_mutex_unlock (g_static_mutex_get_mutex (mutex))
|
g_mutex_unlock (g_static_mutex_get_mutex (mutex))
|
||||||
|
void g_static_mutex_free (GStaticMutex *mutex);
|
||||||
|
|
||||||
struct _GStaticPrivate
|
struct _GStaticPrivate
|
||||||
{
|
{
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
2001-01-30 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* gthread-impl.c (g_thread_init_with_errorcheck_mutexes): Call
|
||||||
|
g_thread_impl_init(), as g_thread_init won't call it.
|
||||||
|
|
||||||
* gthread-impl.c (g_mutex_free_errorcheck_impl): Fixed it for
|
* gthread-impl.c (g_mutex_free_errorcheck_impl): Fixed it for
|
||||||
real. Sorry for this mess. It looked like a real obvious fix, so I
|
real. Sorry for this mess. It looked like a real obvious fix, so I
|
||||||
didn't check. Bad boy. Added some casts to quiet the compiler.
|
didn't check. Bad boy. Added some casts to quiet the compiler.
|
||||||
|
@ -290,6 +290,12 @@ g_thread_init_with_errorcheck_mutexes (GThreadFunctions* init)
|
|||||||
(gboolean (*)(GCond *, GMutex *, GTimeVal *))
|
(gboolean (*)(GCond *, GMutex *, GTimeVal *))
|
||||||
g_cond_timed_wait_errorcheck_impl;
|
g_cond_timed_wait_errorcheck_impl;
|
||||||
|
|
||||||
|
#ifdef HAVE_G_THREAD_IMPL_INIT
|
||||||
|
/* This isn't called in g_thread_init, as it doesn't think to get
|
||||||
|
* the default implementation, so we have to call it on our own. */
|
||||||
|
g_thread_impl_init();
|
||||||
|
#endif
|
||||||
|
|
||||||
g_thread_init (&errorcheck_functions);
|
g_thread_init (&errorcheck_functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user