version bump to 1.1.8, binary age 0, interface age 0.

Wed Dec 16 03:16:58 1998  Tim Janik  <timj@gtk.org>

        * configure.in: version bump to 1.1.8, binary age 0, interface age 0.

        * glib.h: changed g_lock() to G_LOCK(), g_unlock() to G_UNLOCK() and
        g_trylock() to G_TRYLOCK(), since these are macros that expand to
        nothing with --disable-threads.
        changed G_LOCK_DEFINE() to G_LOCK_DECLARE() and introduced
        G_LOCK_DECLARE_STATIC() to achive the results of static G_LOCK_DECLARE().
        changed semantics of g_thread_supported to g_thread_supported() so it
        can be used as a function like g_module_supported(). the actuall
        definition is still a macro that expands into a variable for
        performance reasons though.
        various indentation and coding style cleanups.

        * configure.in: added --enable-threads that defaults to yes.

        * gmutex.c: changed tests g_thread_supported to g_thread_supported (),
        changed variable settings of g_thread_supported
        to g_threads_got_initialized.

        garray.c:
        gcache.c:
        gdataset.c:
        gdate.c:
        ghash.c:
        glist.c:
        gmain.c:
        gnode.c:
        gslist.c:
        gstring.c:
        gtree.c:
        gutils.c:
        changed s/g_lock/G_LOCK/, s/g_unlock/G_UNLOCK/,
        s/static G_LOCK_DEFINE/G_LOCK_DECLARE_STATIC/.
This commit is contained in:
Tim Janik
1998-12-16 05:38:35 +00:00
committed by Tim Janik
parent 06600bd0e6
commit b2e318ff3e
42 changed files with 1223 additions and 941 deletions

View File

@@ -1,3 +1,39 @@
Wed Dec 16 03:16:58 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.8, binary age 0, interface age 0.
* glib.h: changed g_lock() to G_LOCK(), g_unlock() to G_UNLOCK() and
g_trylock() to G_TRYLOCK(), since these are macros that expand to
nothing with --disable-threads.
changed G_LOCK_DEFINE() to G_LOCK_DECLARE() and introduced
G_LOCK_DECLARE_STATIC() to achive the results of static G_LOCK_DECLARE().
changed semantics of g_thread_supported to g_thread_supported() so it
can be used as a function like g_module_supported(). the actuall
definition is still a macro that expands into a variable for
performance reasons though.
various indentation and coding style cleanups.
* configure.in: added --enable-threads that defaults to yes.
* gmutex.c: changed tests g_thread_supported to g_thread_supported (),
changed variable settings of g_thread_supported
to g_threads_got_initialized.
garray.c:
gcache.c:
gdataset.c:
gdate.c:
ghash.c:
glist.c:
gmain.c:
gnode.c:
gslist.c:
gstring.c:
gtree.c:
gutils.c:
changed s/g_lock/G_LOCK/, s/g_unlock/G_UNLOCK/,
s/static G_LOCK_DEFINE/G_LOCK_DECLARE_STATIC/.
Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org> Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.8 * Released GLib 1.1.8

View File

@@ -1,3 +1,39 @@
Wed Dec 16 03:16:58 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.8, binary age 0, interface age 0.
* glib.h: changed g_lock() to G_LOCK(), g_unlock() to G_UNLOCK() and
g_trylock() to G_TRYLOCK(), since these are macros that expand to
nothing with --disable-threads.
changed G_LOCK_DEFINE() to G_LOCK_DECLARE() and introduced
G_LOCK_DECLARE_STATIC() to achive the results of static G_LOCK_DECLARE().
changed semantics of g_thread_supported to g_thread_supported() so it
can be used as a function like g_module_supported(). the actuall
definition is still a macro that expands into a variable for
performance reasons though.
various indentation and coding style cleanups.
* configure.in: added --enable-threads that defaults to yes.
* gmutex.c: changed tests g_thread_supported to g_thread_supported (),
changed variable settings of g_thread_supported
to g_threads_got_initialized.
garray.c:
gcache.c:
gdataset.c:
gdate.c:
ghash.c:
glist.c:
gmain.c:
gnode.c:
gslist.c:
gstring.c:
gtree.c:
gutils.c:
changed s/g_lock/G_LOCK/, s/g_unlock/G_UNLOCK/,
s/static G_LOCK_DEFINE/G_LOCK_DECLARE_STATIC/.
Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org> Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.8 * Released GLib 1.1.8

View File

@@ -1,3 +1,39 @@
Wed Dec 16 03:16:58 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.8, binary age 0, interface age 0.
* glib.h: changed g_lock() to G_LOCK(), g_unlock() to G_UNLOCK() and
g_trylock() to G_TRYLOCK(), since these are macros that expand to
nothing with --disable-threads.
changed G_LOCK_DEFINE() to G_LOCK_DECLARE() and introduced
G_LOCK_DECLARE_STATIC() to achive the results of static G_LOCK_DECLARE().
changed semantics of g_thread_supported to g_thread_supported() so it
can be used as a function like g_module_supported(). the actuall
definition is still a macro that expands into a variable for
performance reasons though.
various indentation and coding style cleanups.
* configure.in: added --enable-threads that defaults to yes.
* gmutex.c: changed tests g_thread_supported to g_thread_supported (),
changed variable settings of g_thread_supported
to g_threads_got_initialized.
garray.c:
gcache.c:
gdataset.c:
gdate.c:
ghash.c:
glist.c:
gmain.c:
gnode.c:
gslist.c:
gstring.c:
gtree.c:
gutils.c:
changed s/g_lock/G_LOCK/, s/g_unlock/G_UNLOCK/,
s/static G_LOCK_DEFINE/G_LOCK_DECLARE_STATIC/.
Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org> Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.8 * Released GLib 1.1.8

View File

@@ -1,3 +1,39 @@
Wed Dec 16 03:16:58 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.8, binary age 0, interface age 0.
* glib.h: changed g_lock() to G_LOCK(), g_unlock() to G_UNLOCK() and
g_trylock() to G_TRYLOCK(), since these are macros that expand to
nothing with --disable-threads.
changed G_LOCK_DEFINE() to G_LOCK_DECLARE() and introduced
G_LOCK_DECLARE_STATIC() to achive the results of static G_LOCK_DECLARE().
changed semantics of g_thread_supported to g_thread_supported() so it
can be used as a function like g_module_supported(). the actuall
definition is still a macro that expands into a variable for
performance reasons though.
various indentation and coding style cleanups.
* configure.in: added --enable-threads that defaults to yes.
* gmutex.c: changed tests g_thread_supported to g_thread_supported (),
changed variable settings of g_thread_supported
to g_threads_got_initialized.
garray.c:
gcache.c:
gdataset.c:
gdate.c:
ghash.c:
glist.c:
gmain.c:
gnode.c:
gslist.c:
gstring.c:
gtree.c:
gutils.c:
changed s/g_lock/G_LOCK/, s/g_unlock/G_UNLOCK/,
s/static G_LOCK_DEFINE/G_LOCK_DECLARE_STATIC/.
Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org> Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.8 * Released GLib 1.1.8

View File

@@ -1,3 +1,39 @@
Wed Dec 16 03:16:58 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.8, binary age 0, interface age 0.
* glib.h: changed g_lock() to G_LOCK(), g_unlock() to G_UNLOCK() and
g_trylock() to G_TRYLOCK(), since these are macros that expand to
nothing with --disable-threads.
changed G_LOCK_DEFINE() to G_LOCK_DECLARE() and introduced
G_LOCK_DECLARE_STATIC() to achive the results of static G_LOCK_DECLARE().
changed semantics of g_thread_supported to g_thread_supported() so it
can be used as a function like g_module_supported(). the actuall
definition is still a macro that expands into a variable for
performance reasons though.
various indentation and coding style cleanups.
* configure.in: added --enable-threads that defaults to yes.
* gmutex.c: changed tests g_thread_supported to g_thread_supported (),
changed variable settings of g_thread_supported
to g_threads_got_initialized.
garray.c:
gcache.c:
gdataset.c:
gdate.c:
ghash.c:
glist.c:
gmain.c:
gnode.c:
gslist.c:
gstring.c:
gtree.c:
gutils.c:
changed s/g_lock/G_LOCK/, s/g_unlock/G_UNLOCK/,
s/static G_LOCK_DEFINE/G_LOCK_DECLARE_STATIC/.
Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org> Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.8 * Released GLib 1.1.8

View File

@@ -1,3 +1,39 @@
Wed Dec 16 03:16:58 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.8, binary age 0, interface age 0.
* glib.h: changed g_lock() to G_LOCK(), g_unlock() to G_UNLOCK() and
g_trylock() to G_TRYLOCK(), since these are macros that expand to
nothing with --disable-threads.
changed G_LOCK_DEFINE() to G_LOCK_DECLARE() and introduced
G_LOCK_DECLARE_STATIC() to achive the results of static G_LOCK_DECLARE().
changed semantics of g_thread_supported to g_thread_supported() so it
can be used as a function like g_module_supported(). the actuall
definition is still a macro that expands into a variable for
performance reasons though.
various indentation and coding style cleanups.
* configure.in: added --enable-threads that defaults to yes.
* gmutex.c: changed tests g_thread_supported to g_thread_supported (),
changed variable settings of g_thread_supported
to g_threads_got_initialized.
garray.c:
gcache.c:
gdataset.c:
gdate.c:
ghash.c:
glist.c:
gmain.c:
gnode.c:
gslist.c:
gstring.c:
gtree.c:
gutils.c:
changed s/g_lock/G_LOCK/, s/g_unlock/G_UNLOCK/,
s/static G_LOCK_DEFINE/G_LOCK_DECLARE_STATIC/.
Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org> Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.8 * Released GLib 1.1.8

View File

@@ -1,3 +1,39 @@
Wed Dec 16 03:16:58 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.8, binary age 0, interface age 0.
* glib.h: changed g_lock() to G_LOCK(), g_unlock() to G_UNLOCK() and
g_trylock() to G_TRYLOCK(), since these are macros that expand to
nothing with --disable-threads.
changed G_LOCK_DEFINE() to G_LOCK_DECLARE() and introduced
G_LOCK_DECLARE_STATIC() to achive the results of static G_LOCK_DECLARE().
changed semantics of g_thread_supported to g_thread_supported() so it
can be used as a function like g_module_supported(). the actuall
definition is still a macro that expands into a variable for
performance reasons though.
various indentation and coding style cleanups.
* configure.in: added --enable-threads that defaults to yes.
* gmutex.c: changed tests g_thread_supported to g_thread_supported (),
changed variable settings of g_thread_supported
to g_threads_got_initialized.
garray.c:
gcache.c:
gdataset.c:
gdate.c:
ghash.c:
glist.c:
gmain.c:
gnode.c:
gslist.c:
gstring.c:
gtree.c:
gutils.c:
changed s/g_lock/G_LOCK/, s/g_unlock/G_UNLOCK/,
s/static G_LOCK_DEFINE/G_LOCK_DECLARE_STATIC/.
Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org> Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.8 * Released GLib 1.1.8

View File

@@ -1,3 +1,39 @@
Wed Dec 16 03:16:58 1998 Tim Janik <timj@gtk.org>
* configure.in: version bump to 1.1.8, binary age 0, interface age 0.
* glib.h: changed g_lock() to G_LOCK(), g_unlock() to G_UNLOCK() and
g_trylock() to G_TRYLOCK(), since these are macros that expand to
nothing with --disable-threads.
changed G_LOCK_DEFINE() to G_LOCK_DECLARE() and introduced
G_LOCK_DECLARE_STATIC() to achive the results of static G_LOCK_DECLARE().
changed semantics of g_thread_supported to g_thread_supported() so it
can be used as a function like g_module_supported(). the actuall
definition is still a macro that expands into a variable for
performance reasons though.
various indentation and coding style cleanups.
* configure.in: added --enable-threads that defaults to yes.
* gmutex.c: changed tests g_thread_supported to g_thread_supported (),
changed variable settings of g_thread_supported
to g_threads_got_initialized.
garray.c:
gcache.c:
gdataset.c:
gdate.c:
ghash.c:
glist.c:
gmain.c:
gnode.c:
gslist.c:
gstring.c:
gtree.c:
gutils.c:
changed s/g_lock/G_LOCK/, s/g_unlock/G_UNLOCK/,
s/static G_LOCK_DEFINE/G_LOCK_DECLARE_STATIC/.
Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org> Tue Dec 15 23:16:05 CST 1998 Shawn T. Amundson <amundson@gtk.org>
* Released GLib 1.1.8 * Released GLib 1.1.8

View File

@@ -38,6 +38,7 @@
#undef ENABLE_MEM_PROFILE #undef ENABLE_MEM_PROFILE
#undef G_COMPILED_WITH_DEBUGGING #undef G_COMPILED_WITH_DEBUGGING
#undef G_THREADS_ENABLED
#undef HAVE_BROKEN_WCTYPE #undef HAVE_BROKEN_WCTYPE
#undef HAVE_DOPRNT #undef HAVE_DOPRNT
#undef HAVE_FLOAT_H #undef HAVE_FLOAT_H

View File

@@ -57,11 +57,16 @@ AM_MAINTAINER_MODE
AC_CANONICAL_HOST AC_CANONICAL_HOST
AC_ARG_ENABLE(debug, [ --enable-debug=[no/minimum/yes] turn on debugging [default=minimum]],,enable_debug=minimum) AC_ARG_ENABLE(debug, [ --enable-debug=[no/minimum/yes] turn on debugging [default=minimum]],,enable_debug=minimum)
AC_ARG_ENABLE(mem_check, [ --enable-mem-check=[no/yes] turn on malloc/free sanity checking [default=no]],,enable_mem_check=no) AC_ARG_ENABLE(mem_check, [ --enable-mem-check turn on malloc/free sanity checking [default=no]],,enable_mem_check=no)
AC_ARG_ENABLE(mem_profile, [ --enable-mem-profile=[no/yes] turn on malloc profiling atexit [default=no]],,enable_mem_profile=no) AC_ARG_ENABLE(mem_profile, [ --enable-mem-profile turn on malloc profiling atexit [default=no]],,enable_mem_profile=no)
AC_ARG_ENABLE(ansi, [ --enable-ansi turn on strict ansi [default=no]], AC_ARG_ENABLE(ansi, [ --enable-ansi turn on strict ansi [default=no]],
, enable_ansi=no) , enable_ansi=no)
AC_ARG_ENABLE(threads, [ --enable-threads turn on basic thread support [default=yes]
([=no] will override --with-threads)],,enable_threads=yes)
if test "x$enable_threads" != "xyes"; then
enable_threads=no
fi
AC_MSG_CHECKING(whether to enable memory checking) AC_MSG_CHECKING(whether to enable memory checking)
if test "x$enable_mem_check" = "xyes"; then if test "x$enable_mem_check" = "xyes"; then
@@ -513,13 +518,16 @@ dnl ***********************
dnl *** g_thread checks *** dnl *** g_thread checks ***
dnl *********************** dnl ***********************
AC_ARG_WITH(threads, [ --with-threads=[none/posix/solaris/nspr] specify a thread implementation to use.], AC_ARG_WITH(threads, [ --with-threads=[none/posix/solaris/nspr] specify a thread implementation to use],
if test "x$with_threads" = x; then if test "x$with_threads" = x; then
want_threads=yes want_threads=yes
else else
want_threads=$with_threads want_threads=$with_threads
fi, fi,
want_threads=yes) want_threads=yes)
if test "x$enable_threads" = "xno"; then
want_threads=no
fi
if test "x$want_threads" = "xnone"; then if test "x$want_threads" = "xnone"; then
want_threads=no want_threads=no
fi fi
@@ -813,6 +821,8 @@ outfile_EOF
cat >>$outfile <<outfile_EOF cat >>$outfile <<outfile_EOF
$g_enable_threads_def G_THREADS_ENABLED
/* definitions for the default mutex implementation */ /* definitions for the default mutex implementation */
outfile_EOF outfile_EOF
@@ -1053,6 +1063,11 @@ if test x$glib_working_wctype = xno; then
#define G_HAVE_BROKEN_WCTYPE 1" #define G_HAVE_BROKEN_WCTYPE 1"
fi fi
case x$enable_threads in
xyes) g_enable_threads_def="#define";;
*) g_enable_threads_def="#undef ";;
esac
case $have_threads in case $have_threads in
posix) posix)
g_mutex_has_default=yes g_mutex_has_default=yes

View File

@@ -46,7 +46,7 @@ static void g_array_maybe_expand (GRealArray *array,
gint len); gint len);
static GMemChunk *array_mem_chunk = NULL; static GMemChunk *array_mem_chunk = NULL;
static G_LOCK_DEFINE(array_mem_chunk); G_LOCK_DECLARE_STATIC (array_mem_chunk);
GArray* GArray*
g_array_new (gboolean zero_terminated, g_array_new (gboolean zero_terminated,
@@ -55,14 +55,14 @@ g_array_new (gboolean zero_terminated,
{ {
GRealArray *array; GRealArray *array;
g_lock (array_mem_chunk); G_LOCK (array_mem_chunk);
if (!array_mem_chunk) if (!array_mem_chunk)
array_mem_chunk = g_mem_chunk_new ("array mem chunk", array_mem_chunk = g_mem_chunk_new ("array mem chunk",
sizeof (GRealArray), sizeof (GRealArray),
1024, G_ALLOC_AND_FREE); 1024, G_ALLOC_AND_FREE);
array = g_chunk_new (GRealArray, array_mem_chunk); array = g_chunk_new (GRealArray, array_mem_chunk);
g_unlock (array_mem_chunk); G_UNLOCK (array_mem_chunk);
array->data = NULL; array->data = NULL;
array->len = 0; array->len = 0;
@@ -81,9 +81,9 @@ g_array_free (GArray *array,
if (free_segment) if (free_segment)
g_free (array->data); g_free (array->data);
g_lock (array_mem_chunk); G_LOCK (array_mem_chunk);
g_mem_chunk_free (array_mem_chunk, array); g_mem_chunk_free (array_mem_chunk, array);
g_unlock (array_mem_chunk); G_UNLOCK (array_mem_chunk);
} }
GArray* GArray*
@@ -250,7 +250,7 @@ static void g_ptr_array_maybe_expand (GRealPtrArray *array,
gint len); gint len);
static GMemChunk *ptr_array_mem_chunk = NULL; static GMemChunk *ptr_array_mem_chunk = NULL;
static G_LOCK_DEFINE(ptr_array_mem_chunk); G_LOCK_DECLARE_STATIC (ptr_array_mem_chunk);
GPtrArray* GPtrArray*
@@ -258,14 +258,14 @@ g_ptr_array_new (void)
{ {
GRealPtrArray *array; GRealPtrArray *array;
g_lock (ptr_array_mem_chunk); G_LOCK (ptr_array_mem_chunk);
if (!ptr_array_mem_chunk) if (!ptr_array_mem_chunk)
ptr_array_mem_chunk = g_mem_chunk_new ("array mem chunk", ptr_array_mem_chunk = g_mem_chunk_new ("array mem chunk",
sizeof (GRealPtrArray), sizeof (GRealPtrArray),
1024, G_ALLOC_AND_FREE); 1024, G_ALLOC_AND_FREE);
array = g_chunk_new (GRealPtrArray, ptr_array_mem_chunk); array = g_chunk_new (GRealPtrArray, ptr_array_mem_chunk);
g_unlock (ptr_array_mem_chunk); G_UNLOCK (ptr_array_mem_chunk);
array->pdata = NULL; array->pdata = NULL;
array->len = 0; array->len = 0;
@@ -283,9 +283,9 @@ g_ptr_array_free (GPtrArray *array,
if (free_segment) if (free_segment)
g_free (array->pdata); g_free (array->pdata);
g_lock (ptr_array_mem_chunk); G_LOCK (ptr_array_mem_chunk);
g_mem_chunk_free (ptr_array_mem_chunk, array); g_mem_chunk_free (ptr_array_mem_chunk, array);
g_unlock (ptr_array_mem_chunk); G_UNLOCK (ptr_array_mem_chunk);
} }
static void static void

View File

@@ -61,7 +61,7 @@ static void g_cache_node_destroy (GCacheNode *node);
static GMemChunk *node_mem_chunk = NULL; static GMemChunk *node_mem_chunk = NULL;
static G_LOCK_DEFINE(node_mem_chunk); G_LOCK_DECLARE_STATIC (node_mem_chunk);
GCache* GCache*
g_cache_new (GCacheNewFunc value_new_func, g_cache_new (GCacheNewFunc value_new_func,
@@ -198,13 +198,13 @@ g_cache_node_new (gpointer value)
{ {
GCacheNode *node; GCacheNode *node;
g_lock (node_mem_chunk); G_LOCK (node_mem_chunk);
if (!node_mem_chunk) if (!node_mem_chunk)
node_mem_chunk = g_mem_chunk_new ("cache node mem chunk", sizeof (GCacheNode), node_mem_chunk = g_mem_chunk_new ("cache node mem chunk", sizeof (GCacheNode),
1024, G_ALLOC_AND_FREE); 1024, G_ALLOC_AND_FREE);
node = g_chunk_new (GCacheNode, node_mem_chunk); node = g_chunk_new (GCacheNode, node_mem_chunk);
g_unlock (node_mem_chunk); G_UNLOCK (node_mem_chunk);
node->value = value; node->value = value;
node->ref_count = 1; node->ref_count = 1;
@@ -215,7 +215,7 @@ g_cache_node_new (gpointer value)
static void static void
g_cache_node_destroy (GCacheNode *node) g_cache_node_destroy (GCacheNode *node)
{ {
g_lock (node_mem_chunk); G_LOCK (node_mem_chunk);
g_mem_chunk_free (node_mem_chunk, node); g_mem_chunk_free (node_mem_chunk, node);
g_unlock (node_mem_chunk); G_UNLOCK (node_mem_chunk);
} }

View File

@@ -67,7 +67,7 @@ static inline GQuark g_quark_new (gchar *string);
/* --- variables --- */ /* --- variables --- */
static G_LOCK_DEFINE(g_dataset_global); G_LOCK_DECLARE_STATIC (g_dataset_global);
static GHashTable *g_dataset_location_ht = NULL; static GHashTable *g_dataset_location_ht = NULL;
static GDataset *g_dataset_cached = NULL; /* should this be static GDataset *g_dataset_cached = NULL; /* should this be
threadspecific? */ threadspecific? */
@@ -76,7 +76,7 @@ static GMemChunk *g_data_mem_chunk = NULL;
static GData *g_data_cache = NULL; static GData *g_data_cache = NULL;
static guint g_data_cache_length = 0; static guint g_data_cache_length = 0;
static G_LOCK_DEFINE(g_quark_global); G_LOCK_DECLARE_STATIC (g_quark_global);
static GHashTable *g_quark_ht = NULL; static GHashTable *g_quark_ht = NULL;
static gchar **g_quarks = NULL; static gchar **g_quarks = NULL;
static GQuark g_quark_seq_id = 0; static GQuark g_quark_seq_id = 0;
@@ -121,13 +121,13 @@ g_datalist_clear (GData **datalist)
{ {
g_return_if_fail (datalist != NULL); g_return_if_fail (datalist != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (!g_dataset_location_ht) if (!g_dataset_location_ht)
g_data_initialize (); g_data_initialize ();
while (*datalist) while (*datalist)
g_datalist_clear_i (datalist); g_datalist_clear_i (datalist);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
/* HOLDS: g_dataset_global_lock */ /* HOLDS: g_dataset_global_lock */
@@ -174,7 +174,7 @@ g_dataset_destroy (gconstpointer dataset_location)
{ {
g_return_if_fail (dataset_location != NULL); g_return_if_fail (dataset_location != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (g_dataset_location_ht) if (g_dataset_location_ht)
{ {
register GDataset *dataset; register GDataset *dataset;
@@ -183,7 +183,7 @@ g_dataset_destroy (gconstpointer dataset_location)
if (dataset) if (dataset)
g_dataset_destroy_internal (dataset); g_dataset_destroy_internal (dataset);
} }
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
/* HOLDS: g_dataset_global_lock */ /* HOLDS: g_dataset_global_lock */
@@ -312,7 +312,7 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
return; return;
} }
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (!g_dataset_location_ht) if (!g_dataset_location_ht)
g_data_initialize (); g_data_initialize ();
@@ -328,7 +328,7 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
} }
g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset); g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
void void
@@ -348,12 +348,12 @@ g_datalist_id_set_data_full (GData **datalist,
return; return;
} }
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (!g_dataset_location_ht) if (!g_dataset_location_ht)
g_data_initialize (); g_data_initialize ();
g_data_set_internal (datalist, key_id, data, destroy_func, NULL); g_data_set_internal (datalist, key_id, data, destroy_func, NULL);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
void void
@@ -362,7 +362,7 @@ g_dataset_id_remove_no_notify (gconstpointer dataset_location,
{ {
g_return_if_fail (dataset_location != NULL); g_return_if_fail (dataset_location != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (key_id && g_dataset_location_ht) if (key_id && g_dataset_location_ht)
{ {
GDataset *dataset; GDataset *dataset;
@@ -371,7 +371,7 @@ g_dataset_id_remove_no_notify (gconstpointer dataset_location,
if (dataset) if (dataset)
g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset); g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset);
} }
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
void void
@@ -380,10 +380,10 @@ g_datalist_id_remove_no_notify (GData **datalist,
{ {
g_return_if_fail (datalist != NULL); g_return_if_fail (datalist != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (key_id && g_dataset_location_ht) if (key_id && g_dataset_location_ht)
g_data_set_internal (datalist, key_id, NULL, (GDestroyNotify) 42, NULL); g_data_set_internal (datalist, key_id, NULL, (GDestroyNotify) 42, NULL);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
gpointer gpointer
@@ -392,7 +392,7 @@ g_dataset_id_get_data (gconstpointer dataset_location,
{ {
g_return_val_if_fail (dataset_location != NULL, NULL); g_return_val_if_fail (dataset_location != NULL, NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (key_id && g_dataset_location_ht) if (key_id && g_dataset_location_ht)
{ {
register GDataset *dataset; register GDataset *dataset;
@@ -405,12 +405,12 @@ g_dataset_id_get_data (gconstpointer dataset_location,
for (list = dataset->datalist; list; list = list->next) for (list = dataset->datalist; list; list = list->next)
if (list->id == key_id) if (list->id == key_id)
{ {
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
return list->data; return list->data;
} }
} }
} }
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
return NULL; return NULL;
} }
@@ -443,11 +443,11 @@ g_dataset_foreach (gconstpointer dataset_location,
g_return_if_fail (dataset_location != NULL); g_return_if_fail (dataset_location != NULL);
g_return_if_fail (func != NULL); g_return_if_fail (func != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (g_dataset_location_ht) if (g_dataset_location_ht)
{ {
dataset = g_dataset_lookup (dataset_location); dataset = g_dataset_lookup (dataset_location);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
if (dataset) if (dataset)
{ {
register GData *list; register GData *list;
@@ -458,7 +458,7 @@ g_dataset_foreach (gconstpointer dataset_location,
} }
else else
{ {
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
} }
@@ -510,10 +510,10 @@ g_quark_try_string (const gchar *string)
GQuark quark = 0; GQuark quark = 0;
g_return_val_if_fail (string != NULL, 0); g_return_val_if_fail (string != NULL, 0);
g_lock (g_quark_global); G_LOCK (g_quark_global);
if (g_quark_ht) if (g_quark_ht)
quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string)); quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string));
g_unlock (g_quark_global); G_UNLOCK (g_quark_global);
return quark; return quark;
} }
@@ -525,7 +525,7 @@ g_quark_from_string (const gchar *string)
g_return_val_if_fail (string != NULL, 0); g_return_val_if_fail (string != NULL, 0);
g_lock (g_quark_global); G_LOCK (g_quark_global);
if (g_quark_ht) if (g_quark_ht)
quark = (gulong) g_hash_table_lookup (g_quark_ht, string); quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
else else
@@ -536,7 +536,7 @@ g_quark_from_string (const gchar *string)
if (!quark) if (!quark)
quark = g_quark_new (g_strdup (string)); quark = g_quark_new (g_strdup (string));
g_unlock (g_quark_global); G_UNLOCK (g_quark_global);
return quark; return quark;
} }
@@ -548,7 +548,7 @@ g_quark_from_static_string (const gchar *string)
g_return_val_if_fail (string != NULL, 0); g_return_val_if_fail (string != NULL, 0);
g_lock (g_quark_global); G_LOCK (g_quark_global);
if (g_quark_ht) if (g_quark_ht)
quark = (gulong) g_hash_table_lookup (g_quark_ht, string); quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
else else
@@ -559,7 +559,7 @@ g_quark_from_static_string (const gchar *string)
if (!quark) if (!quark)
quark = g_quark_new ((gchar*) string); quark = g_quark_new ((gchar*) string);
g_unlock (g_quark_global); G_UNLOCK (g_quark_global);
return quark; return quark;
} }
@@ -568,10 +568,10 @@ gchar*
g_quark_to_string (GQuark quark) g_quark_to_string (GQuark quark)
{ {
gchar* result = NULL; gchar* result = NULL;
g_lock (g_quark_global); G_LOCK (g_quark_global);
if (quark > 0 && quark <= g_quark_seq_id) if (quark > 0 && quark <= g_quark_seq_id)
result = g_quarks[quark - 1]; result = g_quarks[quark - 1];
g_unlock (g_quark_global); G_UNLOCK (g_quark_global);
return result; return result;
} }

View File

@@ -388,7 +388,7 @@ g_date_clear (GDate *d, guint ndates)
memset (d, 0x0, ndates*sizeof (GDate)); memset (d, 0x0, ndates*sizeof (GDate));
} }
static G_LOCK_DEFINE(g_date_global); G_LOCK_DECLARE_STATIC (g_date_global);
/* These are for the parser, output to the user should use * /* These are for the parser, output to the user should use *
* g_date_strftime () - this creates more never-freed memory to annoy * g_date_strftime () - this creates more never-freed memory to annoy
@@ -652,7 +652,7 @@ g_date_set_parse (GDate *d,
/* set invalid */ /* set invalid */
g_date_clear (d, 1); g_date_clear (d, 1);
g_lock (g_date_global); G_LOCK (g_date_global);
g_date_prepare_to_parse (str, &pt); g_date_prepare_to_parse (str, &pt);
@@ -664,7 +664,7 @@ g_date_set_parse (GDate *d,
if (pt.num_ints == 4) if (pt.num_ints == 4)
{ {
g_unlock (g_date_global); G_UNLOCK (g_date_global);
return; /* presumably a typo; bail out. */ return; /* presumably a typo; bail out. */
} }
@@ -782,7 +782,7 @@ g_date_set_parse (GDate *d,
else else
g_message ("Rejected DMY %u %u %u", day, m, y); g_message ("Rejected DMY %u %u %u", day, m, y);
#endif #endif
g_unlock (g_date_global); G_UNLOCK (g_date_global);
} }
void void

14
ghash.c
View File

@@ -57,7 +57,7 @@ static void g_hash_node_destroy (GHashNode *hash_node);
static void g_hash_nodes_destroy (GHashNode *hash_node); static void g_hash_nodes_destroy (GHashNode *hash_node);
static G_LOCK_DEFINE(g_hash_global); G_LOCK_DECLARE_STATIC (g_hash_global);
static GMemChunk *node_mem_chunk = NULL; static GMemChunk *node_mem_chunk = NULL;
static GHashNode *node_free_list = NULL; static GHashNode *node_free_list = NULL;
@@ -345,7 +345,7 @@ g_hash_node_new (gpointer key,
{ {
GHashNode *hash_node; GHashNode *hash_node;
g_lock (g_hash_global); G_LOCK (g_hash_global);
if (node_free_list) if (node_free_list)
{ {
hash_node = node_free_list; hash_node = node_free_list;
@@ -360,7 +360,7 @@ g_hash_node_new (gpointer key,
hash_node = g_chunk_new (GHashNode, node_mem_chunk); hash_node = g_chunk_new (GHashNode, node_mem_chunk);
} }
g_unlock (g_hash_global); G_UNLOCK (g_hash_global);
hash_node->key = key; hash_node->key = key;
hash_node->value = value; hash_node->value = value;
@@ -372,10 +372,10 @@ g_hash_node_new (gpointer key,
static void static void
g_hash_node_destroy (GHashNode *hash_node) g_hash_node_destroy (GHashNode *hash_node)
{ {
g_lock (g_hash_global); G_LOCK (g_hash_global);
hash_node->next = node_free_list; hash_node->next = node_free_list;
node_free_list = hash_node; node_free_list = hash_node;
g_unlock (g_hash_global); G_UNLOCK (g_hash_global);
} }
static void static void
@@ -391,8 +391,8 @@ g_hash_nodes_destroy (GHashNode *hash_node)
while (node->next) while (node->next)
node = node->next; node = node->next;
g_lock (g_hash_global); G_LOCK (g_hash_global);
node->next = node_free_list; node->next = node_free_list;
node_free_list = hash_node; node_free_list = hash_node;
g_unlock (g_hash_global); G_UNLOCK (g_hash_global);
} }

607
glib.h
View File

@@ -2007,7 +2007,8 @@ gint g_scanner_stat_mode (const gchar *filename);
} G_STMT_END } G_STMT_END
/* Completion */ /* GCompletion
*/
struct _GCompletion struct _GCompletion
{ {
@@ -2030,28 +2031,32 @@ GList* g_completion_complete (GCompletion* cmp,
void g_completion_free (GCompletion* cmp); void g_completion_free (GCompletion* cmp);
/* GDate
*
/* Date calculations (not time for now, to be resolved). These are a * Date calculations (not time for now, to be resolved). These are a
* mutant combination of Steffen Beyer's DateCalc routines * mutant combination of Steffen Beyer's DateCalc routines
* (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's * (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's
* date routines (written for in-house software). Written by Havoc * date routines (written for in-house software). Written by Havoc
* Pennington <hp@pobox.com> * Pennington <hp@pobox.com>
*/ */
/* this enum is used to specify order of appearance in parsed date typedef guint16 GDateYear;
* strings typedef guint8 GDateDay; /* day of the month */
*/ typedef struct _GDate GDate;
/* make struct tm known without having to include time.h */
struct tm;
typedef enum { /* enum used to specify order of appearance in parsed date strings */
typedef enum
{
G_DATE_DAY = 0, G_DATE_DAY = 0,
G_DATE_MONTH = 1, G_DATE_MONTH = 1,
G_DATE_YEAR = 2 G_DATE_YEAR = 2
} GDateDMY; } GDateDMY;
/* These other types specify the actual values. */ /* actual week and month values */
typedef enum
typedef enum { {
G_DATE_BAD_WEEKDAY = 0, G_DATE_BAD_WEEKDAY = 0,
G_DATE_MONDAY = 1, G_DATE_MONDAY = 1,
G_DATE_TUESDAY = 2, G_DATE_TUESDAY = 2,
@@ -2061,8 +2066,8 @@ typedef enum {
G_DATE_SATURDAY = 6, G_DATE_SATURDAY = 6,
G_DATE_SUNDAY = 7 G_DATE_SUNDAY = 7
} GDateWeekday; } GDateWeekday;
typedef enum
typedef enum { {
G_DATE_BAD_MONTH = 0, G_DATE_BAD_MONTH = 0,
G_DATE_JANUARY = 1, G_DATE_JANUARY = 1,
G_DATE_FEBRUARY = 2, G_DATE_FEBRUARY = 2,
@@ -2078,22 +2083,17 @@ typedef enum {
G_DATE_DECEMBER = 12 G_DATE_DECEMBER = 12
} GDateMonth; } GDateMonth;
typedef guint16 GDateYear;
typedef guint8 GDateDay; /* day of the month */
#define G_DATE_BAD_JULIAN 0U #define G_DATE_BAD_JULIAN 0U
#define G_DATE_BAD_DAY 0U #define G_DATE_BAD_DAY 0U
#define G_DATE_BAD_YEAR 0U #define G_DATE_BAD_YEAR 0U
typedef struct _GDate GDate;
/* Note: directly manipulating structs is generally a bad idea, but /* Note: directly manipulating structs is generally a bad idea, but
* in this case it's an *incredibly* bad idea, because all or part * in this case it's an *incredibly* bad idea, because all or part
* of this struct can be invalid at any given time. Use the functions, * of this struct can be invalid at any given time. Use the functions,
* or you will get hosed, I promise. * or you will get hosed, I promise.
*/ */
struct _GDate
struct _GDate { {
guint julian_days : 32; /* julian days representation - we use a guint julian_days : 32; /* julian days representation - we use a
* bitfield hoping that 64 bit platforms * bitfield hoping that 64 bit platforms
* will pack this whole struct in one big * will pack this whole struct in one big
@@ -2109,105 +2109,95 @@ struct _GDate {
guint year : 16; guint year : 16;
}; };
/* _new with no args returns an invalid date, you then have to _set() stuff /* g_date_new() returns an invalid date, you then have to _set() stuff
* to get a usable object. You can also allocate a GDate statically, * to get a usable object. You can also allocate a GDate statically,
* then call g_date_clear() to initialize. * then call g_date_clear() to initialize.
*/ */
GDate* g_date_new (void); GDate* g_date_new (void);
GDate* g_date_new_dmy (GDateDay d, GDate* g_date_new_dmy (GDateDay day,
GDateMonth m, GDateMonth month,
GDateYear y); GDateYear year);
GDate* g_date_new_julian (guint32 julian_day); GDate* g_date_new_julian (guint32 julian_day);
void g_date_free (GDate *d); void g_date_free (GDate *date);
/* check g_date_valid() after doing an operation that might fail, like /* check g_date_valid() after doing an operation that might fail, like
* _parse. Almost all g_date operations are undefined on invalid * _parse. Almost all g_date operations are undefined on invalid
* dates (the exceptions are the mutators, since you need those to * dates (the exceptions are the mutators, since you need those to
* return to validity). * return to validity).
*/ */
gboolean g_date_valid (GDate *date);
gboolean g_date_valid_day (GDateDay day);
gboolean g_date_valid_month (GDateMonth month);
gboolean g_date_valid_year (GDateYear year);
gboolean g_date_valid_weekday (GDateWeekday weekday);
gboolean g_date_valid_julian (guint32 julian_date);
gboolean g_date_valid_dmy (GDateDay day,
GDateMonth month,
GDateYear year);
gboolean g_date_valid (GDate *d); GDateWeekday g_date_weekday (GDate *date);
gboolean g_date_valid_day (GDateDay d); GDateMonth g_date_month (GDate *date);
gboolean g_date_valid_month (GDateMonth m); GDateYear g_date_year (GDate *date);
gboolean g_date_valid_year (GDateYear y); GDateDay g_date_day (GDate *date);
gboolean g_date_valid_weekday (GDateWeekday w); guint32 g_date_julian (GDate *date);
gboolean g_date_valid_julian (guint32 j); guint g_date_day_of_year (GDate *date);
gboolean g_date_valid_dmy (GDateDay d,
GDateMonth m,
GDateYear y);
GDateWeekday g_date_weekday (GDate *d);
GDateMonth g_date_month (GDate *d);
GDateYear g_date_year (GDate *d);
GDateDay g_date_day (GDate *d);
guint32 g_date_julian (GDate *d);
guint g_date_day_of_year (GDate *d);
/* First monday/sunday is the start of week 1; if we haven't reached /* First monday/sunday is the start of week 1; if we haven't reached
* that day, return 0. These are not ISO weeks of the year; that * that day, return 0. These are not ISO weeks of the year; that
* routine should be added. * routine needs to be added.
* these functions return the number of weeks, starting on the
* corrsponding day
*/ */
guint g_date_monday_week_of_year (GDate *date);
guint g_date_monday_week_of_year (GDate *d); /* # weeks, starting on Monday */ guint g_date_sunday_week_of_year (GDate *date);
guint g_date_sunday_week_of_year (GDate *d); /* # weeks, starting on Sunday */
/* If you create a static date struct you need to clear it to get it /* If you create a static date struct you need to clear it to get it
* in a sane state before use. You can clear a whole array at * in a sane state before use. You can clear a whole array at
* once with the ndates argument. * once with the ndates argument.
*/ */
void g_date_clear (GDate *date,
void g_date_clear (GDate *d, guint n_dates);
guint ndates);
/* The parse routine is meant for dates typed in by a user, so it /* The parse routine is meant for dates typed in by a user, so it
* permits many formats but tries to catch common typos. If your data * permits many formats but tries to catch common typos. If your data
* needs to be strictly validated, it is not an appropriate function. * needs to be strictly validated, it is not an appropriate function.
*/ */
void g_date_set_parse (GDate *date,
void g_date_set_parse (GDate *d,
const gchar *str); const gchar *str);
void g_date_set_time (GDate *date,
void g_date_set_time (GDate *d,
GTime time); GTime time);
void g_date_set_month (GDate *date,
void g_date_set_month (GDate *d, GDateMonth month);
GDateMonth m); void g_date_set_day (GDate *date,
void g_date_set_day (GDate *d,
GDateDay day); GDateDay day);
void g_date_set_year (GDate *d, void g_date_set_year (GDate *date,
GDateYear y); GDateYear year);
void g_date_set_dmy (GDate *d, void g_date_set_dmy (GDate *date,
GDateDay day, GDateDay day,
GDateMonth m, GDateMonth month,
GDateYear y); GDateYear y);
void g_date_set_julian (GDate *date,
void g_date_set_julian (GDate *d, guint32 julian_date);
guint32 j); gboolean g_date_is_first_of_month (GDate *date);
gboolean g_date_is_last_of_month (GDate *date);
gboolean g_date_is_first_of_month (GDate *d);
gboolean g_date_is_last_of_month (GDate *d);
/* To go forward by some number of weeks just go forward weeks*7 days */ /* To go forward by some number of weeks just go forward weeks*7 days */
void g_date_add_days (GDate *d, void g_date_add_days (GDate *date,
guint ndays); guint n_days);
void g_date_subtract_days (GDate *d, void g_date_subtract_days (GDate *date,
guint ndays); guint n_days);
/* If you add/sub months while day > 28, the day might change */ /* If you add/sub months while day > 28, the day might change */
void g_date_add_months (GDate *d, void g_date_add_months (GDate *date,
guint nmonths); guint n_months);
void g_date_subtract_months (GDate *d, void g_date_subtract_months (GDate *date,
guint nmonths); guint n_months);
/* If it's feb 29, changing years can move you to the 28th */ /* If it's feb 29, changing years can move you to the 28th */
void g_date_add_years (GDate *d, void g_date_add_years (GDate *date,
guint nyears); guint n_years);
void g_date_subtract_years (GDate *d, void g_date_subtract_years (GDate *date,
guint nyears); guint n_years);
gboolean g_date_is_leap_year (GDateYear year); gboolean g_date_is_leap_year (GDateYear year);
guint8 g_date_days_in_month (GDateMonth month, guint8 g_date_days_in_month (GDateMonth month,
GDateYear year); GDateYear year);
@@ -2217,11 +2207,7 @@ guint8 g_date_sunday_weeks_in_year (GDateYear year);
/* qsort-friendly (with a cast...) */ /* qsort-friendly (with a cast...) */
gint g_date_compare (GDate *lhs, gint g_date_compare (GDate *lhs,
GDate *rhs); GDate *rhs);
void g_date_to_struct_tm (GDate *date,
/* make struct tm known without having to include time.h */
struct tm;
void g_date_to_struct_tm (GDate *d,
struct tm *tm); struct tm *tm);
/* Just like strftime() except you can only use date-related formats. /* Just like strftime() except you can only use date-related formats.
@@ -2230,12 +2216,12 @@ void g_date_to_struct_tm (GDate *d,
gsize g_date_strftime (gchar *s, gsize g_date_strftime (gchar *s,
gsize slen, gsize slen,
const gchar *format, const gchar *format,
GDate *d); GDate *date);
/* GRelation
*
/* GRelation: Indexed Relations. Imagine a really simple table in a * Indexed Relations. Imagine a really simple table in a
* database. Relations are not ordered. This data type is meant for * database. Relations are not ordered. This data type is meant for
* maintaining a N-way mapping. * maintaining a N-way mapping.
* *
@@ -2295,47 +2281,47 @@ gpointer g_tuples_index (GTuples *tuples,
guint g_spaced_primes_closest (guint num); guint g_spaced_primes_closest (guint num);
/* IO Channels /* GIOChannel
*/ */
typedef struct _GIOFuncs GIOFuncs; typedef struct _GIOFuncs GIOFuncs;
typedef enum
typedef enum { {
G_IO_ERROR_NONE, G_IO_ERROR_NONE,
G_IO_ERROR_AGAIN, G_IO_ERROR_AGAIN,
G_IO_ERROR_INVAL, G_IO_ERROR_INVAL,
G_IO_ERROR_UNKNOWN G_IO_ERROR_UNKNOWN
} GIOError; } GIOError;
typedef enum
typedef enum { {
G_SEEK_CUR, G_SEEK_CUR,
G_SEEK_SET, G_SEEK_SET,
G_SEEK_END G_SEEK_END
} GSeekType; } GSeekType;
typedef enum
typedef enum { {
G_IO_IN G_IO_IN
#ifdef POLLIN #ifdef POLLIN
= POLLIN = POLLIN
#endif #endif
,G_IO_OUT , G_IO_OUT
#ifdef POLLOUT #ifdef POLLOUT
= POLLOUT = POLLOUT
#endif #endif
,G_IO_PRI , G_IO_PRI
#ifdef POLLPRI #ifdef POLLPRI
= POLLPRI = POLLPRI
#endif #endif
,G_IO_ERR , G_IO_ERR
#ifdef POLLERR #ifdef POLLERR
= POLLERR = POLLERR
#endif #endif
,G_IO_HUP , G_IO_HUP
#ifdef POLLHUP #ifdef POLLHUP
= POLLHUP = POLLHUP
#endif #endif
,G_IO_NVAL , G_IO_NVAL
#ifdef POLLNVAL #ifdef POLLNVAL
= POLLNVAL = POLLNVAL
#endif #endif
@@ -2351,27 +2337,27 @@ struct _GIOChannel
typedef gboolean (*GIOFunc) (GIOChannel *source, typedef gboolean (*GIOFunc) (GIOChannel *source,
GIOCondition condition, GIOCondition condition,
gpointer data); gpointer data);
struct _GIOFuncs
struct _GIOFuncs { {
GIOError (*io_read) (GIOChannel *channel, GIOError (*io_read) (GIOChannel *channel,
gchar *buf, gchar *buf,
guint count, guint count,
guint *bytes_read); guint *bytes_read);
GIOError (*io_write) (GIOChannel *channel, GIOError (*io_write) (GIOChannel *channel,
gchar *buf, gchar *buf,
guint count, guint count,
guint *bytes_written); guint *bytes_written);
GIOError (*io_seek) (GIOChannel *channel, GIOError (*io_seek) (GIOChannel *channel,
gint offset, gint offset,
GSeekType type); GSeekType type);
void (*io_close) (GIOChannel *channel); void (*io_close) (GIOChannel *channel);
guint (*io_add_watch) (GIOChannel *channel, guint (*io_add_watch) (GIOChannel *channel,
gint priority, gint priority,
GIOCondition condition, GIOCondition condition,
GIOFunc func, GIOFunc func,
gpointer user_data, gpointer user_data,
GDestroyNotify notify); GDestroyNotify notify);
void (*io_free) (GIOChannel *channel); void (*io_free) (GIOChannel *channel);
}; };
void g_io_channel_init (GIOChannel *channel); void g_io_channel_init (GIOChannel *channel);
@@ -2400,19 +2386,20 @@ guint g_io_add_watch (GIOChannel *channel,
GIOFunc func, GIOFunc func,
gpointer user_data); gpointer user_data);
/* Main loop */
typedef struct _GTimeVal GTimeVal; /* Main loop
typedef struct _GSourceFuncs GSourceFuncs; */
typedef struct _GTimeVal GTimeVal;
typedef struct _GSourceFuncs GSourceFuncs;
typedef struct _GMainLoop GMainLoop; /* Opaque */
typedef struct _GMainLoop GMainLoop; /* Opaque */ struct _GTimeVal
{
struct _GTimeVal {
glong tv_sec; glong tv_sec;
glong tv_usec; glong tv_usec;
}; };
struct _GSourceFuncs
struct _GSourceFuncs { {
gboolean (*prepare) (gpointer source_data, gboolean (*prepare) (gpointer source_data,
GTimeVal *current_time, GTimeVal *current_time,
gint *timeout); gint *timeout);
@@ -2424,10 +2411,9 @@ struct _GSourceFuncs {
GDestroyNotify destroy; GDestroyNotify destroy;
}; };
typedef gboolean (*GSourceFunc) (gpointer data); typedef gboolean (*GSourceFunc) (gpointer data);
/* Hooks for adding to the main loop */ /* Hooks for adding to the main loop */
guint g_source_add (gint priority, guint g_source_add (gint priority,
gboolean can_recurse, gboolean can_recurse,
GSourceFuncs *funcs, GSourceFuncs *funcs,
@@ -2438,67 +2424,65 @@ void g_source_remove (guint tag);
void g_source_remove_by_user_data (gpointer user_data); void g_source_remove_by_user_data (gpointer user_data);
void g_source_remove_by_source_data (gpointer source_data); void g_source_remove_by_source_data (gpointer source_data);
void g_get_current_time (GTimeVal *result);
void g_get_current_time (GTimeVal *result);
/* Running the main loop */ /* Running the main loop */
GMainLoop* g_main_new (void);
GMainLoop *g_main_new (void); void g_main_run (GMainLoop *loop);
void g_main_run (GMainLoop *loop); void g_main_quit (GMainLoop *loop);
void g_main_quit (GMainLoop *loop); void g_main_destroy (GMainLoop *loop);
void g_main_destroy (GMainLoop *loop);
/* Run a single iteration of the mainloop. If block is FALSE, /* Run a single iteration of the mainloop. If block is FALSE,
* will never block * will never block
*/ */
gboolean g_main_iteration (gboolean block); gboolean g_main_iteration (gboolean may_block);
/* See if any events are pending /* See if any events are pending */
*/ gboolean g_main_pending (void);
gboolean g_main_pending ();
/* Idles and timeouts */ /* Idles and timeouts */
guint g_timeout_add_full (gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify);
guint g_timeout_add (guint interval,
GSourceFunc function,
gpointer data);
guint g_idle_add (GSourceFunc function,
gpointer data);
guint g_idle_add_full (gint priority,
GSourceFunc function,
gpointer data,
GDestroyNotify destroy);
guint g_timeout_add_full (gint priority, /* GPollFD
guint interval, *
GSourceFunc function, * Unix-specific IO and main loop calls
gpointer data, */
GDestroyNotify notify);
guint g_timeout_add (guint interval,
GSourceFunc function,
gpointer data);
guint g_idle_add (GSourceFunc function,
gpointer data);
guint g_idle_add_full (gint priority,
GSourceFunc function,
gpointer data,
GDestroyNotify destroy);
/* Unix-specific IO and main loop calls */
typedef struct _GPollFD GPollFD; typedef struct _GPollFD GPollFD;
typedef gint (*GPollFunc) (GPollFD *ufds,
struct _GPollFD { guint nfsd,
gint fd; gint timeout);
gushort events; struct _GPollFD
gushort revents; {
gint fd;
gushort events;
gushort revents;
}; };
typedef gint (*GPollFunc) (GPollFD *ufds, guint nfsd, gint timeout);
void g_main_poll_add (gint priority, void g_main_poll_add (gint priority,
GPollFD *fd); GPollFD *fd);
void g_main_poll_remove (GPollFD *fd); void g_main_poll_remove (GPollFD *fd);
void g_main_set_poll_func (GPollFunc func); void g_main_set_poll_func (GPollFunc func);
GIOChannel* g_io_channel_unix_new (int fd);
GIOChannel *g_io_channel_unix_new (int fd);
gint g_io_channel_unix_get_fd (GIOChannel *channel); gint g_io_channel_unix_get_fd (GIOChannel *channel);
#if 0 /* old IO Channels */
/* old IO Channels */
#if 0
/* IO Channels. /* IO Channels.
* These are used for plug-in communication in the GIMP, for instance. * These are used for plug-in communication in the GIMP, for instance.
* On Unix, it's simply an encapsulated file descriptor (a pipe). * On Unix, it's simply an encapsulated file descriptor (a pipe).
@@ -2521,7 +2505,6 @@ struct _GIOChannel
*/ */
#endif #endif
}; };
GIOChannel *g_iochannel_new (gint fd); GIOChannel *g_iochannel_new (gint fd);
void g_iochannel_free (GIOChannel *channel); void g_iochannel_free (GIOChannel *channel);
void g_iochannel_close_and_free (GIOChannel *channel); void g_iochannel_close_and_free (GIOChannel *channel);
@@ -2529,16 +2512,14 @@ void g_iochannel_wakeup_peer (GIOChannel *channel);
#ifndef NATIVE_WIN32 #ifndef NATIVE_WIN32
# define g_iochannel_wakeup_peer(channel) G_STMT_START { } G_STMT_END # define g_iochannel_wakeup_peer(channel) G_STMT_START { } G_STMT_END
#endif #endif
#endif /* old IO Channels */
#endif /* old IO Channels */
/* Windows emulation stubs for common unix functions /* Windows emulation stubs for common unix functions
*/ */
#ifdef NATIVE_WIN32 #ifdef NATIVE_WIN32
# define MAXPATHLEN 1024
#define MAXPATHLEN 1024 # ifdef _MSC_VER
#ifdef _MSC_VER
typedef int pid_t; typedef int pid_t;
/* These POSIXish functions are available in the Microsoft C library /* These POSIXish functions are available in the Microsoft C library
@@ -2553,30 +2534,27 @@ typedef int pid_t;
* For some functions, we provide emulators in glib, which are prefixed * For some functions, we provide emulators in glib, which are prefixed
* with gwin_. * with gwin_.
*/ */
#define getcwd _getcwd # define getcwd _getcwd
#define getpid _getpid # define getpid _getpid
#define access _access # define access _access
#define open _open # define open _open
#define read _read # define read _read
#define write _write # define write _write
#define lseek _lseek # define lseek _lseek
#define close _close # define close _close
#define pipe(phandles) _pipe (phandles, 4096, _O_BINARY) # define pipe(phandles) _pipe (phandles, 4096, _O_BINARY)
#define popen _popen # define popen _popen
#define pclose _pclose # define pclose _pclose
#define fdopen _fdopen # define fdopen _fdopen
#define ftruncate(fd, size) gwin_ftruncate (fd, size) # define ftruncate(fd, size) gwin_ftruncate (fd, size)
#define opendir gwin_opendir # define opendir gwin_opendir
#define readdir gwin_readdir # define readdir gwin_readdir
#define rewinddir gwin_rewinddir # define rewinddir gwin_rewinddir
#define closedir gwin_closedir # define closedir gwin_closedir
# define NAME_MAX 255
#define NAME_MAX 255
struct DIR struct DIR
{ {
gchar *dir_name; gchar *dir_name;
gboolean just_opened; gboolean just_opened;
guint find_file_handle; guint find_file_handle;
gpointer find_file_data; gpointer find_file_data;
@@ -2586,7 +2564,6 @@ struct dirent
{ {
gchar d_name[NAME_MAX + 1]; gchar d_name[NAME_MAX + 1];
}; };
/* emulation functions */ /* emulation functions */
extern int gwin_ftruncate (gint f, extern int gwin_ftruncate (gint f,
guint size); guint size);
@@ -2594,145 +2571,153 @@ DIR* gwin_opendir (const gchar *dirname);
struct dirent* gwin_readdir (DIR *dir); struct dirent* gwin_readdir (DIR *dir);
void gwin_rewinddir (DIR *dir); void gwin_rewinddir (DIR *dir);
gint gwin_closedir (DIR *dir); gint gwin_closedir (DIR *dir);
# endif /* _MSC_VER */
#endif /* NATIVE_WIN32 */
#endif /* _MSC_VER */
#endif /* NATIVE_WIN32 */
/* functions for thread support for glib. */
typedef struct _GMutex GMutex;
typedef struct _GCond GCond;
typedef struct _GPrivate GPrivate;
typedef struct _GStaticPrivate GStaticPrivate;
/* GLib Thread support
*/
typedef struct _GMutex GMutex;
typedef struct _GCond GCond;
typedef struct _GPrivate GPrivate;
typedef struct _GStaticPrivate GStaticPrivate;
typedef struct _GThreadFunctions GThreadFunctions; typedef struct _GThreadFunctions GThreadFunctions;
struct _GThreadFunctions struct _GThreadFunctions
{ {
GMutex* (*mutex_new) (void); GMutex* (*mutex_new) (void);
void (*mutex_lock) (GMutex* mutex); void (*mutex_lock) (GMutex *mutex);
gboolean (*mutex_trylock) (GMutex* mutex); gboolean (*mutex_trylock) (GMutex *mutex);
void (*mutex_unlock) (GMutex* mutex); void (*mutex_unlock) (GMutex *mutex);
void (*mutex_free) (GMutex* mutex); void (*mutex_free) (GMutex *mutex);
GCond* (*cond_new) (void); GCond* (*cond_new) (void);
void (*cond_signal) (GCond* cond); void (*cond_signal) (GCond *cond);
void (*cond_broadcast) (GCond* cond); void (*cond_broadcast) (GCond *cond);
void (*cond_wait) (GCond* cond, GMutex* mutex); void (*cond_wait) (GCond *cond,
gboolean (*cond_timed_wait) (GCond* cond, GMutex* mutex, GMutex *mutex);
GTimeVal *end_time); gboolean (*cond_timed_wait) (GCond *cond,
void (*cond_free) (GCond* cond); GMutex *mutex,
GPrivate* (*private_new) (GDestroyNotify destructor); GTimeVal *end_time);
gpointer (*private_get) (GPrivate* private_key); void (*cond_free) (GCond *cond);
void (*private_set) (GPrivate* private_key, gpointer value); GPrivate* (*private_new) (GDestroyNotify destructor);
gpointer (*private_get) (GPrivate *private_key);
void (*private_set) (GPrivate *private_key,
gpointer data);
}; };
GUTILS_C_VAR GThreadFunctions g_thread_functions_for_glib_use; GUTILS_C_VAR GThreadFunctions g_thread_functions_for_glib_use;
GUTILS_C_VAR gboolean g_thread_use_default_impl; GUTILS_C_VAR gboolean g_thread_use_default_impl;
GUTILS_C_VAR gboolean g_thread_supported; GUTILS_C_VAR gboolean g_threads_got_initialized;
/* initializes the mutex/cond/private implementation for glib, might /* initializes the mutex/cond/private implementation for glib, might
* only be called once, and must not be called directly or indirectly * only be called once, and must not be called directly or indirectly
* from another glib-function, e.g. as a callback. */ * from another glib-function, e.g. as a callback.
void g_thread_init(GThreadFunctions* init);
/* Internal functions for fallback static mutex implementation
* Please don't use it directly
*/ */
GMutex* g_static_mutex_get_mutex_impl(GMutex** mutex); void g_thread_init (GThreadFunctions *vtable);
#define G_USE_THREAD_FUNC_UNCOND(name,arg) \ /* internal function for fallback static mutex implementation */
(*g_thread_functions_for_glib_use.name)arg GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
#define G_USE_THREAD_FUNC(name,fail,arg) \
(g_thread_supported ? G_USE_THREAD_FUNC_UNCOND(name,arg) : (fail))
/* shorthands for conditional and unconditional function calls */
#define G_THREAD_UF(name, arglist) \
(*g_thread_functions_for_glib_use . name) arglist
#define G_THREAD_CF(name, fail, arg) \
(g_thread_supported () ? G_THREAD_UF (name, arg) : (fail))
/* keep in mind, all those mutexes and static mutexes are not /* keep in mind, all those mutexes and static mutexes are not
* recursive in general, don't rely on that */ * recursive in general, don't rely on that
#define g_mutex_new() G_USE_THREAD_FUNC_UNCOND(mutex_new,()) */
#define g_mutex_lock(mutex) G_USE_THREAD_FUNC(mutex_lock,(void)0,(mutex)) #define g_thread_supported() (g_threads_got_initialized)
#define g_mutex_trylock(mutex) G_USE_THREAD_FUNC(mutex_trylock,TRUE,(mutex)) #define g_mutex_new() G_THREAD_UF (mutex_new, ())
#define g_mutex_unlock(mutex) G_USE_THREAD_FUNC(mutex_unlock,(void)0,(mutex)) #define g_mutex_lock(mutex) G_THREAD_CF (mutex_lock, (void)0, (mutex))
#define g_mutex_free(mutex) G_USE_THREAD_FUNC(mutex_free,(void)0,(mutex)) #define g_mutex_trylock(mutex) G_THREAD_CF (mutex_trylock, TRUE, (mutex))
#define g_cond_new() G_USE_THREAD_FUNC_UNCOND(cond_new,()) #define g_mutex_unlock(mutex) G_THREAD_CF (mutex_unlock, (void)0, (mutex))
#define g_cond_signal(cond) G_USE_THREAD_FUNC(cond_signal,(void)0,(cond)) #define g_mutex_free(mutex) G_THREAD_CF (mutex_free, (void)0, (mutex))
#define g_cond_broadcast(cond) G_USE_THREAD_FUNC(cond_broadcast,(void)0,(cond)) #define g_cond_new() G_THREAD_UF (cond_new, ())
#define g_cond_wait(cond,mutex) G_USE_THREAD_FUNC(cond_wait,(void)0,(cond,mutex)) #define g_cond_signal(cond) G_THREAD_CF (cond_signal, (void)0, (cond))
#define g_cond_timed_wait(cond,mutex,abs_time) \ #define g_cond_broadcast(cond) G_THREAD_CF (cond_broadcast, (void)0, (cond))
G_USE_THREAD_FUNC(cond_timed_wait,TRUE,(cond,mutex,abs_time)) #define g_cond_wait(cond, mutex) G_THREAD_CF (cond_wait, (void)0, (cond, \
#define g_cond_free(cond) G_USE_THREAD_FUNC(cond_free,(void)0,(cond)) mutex))
#define g_cond_free(cond) G_THREAD_CF (cond_free, (void)0, (cond))
#define g_private_new(destructor) \ #define g_cond_timed_wait(cond, mutex, abs_time) G_THREAD_CF (cond_timed_wait, \
G_USE_THREAD_FUNC_UNCOND(private_new,(destructor)) TRUE, \
#define g_private_get(private_key) \ (cond, mutex, \
G_USE_THREAD_FUNC(private_get,((gpointer)private_key),(private_key)) abs_time))
#define g_private_set(private_key,value) \ #define g_private_new(destructor) G_THREAD_UF (private_new, (destructor))
G_USE_THREAD_FUNC(private_set,(void)(private_key=(GPrivate *)(value)), \ #define g_private_get(private_key) G_THREAD_CF (private_get, \
(private_key,value)) ((gpointer)private_key), \
(private_key))
/* GStaticMutex'es can be statically initialized with the value #define g_private_set(private_key, value) G_THREAD_CF (private_set, \
(void) (private_key = \
(GPrivate*) (value)), \
(private_key, value))
/* GStaticMutexes can be statically initialized with the value
* G_STATIC_MUTEX_INIT, and then they can directly be used, that is * G_STATIC_MUTEX_INIT, and then they can directly be used, that is
* much easier, than having to explicitly allocate the mutex before * much easier, than having to explicitly allocate the mutex before
* use */ * use
*/
#define g_static_mutex_lock(mutex) \ #define g_static_mutex_lock(mutex) \
g_mutex_lock( g_static_mutex_get_mutex(mutex) ) g_mutex_lock (g_static_mutex_get_mutex (mutex))
#define g_static_mutex_trylock(mutex) \ #define g_static_mutex_trylock(mutex) \
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))
struct _GStaticPrivate struct _GStaticPrivate
{ {
guint index; guint index;
}; };
#define G_STATIC_PRIVATE_INIT { 0 } #define G_STATIC_PRIVATE_INIT { 0 }
gpointer g_static_private_get (GStaticPrivate *private_key);
void g_static_private_set (GStaticPrivate *private_key,
gpointer data,
GDestroyNotify notify);
gpointer g_static_private_get (GStaticPrivate* private_key); /* these are some convenience macros that expand to nothing if GLib was
void g_static_private_set (GStaticPrivate *private_key, * configured with --deisable-threads. for using StaticMutexes, you
gpointer data, * declare them with G_LOCK_DECLARE_STATIC (name) or G_LOCK_DECLARE (name)
GDestroyNotify notify); * if you need to export the mutex. name is a unique identifier for the
* protected varibale or code portion. locking, testing and unlocking of
* such mutexes can be done with G_LOCK(), G_UNLOCK() and G_TRYLOCK()
* respectively.
*/
extern gboolean glib_dummy_decl;
#define G_LOCK_NAME(name) (g__ ## name ## _lock)
#ifdef G_THREADS_ENABLED
# define G_LOCK_DECLARE_STATIC(name) static G_LOCK_DECLARE (name)
# define G_LOCK_DECLARE(name) \
GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT
/* these are some convenience macros, for using StaticMutex'es, you # ifdef G_DEBUG_LOCKS
* define them by G_LOCK_DEFINE(name), where name could for example be the # define G_LOCK(name) G_STMT_START{ \
* name of the protected varibale, and you (un)lock them with g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
* g_(un)lock(name) */ "file %s: line %d (%s): locking: %s ", \
#define g_lock_name(name) (name ## _lock) __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
#define G_LOCK_DEFINE(name) GStaticMutex g_lock_name(name)=G_STATIC_MUTEX_INIT #name); \
g_static_mutex_lock (G_LOCK_NAME (name)); \
#ifdef G_DEBUG_LOCKS
#define g_lock(name) G_STMT_START{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_MESSAGE, \
"file %s: line %d (%s): locking: %s ", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#name); \
g_static_mutex_lock(g_lock_name(name)); \
}G_STMT_END }G_STMT_END
#define g_unlock(name) G_STMT_START{ \ # define G_UNLOCK(name) G_STMT_START{ \
g_log (G_LOG_DOMAIN, \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
G_LOG_LEVEL_MESSAGE, \ "file %s: line %d (%s): unlocking: %s ", \
"file %s: line %d (%s): unlocking: %s ", \ __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
__FILE__, \ #name); \
__LINE__, \ g_static_mutex_unlock (G_LOCK_NAME (name)); \
__PRETTY_FUNCTION__, \
#name); \
g_static_mutex_unlock(g_lock_name(name)); \
}G_STMT_END }G_STMT_END
#define g_trylock(name) G_STMT_START{ \ # define G_TRYLOCK(name) G_STMT_START{ \
g_log (G_LOG_DOMAIN, \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
G_LOG_LEVEL_MESSAGE, \ "file %s: line %d (%s): try locking: %s ", \
"file %s: line %d (%s): try locking: %s ", \ __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
__FILE__, \ #name); \
__LINE__, \ }G_STMT_END, g_static_mutex_trylock (G_LOCK_NAME (name))
__PRETTY_FUNCTION__, \ # else /* !G_DEBUG_LOCKS */
#name); \ # define G_LOCK(name) g_static_mutex_lock (G_LOCK_NAME (name))
}G_STMT_END, g_static_mutex_trylock(g_lock_name(name)) # define G_UNLOCK(name) g_static_mutex_unlock (G_LOCK_NAME (name))
#else /* !G_DEBUG_LOCKS */ # define G_TRYLOCK(name) g_static_mutex_trylock (G_LOCK_NAME (name))
#define g_lock(name) g_static_mutex_lock(g_lock_name(name)) # endif /* !G_DEBUG_LOCKS */
#define g_unlock(name) g_static_mutex_unlock(g_lock_name(name)) #else /* !G_THREADS_ENABLED */
#define g_trylock(name) g_static_mutex_trylock(g_lock_name(name)) # define G_LOCK_DECLARE_STATIC(name) extern gboolean glib_dummy_decl
#endif # define G_LOCK_DECLARE(name) extern gboolean glib_dummy_decl
# define G_LOCK(name)
# define G_UNLOCK(name)
# define G_TRYLOCK(name) (FALSE)
#endif /* !G_THREADS_ENABLED */
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -46,7 +46,7 @@ static void g_array_maybe_expand (GRealArray *array,
gint len); gint len);
static GMemChunk *array_mem_chunk = NULL; static GMemChunk *array_mem_chunk = NULL;
static G_LOCK_DEFINE(array_mem_chunk); G_LOCK_DECLARE_STATIC (array_mem_chunk);
GArray* GArray*
g_array_new (gboolean zero_terminated, g_array_new (gboolean zero_terminated,
@@ -55,14 +55,14 @@ g_array_new (gboolean zero_terminated,
{ {
GRealArray *array; GRealArray *array;
g_lock (array_mem_chunk); G_LOCK (array_mem_chunk);
if (!array_mem_chunk) if (!array_mem_chunk)
array_mem_chunk = g_mem_chunk_new ("array mem chunk", array_mem_chunk = g_mem_chunk_new ("array mem chunk",
sizeof (GRealArray), sizeof (GRealArray),
1024, G_ALLOC_AND_FREE); 1024, G_ALLOC_AND_FREE);
array = g_chunk_new (GRealArray, array_mem_chunk); array = g_chunk_new (GRealArray, array_mem_chunk);
g_unlock (array_mem_chunk); G_UNLOCK (array_mem_chunk);
array->data = NULL; array->data = NULL;
array->len = 0; array->len = 0;
@@ -81,9 +81,9 @@ g_array_free (GArray *array,
if (free_segment) if (free_segment)
g_free (array->data); g_free (array->data);
g_lock (array_mem_chunk); G_LOCK (array_mem_chunk);
g_mem_chunk_free (array_mem_chunk, array); g_mem_chunk_free (array_mem_chunk, array);
g_unlock (array_mem_chunk); G_UNLOCK (array_mem_chunk);
} }
GArray* GArray*
@@ -250,7 +250,7 @@ static void g_ptr_array_maybe_expand (GRealPtrArray *array,
gint len); gint len);
static GMemChunk *ptr_array_mem_chunk = NULL; static GMemChunk *ptr_array_mem_chunk = NULL;
static G_LOCK_DEFINE(ptr_array_mem_chunk); G_LOCK_DECLARE_STATIC (ptr_array_mem_chunk);
GPtrArray* GPtrArray*
@@ -258,14 +258,14 @@ g_ptr_array_new (void)
{ {
GRealPtrArray *array; GRealPtrArray *array;
g_lock (ptr_array_mem_chunk); G_LOCK (ptr_array_mem_chunk);
if (!ptr_array_mem_chunk) if (!ptr_array_mem_chunk)
ptr_array_mem_chunk = g_mem_chunk_new ("array mem chunk", ptr_array_mem_chunk = g_mem_chunk_new ("array mem chunk",
sizeof (GRealPtrArray), sizeof (GRealPtrArray),
1024, G_ALLOC_AND_FREE); 1024, G_ALLOC_AND_FREE);
array = g_chunk_new (GRealPtrArray, ptr_array_mem_chunk); array = g_chunk_new (GRealPtrArray, ptr_array_mem_chunk);
g_unlock (ptr_array_mem_chunk); G_UNLOCK (ptr_array_mem_chunk);
array->pdata = NULL; array->pdata = NULL;
array->len = 0; array->len = 0;
@@ -283,9 +283,9 @@ g_ptr_array_free (GPtrArray *array,
if (free_segment) if (free_segment)
g_free (array->pdata); g_free (array->pdata);
g_lock (ptr_array_mem_chunk); G_LOCK (ptr_array_mem_chunk);
g_mem_chunk_free (ptr_array_mem_chunk, array); g_mem_chunk_free (ptr_array_mem_chunk, array);
g_unlock (ptr_array_mem_chunk); G_UNLOCK (ptr_array_mem_chunk);
} }
static void static void

View File

@@ -61,7 +61,7 @@ static void g_cache_node_destroy (GCacheNode *node);
static GMemChunk *node_mem_chunk = NULL; static GMemChunk *node_mem_chunk = NULL;
static G_LOCK_DEFINE(node_mem_chunk); G_LOCK_DECLARE_STATIC (node_mem_chunk);
GCache* GCache*
g_cache_new (GCacheNewFunc value_new_func, g_cache_new (GCacheNewFunc value_new_func,
@@ -198,13 +198,13 @@ g_cache_node_new (gpointer value)
{ {
GCacheNode *node; GCacheNode *node;
g_lock (node_mem_chunk); G_LOCK (node_mem_chunk);
if (!node_mem_chunk) if (!node_mem_chunk)
node_mem_chunk = g_mem_chunk_new ("cache node mem chunk", sizeof (GCacheNode), node_mem_chunk = g_mem_chunk_new ("cache node mem chunk", sizeof (GCacheNode),
1024, G_ALLOC_AND_FREE); 1024, G_ALLOC_AND_FREE);
node = g_chunk_new (GCacheNode, node_mem_chunk); node = g_chunk_new (GCacheNode, node_mem_chunk);
g_unlock (node_mem_chunk); G_UNLOCK (node_mem_chunk);
node->value = value; node->value = value;
node->ref_count = 1; node->ref_count = 1;
@@ -215,7 +215,7 @@ g_cache_node_new (gpointer value)
static void static void
g_cache_node_destroy (GCacheNode *node) g_cache_node_destroy (GCacheNode *node)
{ {
g_lock (node_mem_chunk); G_LOCK (node_mem_chunk);
g_mem_chunk_free (node_mem_chunk, node); g_mem_chunk_free (node_mem_chunk, node);
g_unlock (node_mem_chunk); G_UNLOCK (node_mem_chunk);
} }

View File

@@ -67,7 +67,7 @@ static inline GQuark g_quark_new (gchar *string);
/* --- variables --- */ /* --- variables --- */
static G_LOCK_DEFINE(g_dataset_global); G_LOCK_DECLARE_STATIC (g_dataset_global);
static GHashTable *g_dataset_location_ht = NULL; static GHashTable *g_dataset_location_ht = NULL;
static GDataset *g_dataset_cached = NULL; /* should this be static GDataset *g_dataset_cached = NULL; /* should this be
threadspecific? */ threadspecific? */
@@ -76,7 +76,7 @@ static GMemChunk *g_data_mem_chunk = NULL;
static GData *g_data_cache = NULL; static GData *g_data_cache = NULL;
static guint g_data_cache_length = 0; static guint g_data_cache_length = 0;
static G_LOCK_DEFINE(g_quark_global); G_LOCK_DECLARE_STATIC (g_quark_global);
static GHashTable *g_quark_ht = NULL; static GHashTable *g_quark_ht = NULL;
static gchar **g_quarks = NULL; static gchar **g_quarks = NULL;
static GQuark g_quark_seq_id = 0; static GQuark g_quark_seq_id = 0;
@@ -121,13 +121,13 @@ g_datalist_clear (GData **datalist)
{ {
g_return_if_fail (datalist != NULL); g_return_if_fail (datalist != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (!g_dataset_location_ht) if (!g_dataset_location_ht)
g_data_initialize (); g_data_initialize ();
while (*datalist) while (*datalist)
g_datalist_clear_i (datalist); g_datalist_clear_i (datalist);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
/* HOLDS: g_dataset_global_lock */ /* HOLDS: g_dataset_global_lock */
@@ -174,7 +174,7 @@ g_dataset_destroy (gconstpointer dataset_location)
{ {
g_return_if_fail (dataset_location != NULL); g_return_if_fail (dataset_location != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (g_dataset_location_ht) if (g_dataset_location_ht)
{ {
register GDataset *dataset; register GDataset *dataset;
@@ -183,7 +183,7 @@ g_dataset_destroy (gconstpointer dataset_location)
if (dataset) if (dataset)
g_dataset_destroy_internal (dataset); g_dataset_destroy_internal (dataset);
} }
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
/* HOLDS: g_dataset_global_lock */ /* HOLDS: g_dataset_global_lock */
@@ -312,7 +312,7 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
return; return;
} }
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (!g_dataset_location_ht) if (!g_dataset_location_ht)
g_data_initialize (); g_data_initialize ();
@@ -328,7 +328,7 @@ g_dataset_id_set_data_full (gconstpointer dataset_location,
} }
g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset); g_data_set_internal (&dataset->datalist, key_id, data, destroy_func, dataset);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
void void
@@ -348,12 +348,12 @@ g_datalist_id_set_data_full (GData **datalist,
return; return;
} }
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (!g_dataset_location_ht) if (!g_dataset_location_ht)
g_data_initialize (); g_data_initialize ();
g_data_set_internal (datalist, key_id, data, destroy_func, NULL); g_data_set_internal (datalist, key_id, data, destroy_func, NULL);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
void void
@@ -362,7 +362,7 @@ g_dataset_id_remove_no_notify (gconstpointer dataset_location,
{ {
g_return_if_fail (dataset_location != NULL); g_return_if_fail (dataset_location != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (key_id && g_dataset_location_ht) if (key_id && g_dataset_location_ht)
{ {
GDataset *dataset; GDataset *dataset;
@@ -371,7 +371,7 @@ g_dataset_id_remove_no_notify (gconstpointer dataset_location,
if (dataset) if (dataset)
g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset); g_data_set_internal (&dataset->datalist, key_id, NULL, (GDestroyNotify) 42, dataset);
} }
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
void void
@@ -380,10 +380,10 @@ g_datalist_id_remove_no_notify (GData **datalist,
{ {
g_return_if_fail (datalist != NULL); g_return_if_fail (datalist != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (key_id && g_dataset_location_ht) if (key_id && g_dataset_location_ht)
g_data_set_internal (datalist, key_id, NULL, (GDestroyNotify) 42, NULL); g_data_set_internal (datalist, key_id, NULL, (GDestroyNotify) 42, NULL);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
gpointer gpointer
@@ -392,7 +392,7 @@ g_dataset_id_get_data (gconstpointer dataset_location,
{ {
g_return_val_if_fail (dataset_location != NULL, NULL); g_return_val_if_fail (dataset_location != NULL, NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (key_id && g_dataset_location_ht) if (key_id && g_dataset_location_ht)
{ {
register GDataset *dataset; register GDataset *dataset;
@@ -405,12 +405,12 @@ g_dataset_id_get_data (gconstpointer dataset_location,
for (list = dataset->datalist; list; list = list->next) for (list = dataset->datalist; list; list = list->next)
if (list->id == key_id) if (list->id == key_id)
{ {
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
return list->data; return list->data;
} }
} }
} }
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
return NULL; return NULL;
} }
@@ -443,11 +443,11 @@ g_dataset_foreach (gconstpointer dataset_location,
g_return_if_fail (dataset_location != NULL); g_return_if_fail (dataset_location != NULL);
g_return_if_fail (func != NULL); g_return_if_fail (func != NULL);
g_lock (g_dataset_global); G_LOCK (g_dataset_global);
if (g_dataset_location_ht) if (g_dataset_location_ht)
{ {
dataset = g_dataset_lookup (dataset_location); dataset = g_dataset_lookup (dataset_location);
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
if (dataset) if (dataset)
{ {
register GData *list; register GData *list;
@@ -458,7 +458,7 @@ g_dataset_foreach (gconstpointer dataset_location,
} }
else else
{ {
g_unlock (g_dataset_global); G_UNLOCK (g_dataset_global);
} }
} }
@@ -510,10 +510,10 @@ g_quark_try_string (const gchar *string)
GQuark quark = 0; GQuark quark = 0;
g_return_val_if_fail (string != NULL, 0); g_return_val_if_fail (string != NULL, 0);
g_lock (g_quark_global); G_LOCK (g_quark_global);
if (g_quark_ht) if (g_quark_ht)
quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string)); quark = GPOINTER_TO_UINT (g_hash_table_lookup (g_quark_ht, string));
g_unlock (g_quark_global); G_UNLOCK (g_quark_global);
return quark; return quark;
} }
@@ -525,7 +525,7 @@ g_quark_from_string (const gchar *string)
g_return_val_if_fail (string != NULL, 0); g_return_val_if_fail (string != NULL, 0);
g_lock (g_quark_global); G_LOCK (g_quark_global);
if (g_quark_ht) if (g_quark_ht)
quark = (gulong) g_hash_table_lookup (g_quark_ht, string); quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
else else
@@ -536,7 +536,7 @@ g_quark_from_string (const gchar *string)
if (!quark) if (!quark)
quark = g_quark_new (g_strdup (string)); quark = g_quark_new (g_strdup (string));
g_unlock (g_quark_global); G_UNLOCK (g_quark_global);
return quark; return quark;
} }
@@ -548,7 +548,7 @@ g_quark_from_static_string (const gchar *string)
g_return_val_if_fail (string != NULL, 0); g_return_val_if_fail (string != NULL, 0);
g_lock (g_quark_global); G_LOCK (g_quark_global);
if (g_quark_ht) if (g_quark_ht)
quark = (gulong) g_hash_table_lookup (g_quark_ht, string); quark = (gulong) g_hash_table_lookup (g_quark_ht, string);
else else
@@ -559,7 +559,7 @@ g_quark_from_static_string (const gchar *string)
if (!quark) if (!quark)
quark = g_quark_new ((gchar*) string); quark = g_quark_new ((gchar*) string);
g_unlock (g_quark_global); G_UNLOCK (g_quark_global);
return quark; return quark;
} }
@@ -568,10 +568,10 @@ gchar*
g_quark_to_string (GQuark quark) g_quark_to_string (GQuark quark)
{ {
gchar* result = NULL; gchar* result = NULL;
g_lock (g_quark_global); G_LOCK (g_quark_global);
if (quark > 0 && quark <= g_quark_seq_id) if (quark > 0 && quark <= g_quark_seq_id)
result = g_quarks[quark - 1]; result = g_quarks[quark - 1];
g_unlock (g_quark_global); G_UNLOCK (g_quark_global);
return result; return result;
} }

View File

@@ -388,7 +388,7 @@ g_date_clear (GDate *d, guint ndates)
memset (d, 0x0, ndates*sizeof (GDate)); memset (d, 0x0, ndates*sizeof (GDate));
} }
static G_LOCK_DEFINE(g_date_global); G_LOCK_DECLARE_STATIC (g_date_global);
/* These are for the parser, output to the user should use * /* These are for the parser, output to the user should use *
* g_date_strftime () - this creates more never-freed memory to annoy * g_date_strftime () - this creates more never-freed memory to annoy
@@ -652,7 +652,7 @@ g_date_set_parse (GDate *d,
/* set invalid */ /* set invalid */
g_date_clear (d, 1); g_date_clear (d, 1);
g_lock (g_date_global); G_LOCK (g_date_global);
g_date_prepare_to_parse (str, &pt); g_date_prepare_to_parse (str, &pt);
@@ -664,7 +664,7 @@ g_date_set_parse (GDate *d,
if (pt.num_ints == 4) if (pt.num_ints == 4)
{ {
g_unlock (g_date_global); G_UNLOCK (g_date_global);
return; /* presumably a typo; bail out. */ return; /* presumably a typo; bail out. */
} }
@@ -782,7 +782,7 @@ g_date_set_parse (GDate *d,
else else
g_message ("Rejected DMY %u %u %u", day, m, y); g_message ("Rejected DMY %u %u %u", day, m, y);
#endif #endif
g_unlock (g_date_global); G_UNLOCK (g_date_global);
} }
void void

View File

@@ -57,7 +57,7 @@ static void g_hash_node_destroy (GHashNode *hash_node);
static void g_hash_nodes_destroy (GHashNode *hash_node); static void g_hash_nodes_destroy (GHashNode *hash_node);
static G_LOCK_DEFINE(g_hash_global); G_LOCK_DECLARE_STATIC (g_hash_global);
static GMemChunk *node_mem_chunk = NULL; static GMemChunk *node_mem_chunk = NULL;
static GHashNode *node_free_list = NULL; static GHashNode *node_free_list = NULL;
@@ -345,7 +345,7 @@ g_hash_node_new (gpointer key,
{ {
GHashNode *hash_node; GHashNode *hash_node;
g_lock (g_hash_global); G_LOCK (g_hash_global);
if (node_free_list) if (node_free_list)
{ {
hash_node = node_free_list; hash_node = node_free_list;
@@ -360,7 +360,7 @@ g_hash_node_new (gpointer key,
hash_node = g_chunk_new (GHashNode, node_mem_chunk); hash_node = g_chunk_new (GHashNode, node_mem_chunk);
} }
g_unlock (g_hash_global); G_UNLOCK (g_hash_global);
hash_node->key = key; hash_node->key = key;
hash_node->value = value; hash_node->value = value;
@@ -372,10 +372,10 @@ g_hash_node_new (gpointer key,
static void static void
g_hash_node_destroy (GHashNode *hash_node) g_hash_node_destroy (GHashNode *hash_node)
{ {
g_lock (g_hash_global); G_LOCK (g_hash_global);
hash_node->next = node_free_list; hash_node->next = node_free_list;
node_free_list = hash_node; node_free_list = hash_node;
g_unlock (g_hash_global); G_UNLOCK (g_hash_global);
} }
static void static void
@@ -391,8 +391,8 @@ g_hash_nodes_destroy (GHashNode *hash_node)
while (node->next) while (node->next)
node = node->next; node = node->next;
g_lock (g_hash_global); G_LOCK (g_hash_global);
node->next = node_free_list; node->next = node_free_list;
node_free_list = hash_node; node_free_list = hash_node;
g_unlock (g_hash_global); G_UNLOCK (g_hash_global);
} }

View File

@@ -2007,7 +2007,8 @@ gint g_scanner_stat_mode (const gchar *filename);
} G_STMT_END } G_STMT_END
/* Completion */ /* GCompletion
*/
struct _GCompletion struct _GCompletion
{ {
@@ -2030,28 +2031,32 @@ GList* g_completion_complete (GCompletion* cmp,
void g_completion_free (GCompletion* cmp); void g_completion_free (GCompletion* cmp);
/* GDate
*
/* Date calculations (not time for now, to be resolved). These are a * Date calculations (not time for now, to be resolved). These are a
* mutant combination of Steffen Beyer's DateCalc routines * mutant combination of Steffen Beyer's DateCalc routines
* (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's * (http://www.perl.com/CPAN/authors/id/STBEY/) and Jon Trowbridge's
* date routines (written for in-house software). Written by Havoc * date routines (written for in-house software). Written by Havoc
* Pennington <hp@pobox.com> * Pennington <hp@pobox.com>
*/ */
/* this enum is used to specify order of appearance in parsed date typedef guint16 GDateYear;
* strings typedef guint8 GDateDay; /* day of the month */
*/ typedef struct _GDate GDate;
/* make struct tm known without having to include time.h */
struct tm;
typedef enum { /* enum used to specify order of appearance in parsed date strings */
typedef enum
{
G_DATE_DAY = 0, G_DATE_DAY = 0,
G_DATE_MONTH = 1, G_DATE_MONTH = 1,
G_DATE_YEAR = 2 G_DATE_YEAR = 2
} GDateDMY; } GDateDMY;
/* These other types specify the actual values. */ /* actual week and month values */
typedef enum
typedef enum { {
G_DATE_BAD_WEEKDAY = 0, G_DATE_BAD_WEEKDAY = 0,
G_DATE_MONDAY = 1, G_DATE_MONDAY = 1,
G_DATE_TUESDAY = 2, G_DATE_TUESDAY = 2,
@@ -2061,8 +2066,8 @@ typedef enum {
G_DATE_SATURDAY = 6, G_DATE_SATURDAY = 6,
G_DATE_SUNDAY = 7 G_DATE_SUNDAY = 7
} GDateWeekday; } GDateWeekday;
typedef enum
typedef enum { {
G_DATE_BAD_MONTH = 0, G_DATE_BAD_MONTH = 0,
G_DATE_JANUARY = 1, G_DATE_JANUARY = 1,
G_DATE_FEBRUARY = 2, G_DATE_FEBRUARY = 2,
@@ -2078,22 +2083,17 @@ typedef enum {
G_DATE_DECEMBER = 12 G_DATE_DECEMBER = 12
} GDateMonth; } GDateMonth;
typedef guint16 GDateYear;
typedef guint8 GDateDay; /* day of the month */
#define G_DATE_BAD_JULIAN 0U #define G_DATE_BAD_JULIAN 0U
#define G_DATE_BAD_DAY 0U #define G_DATE_BAD_DAY 0U
#define G_DATE_BAD_YEAR 0U #define G_DATE_BAD_YEAR 0U
typedef struct _GDate GDate;
/* Note: directly manipulating structs is generally a bad idea, but /* Note: directly manipulating structs is generally a bad idea, but
* in this case it's an *incredibly* bad idea, because all or part * in this case it's an *incredibly* bad idea, because all or part
* of this struct can be invalid at any given time. Use the functions, * of this struct can be invalid at any given time. Use the functions,
* or you will get hosed, I promise. * or you will get hosed, I promise.
*/ */
struct _GDate
struct _GDate { {
guint julian_days : 32; /* julian days representation - we use a guint julian_days : 32; /* julian days representation - we use a
* bitfield hoping that 64 bit platforms * bitfield hoping that 64 bit platforms
* will pack this whole struct in one big * will pack this whole struct in one big
@@ -2109,105 +2109,95 @@ struct _GDate {
guint year : 16; guint year : 16;
}; };
/* _new with no args returns an invalid date, you then have to _set() stuff /* g_date_new() returns an invalid date, you then have to _set() stuff
* to get a usable object. You can also allocate a GDate statically, * to get a usable object. You can also allocate a GDate statically,
* then call g_date_clear() to initialize. * then call g_date_clear() to initialize.
*/ */
GDate* g_date_new (void); GDate* g_date_new (void);
GDate* g_date_new_dmy (GDateDay d, GDate* g_date_new_dmy (GDateDay day,
GDateMonth m, GDateMonth month,
GDateYear y); GDateYear year);
GDate* g_date_new_julian (guint32 julian_day); GDate* g_date_new_julian (guint32 julian_day);
void g_date_free (GDate *d); void g_date_free (GDate *date);
/* check g_date_valid() after doing an operation that might fail, like /* check g_date_valid() after doing an operation that might fail, like
* _parse. Almost all g_date operations are undefined on invalid * _parse. Almost all g_date operations are undefined on invalid
* dates (the exceptions are the mutators, since you need those to * dates (the exceptions are the mutators, since you need those to
* return to validity). * return to validity).
*/ */
gboolean g_date_valid (GDate *date);
gboolean g_date_valid_day (GDateDay day);
gboolean g_date_valid_month (GDateMonth month);
gboolean g_date_valid_year (GDateYear year);
gboolean g_date_valid_weekday (GDateWeekday weekday);
gboolean g_date_valid_julian (guint32 julian_date);
gboolean g_date_valid_dmy (GDateDay day,
GDateMonth month,
GDateYear year);
gboolean g_date_valid (GDate *d); GDateWeekday g_date_weekday (GDate *date);
gboolean g_date_valid_day (GDateDay d); GDateMonth g_date_month (GDate *date);
gboolean g_date_valid_month (GDateMonth m); GDateYear g_date_year (GDate *date);
gboolean g_date_valid_year (GDateYear y); GDateDay g_date_day (GDate *date);
gboolean g_date_valid_weekday (GDateWeekday w); guint32 g_date_julian (GDate *date);
gboolean g_date_valid_julian (guint32 j); guint g_date_day_of_year (GDate *date);
gboolean g_date_valid_dmy (GDateDay d,
GDateMonth m,
GDateYear y);
GDateWeekday g_date_weekday (GDate *d);
GDateMonth g_date_month (GDate *d);
GDateYear g_date_year (GDate *d);
GDateDay g_date_day (GDate *d);
guint32 g_date_julian (GDate *d);
guint g_date_day_of_year (GDate *d);
/* First monday/sunday is the start of week 1; if we haven't reached /* First monday/sunday is the start of week 1; if we haven't reached
* that day, return 0. These are not ISO weeks of the year; that * that day, return 0. These are not ISO weeks of the year; that
* routine should be added. * routine needs to be added.
* these functions return the number of weeks, starting on the
* corrsponding day
*/ */
guint g_date_monday_week_of_year (GDate *date);
guint g_date_monday_week_of_year (GDate *d); /* # weeks, starting on Monday */ guint g_date_sunday_week_of_year (GDate *date);
guint g_date_sunday_week_of_year (GDate *d); /* # weeks, starting on Sunday */
/* If you create a static date struct you need to clear it to get it /* If you create a static date struct you need to clear it to get it
* in a sane state before use. You can clear a whole array at * in a sane state before use. You can clear a whole array at
* once with the ndates argument. * once with the ndates argument.
*/ */
void g_date_clear (GDate *date,
void g_date_clear (GDate *d, guint n_dates);
guint ndates);
/* The parse routine is meant for dates typed in by a user, so it /* The parse routine is meant for dates typed in by a user, so it
* permits many formats but tries to catch common typos. If your data * permits many formats but tries to catch common typos. If your data
* needs to be strictly validated, it is not an appropriate function. * needs to be strictly validated, it is not an appropriate function.
*/ */
void g_date_set_parse (GDate *date,
void g_date_set_parse (GDate *d,
const gchar *str); const gchar *str);
void g_date_set_time (GDate *date,
void g_date_set_time (GDate *d,
GTime time); GTime time);
void g_date_set_month (GDate *date,
void g_date_set_month (GDate *d, GDateMonth month);
GDateMonth m); void g_date_set_day (GDate *date,
void g_date_set_day (GDate *d,
GDateDay day); GDateDay day);
void g_date_set_year (GDate *d, void g_date_set_year (GDate *date,
GDateYear y); GDateYear year);
void g_date_set_dmy (GDate *d, void g_date_set_dmy (GDate *date,
GDateDay day, GDateDay day,
GDateMonth m, GDateMonth month,
GDateYear y); GDateYear y);
void g_date_set_julian (GDate *date,
void g_date_set_julian (GDate *d, guint32 julian_date);
guint32 j); gboolean g_date_is_first_of_month (GDate *date);
gboolean g_date_is_last_of_month (GDate *date);
gboolean g_date_is_first_of_month (GDate *d);
gboolean g_date_is_last_of_month (GDate *d);
/* To go forward by some number of weeks just go forward weeks*7 days */ /* To go forward by some number of weeks just go forward weeks*7 days */
void g_date_add_days (GDate *d, void g_date_add_days (GDate *date,
guint ndays); guint n_days);
void g_date_subtract_days (GDate *d, void g_date_subtract_days (GDate *date,
guint ndays); guint n_days);
/* If you add/sub months while day > 28, the day might change */ /* If you add/sub months while day > 28, the day might change */
void g_date_add_months (GDate *d, void g_date_add_months (GDate *date,
guint nmonths); guint n_months);
void g_date_subtract_months (GDate *d, void g_date_subtract_months (GDate *date,
guint nmonths); guint n_months);
/* If it's feb 29, changing years can move you to the 28th */ /* If it's feb 29, changing years can move you to the 28th */
void g_date_add_years (GDate *d, void g_date_add_years (GDate *date,
guint nyears); guint n_years);
void g_date_subtract_years (GDate *d, void g_date_subtract_years (GDate *date,
guint nyears); guint n_years);
gboolean g_date_is_leap_year (GDateYear year); gboolean g_date_is_leap_year (GDateYear year);
guint8 g_date_days_in_month (GDateMonth month, guint8 g_date_days_in_month (GDateMonth month,
GDateYear year); GDateYear year);
@@ -2217,11 +2207,7 @@ guint8 g_date_sunday_weeks_in_year (GDateYear year);
/* qsort-friendly (with a cast...) */ /* qsort-friendly (with a cast...) */
gint g_date_compare (GDate *lhs, gint g_date_compare (GDate *lhs,
GDate *rhs); GDate *rhs);
void g_date_to_struct_tm (GDate *date,
/* make struct tm known without having to include time.h */
struct tm;
void g_date_to_struct_tm (GDate *d,
struct tm *tm); struct tm *tm);
/* Just like strftime() except you can only use date-related formats. /* Just like strftime() except you can only use date-related formats.
@@ -2230,12 +2216,12 @@ void g_date_to_struct_tm (GDate *d,
gsize g_date_strftime (gchar *s, gsize g_date_strftime (gchar *s,
gsize slen, gsize slen,
const gchar *format, const gchar *format,
GDate *d); GDate *date);
/* GRelation
*
/* GRelation: Indexed Relations. Imagine a really simple table in a * Indexed Relations. Imagine a really simple table in a
* database. Relations are not ordered. This data type is meant for * database. Relations are not ordered. This data type is meant for
* maintaining a N-way mapping. * maintaining a N-way mapping.
* *
@@ -2295,47 +2281,47 @@ gpointer g_tuples_index (GTuples *tuples,
guint g_spaced_primes_closest (guint num); guint g_spaced_primes_closest (guint num);
/* IO Channels /* GIOChannel
*/ */
typedef struct _GIOFuncs GIOFuncs; typedef struct _GIOFuncs GIOFuncs;
typedef enum
typedef enum { {
G_IO_ERROR_NONE, G_IO_ERROR_NONE,
G_IO_ERROR_AGAIN, G_IO_ERROR_AGAIN,
G_IO_ERROR_INVAL, G_IO_ERROR_INVAL,
G_IO_ERROR_UNKNOWN G_IO_ERROR_UNKNOWN
} GIOError; } GIOError;
typedef enum
typedef enum { {
G_SEEK_CUR, G_SEEK_CUR,
G_SEEK_SET, G_SEEK_SET,
G_SEEK_END G_SEEK_END
} GSeekType; } GSeekType;
typedef enum
typedef enum { {
G_IO_IN G_IO_IN
#ifdef POLLIN #ifdef POLLIN
= POLLIN = POLLIN
#endif #endif
,G_IO_OUT , G_IO_OUT
#ifdef POLLOUT #ifdef POLLOUT
= POLLOUT = POLLOUT
#endif #endif
,G_IO_PRI , G_IO_PRI
#ifdef POLLPRI #ifdef POLLPRI
= POLLPRI = POLLPRI
#endif #endif
,G_IO_ERR , G_IO_ERR
#ifdef POLLERR #ifdef POLLERR
= POLLERR = POLLERR
#endif #endif
,G_IO_HUP , G_IO_HUP
#ifdef POLLHUP #ifdef POLLHUP
= POLLHUP = POLLHUP
#endif #endif
,G_IO_NVAL , G_IO_NVAL
#ifdef POLLNVAL #ifdef POLLNVAL
= POLLNVAL = POLLNVAL
#endif #endif
@@ -2351,27 +2337,27 @@ struct _GIOChannel
typedef gboolean (*GIOFunc) (GIOChannel *source, typedef gboolean (*GIOFunc) (GIOChannel *source,
GIOCondition condition, GIOCondition condition,
gpointer data); gpointer data);
struct _GIOFuncs
struct _GIOFuncs { {
GIOError (*io_read) (GIOChannel *channel, GIOError (*io_read) (GIOChannel *channel,
gchar *buf, gchar *buf,
guint count, guint count,
guint *bytes_read); guint *bytes_read);
GIOError (*io_write) (GIOChannel *channel, GIOError (*io_write) (GIOChannel *channel,
gchar *buf, gchar *buf,
guint count, guint count,
guint *bytes_written); guint *bytes_written);
GIOError (*io_seek) (GIOChannel *channel, GIOError (*io_seek) (GIOChannel *channel,
gint offset, gint offset,
GSeekType type); GSeekType type);
void (*io_close) (GIOChannel *channel); void (*io_close) (GIOChannel *channel);
guint (*io_add_watch) (GIOChannel *channel, guint (*io_add_watch) (GIOChannel *channel,
gint priority, gint priority,
GIOCondition condition, GIOCondition condition,
GIOFunc func, GIOFunc func,
gpointer user_data, gpointer user_data,
GDestroyNotify notify); GDestroyNotify notify);
void (*io_free) (GIOChannel *channel); void (*io_free) (GIOChannel *channel);
}; };
void g_io_channel_init (GIOChannel *channel); void g_io_channel_init (GIOChannel *channel);
@@ -2400,19 +2386,20 @@ guint g_io_add_watch (GIOChannel *channel,
GIOFunc func, GIOFunc func,
gpointer user_data); gpointer user_data);
/* Main loop */
typedef struct _GTimeVal GTimeVal; /* Main loop
typedef struct _GSourceFuncs GSourceFuncs; */
typedef struct _GTimeVal GTimeVal;
typedef struct _GSourceFuncs GSourceFuncs;
typedef struct _GMainLoop GMainLoop; /* Opaque */
typedef struct _GMainLoop GMainLoop; /* Opaque */ struct _GTimeVal
{
struct _GTimeVal {
glong tv_sec; glong tv_sec;
glong tv_usec; glong tv_usec;
}; };
struct _GSourceFuncs
struct _GSourceFuncs { {
gboolean (*prepare) (gpointer source_data, gboolean (*prepare) (gpointer source_data,
GTimeVal *current_time, GTimeVal *current_time,
gint *timeout); gint *timeout);
@@ -2424,10 +2411,9 @@ struct _GSourceFuncs {
GDestroyNotify destroy; GDestroyNotify destroy;
}; };
typedef gboolean (*GSourceFunc) (gpointer data); typedef gboolean (*GSourceFunc) (gpointer data);
/* Hooks for adding to the main loop */ /* Hooks for adding to the main loop */
guint g_source_add (gint priority, guint g_source_add (gint priority,
gboolean can_recurse, gboolean can_recurse,
GSourceFuncs *funcs, GSourceFuncs *funcs,
@@ -2438,67 +2424,65 @@ void g_source_remove (guint tag);
void g_source_remove_by_user_data (gpointer user_data); void g_source_remove_by_user_data (gpointer user_data);
void g_source_remove_by_source_data (gpointer source_data); void g_source_remove_by_source_data (gpointer source_data);
void g_get_current_time (GTimeVal *result);
void g_get_current_time (GTimeVal *result);
/* Running the main loop */ /* Running the main loop */
GMainLoop* g_main_new (void);
GMainLoop *g_main_new (void); void g_main_run (GMainLoop *loop);
void g_main_run (GMainLoop *loop); void g_main_quit (GMainLoop *loop);
void g_main_quit (GMainLoop *loop); void g_main_destroy (GMainLoop *loop);
void g_main_destroy (GMainLoop *loop);
/* Run a single iteration of the mainloop. If block is FALSE, /* Run a single iteration of the mainloop. If block is FALSE,
* will never block * will never block
*/ */
gboolean g_main_iteration (gboolean block); gboolean g_main_iteration (gboolean may_block);
/* See if any events are pending /* See if any events are pending */
*/ gboolean g_main_pending (void);
gboolean g_main_pending ();
/* Idles and timeouts */ /* Idles and timeouts */
guint g_timeout_add_full (gint priority,
guint interval,
GSourceFunc function,
gpointer data,
GDestroyNotify notify);
guint g_timeout_add (guint interval,
GSourceFunc function,
gpointer data);
guint g_idle_add (GSourceFunc function,
gpointer data);
guint g_idle_add_full (gint priority,
GSourceFunc function,
gpointer data,
GDestroyNotify destroy);
guint g_timeout_add_full (gint priority, /* GPollFD
guint interval, *
GSourceFunc function, * Unix-specific IO and main loop calls
gpointer data, */
GDestroyNotify notify);
guint g_timeout_add (guint interval,
GSourceFunc function,
gpointer data);
guint g_idle_add (GSourceFunc function,
gpointer data);
guint g_idle_add_full (gint priority,
GSourceFunc function,
gpointer data,
GDestroyNotify destroy);
/* Unix-specific IO and main loop calls */
typedef struct _GPollFD GPollFD; typedef struct _GPollFD GPollFD;
typedef gint (*GPollFunc) (GPollFD *ufds,
struct _GPollFD { guint nfsd,
gint fd; gint timeout);
gushort events; struct _GPollFD
gushort revents; {
gint fd;
gushort events;
gushort revents;
}; };
typedef gint (*GPollFunc) (GPollFD *ufds, guint nfsd, gint timeout);
void g_main_poll_add (gint priority, void g_main_poll_add (gint priority,
GPollFD *fd); GPollFD *fd);
void g_main_poll_remove (GPollFD *fd); void g_main_poll_remove (GPollFD *fd);
void g_main_set_poll_func (GPollFunc func); void g_main_set_poll_func (GPollFunc func);
GIOChannel* g_io_channel_unix_new (int fd);
GIOChannel *g_io_channel_unix_new (int fd);
gint g_io_channel_unix_get_fd (GIOChannel *channel); gint g_io_channel_unix_get_fd (GIOChannel *channel);
#if 0 /* old IO Channels */
/* old IO Channels */
#if 0
/* IO Channels. /* IO Channels.
* These are used for plug-in communication in the GIMP, for instance. * These are used for plug-in communication in the GIMP, for instance.
* On Unix, it's simply an encapsulated file descriptor (a pipe). * On Unix, it's simply an encapsulated file descriptor (a pipe).
@@ -2521,7 +2505,6 @@ struct _GIOChannel
*/ */
#endif #endif
}; };
GIOChannel *g_iochannel_new (gint fd); GIOChannel *g_iochannel_new (gint fd);
void g_iochannel_free (GIOChannel *channel); void g_iochannel_free (GIOChannel *channel);
void g_iochannel_close_and_free (GIOChannel *channel); void g_iochannel_close_and_free (GIOChannel *channel);
@@ -2529,16 +2512,14 @@ void g_iochannel_wakeup_peer (GIOChannel *channel);
#ifndef NATIVE_WIN32 #ifndef NATIVE_WIN32
# define g_iochannel_wakeup_peer(channel) G_STMT_START { } G_STMT_END # define g_iochannel_wakeup_peer(channel) G_STMT_START { } G_STMT_END
#endif #endif
#endif /* old IO Channels */
#endif /* old IO Channels */
/* Windows emulation stubs for common unix functions /* Windows emulation stubs for common unix functions
*/ */
#ifdef NATIVE_WIN32 #ifdef NATIVE_WIN32
# define MAXPATHLEN 1024
#define MAXPATHLEN 1024 # ifdef _MSC_VER
#ifdef _MSC_VER
typedef int pid_t; typedef int pid_t;
/* These POSIXish functions are available in the Microsoft C library /* These POSIXish functions are available in the Microsoft C library
@@ -2553,30 +2534,27 @@ typedef int pid_t;
* For some functions, we provide emulators in glib, which are prefixed * For some functions, we provide emulators in glib, which are prefixed
* with gwin_. * with gwin_.
*/ */
#define getcwd _getcwd # define getcwd _getcwd
#define getpid _getpid # define getpid _getpid
#define access _access # define access _access
#define open _open # define open _open
#define read _read # define read _read
#define write _write # define write _write
#define lseek _lseek # define lseek _lseek
#define close _close # define close _close
#define pipe(phandles) _pipe (phandles, 4096, _O_BINARY) # define pipe(phandles) _pipe (phandles, 4096, _O_BINARY)
#define popen _popen # define popen _popen
#define pclose _pclose # define pclose _pclose
#define fdopen _fdopen # define fdopen _fdopen
#define ftruncate(fd, size) gwin_ftruncate (fd, size) # define ftruncate(fd, size) gwin_ftruncate (fd, size)
#define opendir gwin_opendir # define opendir gwin_opendir
#define readdir gwin_readdir # define readdir gwin_readdir
#define rewinddir gwin_rewinddir # define rewinddir gwin_rewinddir
#define closedir gwin_closedir # define closedir gwin_closedir
# define NAME_MAX 255
#define NAME_MAX 255
struct DIR struct DIR
{ {
gchar *dir_name; gchar *dir_name;
gboolean just_opened; gboolean just_opened;
guint find_file_handle; guint find_file_handle;
gpointer find_file_data; gpointer find_file_data;
@@ -2586,7 +2564,6 @@ struct dirent
{ {
gchar d_name[NAME_MAX + 1]; gchar d_name[NAME_MAX + 1];
}; };
/* emulation functions */ /* emulation functions */
extern int gwin_ftruncate (gint f, extern int gwin_ftruncate (gint f,
guint size); guint size);
@@ -2594,145 +2571,153 @@ DIR* gwin_opendir (const gchar *dirname);
struct dirent* gwin_readdir (DIR *dir); struct dirent* gwin_readdir (DIR *dir);
void gwin_rewinddir (DIR *dir); void gwin_rewinddir (DIR *dir);
gint gwin_closedir (DIR *dir); gint gwin_closedir (DIR *dir);
# endif /* _MSC_VER */
#endif /* NATIVE_WIN32 */
#endif /* _MSC_VER */
#endif /* NATIVE_WIN32 */
/* functions for thread support for glib. */
typedef struct _GMutex GMutex;
typedef struct _GCond GCond;
typedef struct _GPrivate GPrivate;
typedef struct _GStaticPrivate GStaticPrivate;
/* GLib Thread support
*/
typedef struct _GMutex GMutex;
typedef struct _GCond GCond;
typedef struct _GPrivate GPrivate;
typedef struct _GStaticPrivate GStaticPrivate;
typedef struct _GThreadFunctions GThreadFunctions; typedef struct _GThreadFunctions GThreadFunctions;
struct _GThreadFunctions struct _GThreadFunctions
{ {
GMutex* (*mutex_new) (void); GMutex* (*mutex_new) (void);
void (*mutex_lock) (GMutex* mutex); void (*mutex_lock) (GMutex *mutex);
gboolean (*mutex_trylock) (GMutex* mutex); gboolean (*mutex_trylock) (GMutex *mutex);
void (*mutex_unlock) (GMutex* mutex); void (*mutex_unlock) (GMutex *mutex);
void (*mutex_free) (GMutex* mutex); void (*mutex_free) (GMutex *mutex);
GCond* (*cond_new) (void); GCond* (*cond_new) (void);
void (*cond_signal) (GCond* cond); void (*cond_signal) (GCond *cond);
void (*cond_broadcast) (GCond* cond); void (*cond_broadcast) (GCond *cond);
void (*cond_wait) (GCond* cond, GMutex* mutex); void (*cond_wait) (GCond *cond,
gboolean (*cond_timed_wait) (GCond* cond, GMutex* mutex, GMutex *mutex);
GTimeVal *end_time); gboolean (*cond_timed_wait) (GCond *cond,
void (*cond_free) (GCond* cond); GMutex *mutex,
GPrivate* (*private_new) (GDestroyNotify destructor); GTimeVal *end_time);
gpointer (*private_get) (GPrivate* private_key); void (*cond_free) (GCond *cond);
void (*private_set) (GPrivate* private_key, gpointer value); GPrivate* (*private_new) (GDestroyNotify destructor);
gpointer (*private_get) (GPrivate *private_key);
void (*private_set) (GPrivate *private_key,
gpointer data);
}; };
GUTILS_C_VAR GThreadFunctions g_thread_functions_for_glib_use; GUTILS_C_VAR GThreadFunctions g_thread_functions_for_glib_use;
GUTILS_C_VAR gboolean g_thread_use_default_impl; GUTILS_C_VAR gboolean g_thread_use_default_impl;
GUTILS_C_VAR gboolean g_thread_supported; GUTILS_C_VAR gboolean g_threads_got_initialized;
/* initializes the mutex/cond/private implementation for glib, might /* initializes the mutex/cond/private implementation for glib, might
* only be called once, and must not be called directly or indirectly * only be called once, and must not be called directly or indirectly
* from another glib-function, e.g. as a callback. */ * from another glib-function, e.g. as a callback.
void g_thread_init(GThreadFunctions* init);
/* Internal functions for fallback static mutex implementation
* Please don't use it directly
*/ */
GMutex* g_static_mutex_get_mutex_impl(GMutex** mutex); void g_thread_init (GThreadFunctions *vtable);
#define G_USE_THREAD_FUNC_UNCOND(name,arg) \ /* internal function for fallback static mutex implementation */
(*g_thread_functions_for_glib_use.name)arg GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
#define G_USE_THREAD_FUNC(name,fail,arg) \
(g_thread_supported ? G_USE_THREAD_FUNC_UNCOND(name,arg) : (fail))
/* shorthands for conditional and unconditional function calls */
#define G_THREAD_UF(name, arglist) \
(*g_thread_functions_for_glib_use . name) arglist
#define G_THREAD_CF(name, fail, arg) \
(g_thread_supported () ? G_THREAD_UF (name, arg) : (fail))
/* keep in mind, all those mutexes and static mutexes are not /* keep in mind, all those mutexes and static mutexes are not
* recursive in general, don't rely on that */ * recursive in general, don't rely on that
#define g_mutex_new() G_USE_THREAD_FUNC_UNCOND(mutex_new,()) */
#define g_mutex_lock(mutex) G_USE_THREAD_FUNC(mutex_lock,(void)0,(mutex)) #define g_thread_supported() (g_threads_got_initialized)
#define g_mutex_trylock(mutex) G_USE_THREAD_FUNC(mutex_trylock,TRUE,(mutex)) #define g_mutex_new() G_THREAD_UF (mutex_new, ())
#define g_mutex_unlock(mutex) G_USE_THREAD_FUNC(mutex_unlock,(void)0,(mutex)) #define g_mutex_lock(mutex) G_THREAD_CF (mutex_lock, (void)0, (mutex))
#define g_mutex_free(mutex) G_USE_THREAD_FUNC(mutex_free,(void)0,(mutex)) #define g_mutex_trylock(mutex) G_THREAD_CF (mutex_trylock, TRUE, (mutex))
#define g_cond_new() G_USE_THREAD_FUNC_UNCOND(cond_new,()) #define g_mutex_unlock(mutex) G_THREAD_CF (mutex_unlock, (void)0, (mutex))
#define g_cond_signal(cond) G_USE_THREAD_FUNC(cond_signal,(void)0,(cond)) #define g_mutex_free(mutex) G_THREAD_CF (mutex_free, (void)0, (mutex))
#define g_cond_broadcast(cond) G_USE_THREAD_FUNC(cond_broadcast,(void)0,(cond)) #define g_cond_new() G_THREAD_UF (cond_new, ())
#define g_cond_wait(cond,mutex) G_USE_THREAD_FUNC(cond_wait,(void)0,(cond,mutex)) #define g_cond_signal(cond) G_THREAD_CF (cond_signal, (void)0, (cond))
#define g_cond_timed_wait(cond,mutex,abs_time) \ #define g_cond_broadcast(cond) G_THREAD_CF (cond_broadcast, (void)0, (cond))
G_USE_THREAD_FUNC(cond_timed_wait,TRUE,(cond,mutex,abs_time)) #define g_cond_wait(cond, mutex) G_THREAD_CF (cond_wait, (void)0, (cond, \
#define g_cond_free(cond) G_USE_THREAD_FUNC(cond_free,(void)0,(cond)) mutex))
#define g_cond_free(cond) G_THREAD_CF (cond_free, (void)0, (cond))
#define g_private_new(destructor) \ #define g_cond_timed_wait(cond, mutex, abs_time) G_THREAD_CF (cond_timed_wait, \
G_USE_THREAD_FUNC_UNCOND(private_new,(destructor)) TRUE, \
#define g_private_get(private_key) \ (cond, mutex, \
G_USE_THREAD_FUNC(private_get,((gpointer)private_key),(private_key)) abs_time))
#define g_private_set(private_key,value) \ #define g_private_new(destructor) G_THREAD_UF (private_new, (destructor))
G_USE_THREAD_FUNC(private_set,(void)(private_key=(GPrivate *)(value)), \ #define g_private_get(private_key) G_THREAD_CF (private_get, \
(private_key,value)) ((gpointer)private_key), \
(private_key))
/* GStaticMutex'es can be statically initialized with the value #define g_private_set(private_key, value) G_THREAD_CF (private_set, \
(void) (private_key = \
(GPrivate*) (value)), \
(private_key, value))
/* GStaticMutexes can be statically initialized with the value
* G_STATIC_MUTEX_INIT, and then they can directly be used, that is * G_STATIC_MUTEX_INIT, and then they can directly be used, that is
* much easier, than having to explicitly allocate the mutex before * much easier, than having to explicitly allocate the mutex before
* use */ * use
*/
#define g_static_mutex_lock(mutex) \ #define g_static_mutex_lock(mutex) \
g_mutex_lock( g_static_mutex_get_mutex(mutex) ) g_mutex_lock (g_static_mutex_get_mutex (mutex))
#define g_static_mutex_trylock(mutex) \ #define g_static_mutex_trylock(mutex) \
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))
struct _GStaticPrivate struct _GStaticPrivate
{ {
guint index; guint index;
}; };
#define G_STATIC_PRIVATE_INIT { 0 } #define G_STATIC_PRIVATE_INIT { 0 }
gpointer g_static_private_get (GStaticPrivate *private_key);
void g_static_private_set (GStaticPrivate *private_key,
gpointer data,
GDestroyNotify notify);
gpointer g_static_private_get (GStaticPrivate* private_key); /* these are some convenience macros that expand to nothing if GLib was
void g_static_private_set (GStaticPrivate *private_key, * configured with --deisable-threads. for using StaticMutexes, you
gpointer data, * declare them with G_LOCK_DECLARE_STATIC (name) or G_LOCK_DECLARE (name)
GDestroyNotify notify); * if you need to export the mutex. name is a unique identifier for the
* protected varibale or code portion. locking, testing and unlocking of
* such mutexes can be done with G_LOCK(), G_UNLOCK() and G_TRYLOCK()
* respectively.
*/
extern gboolean glib_dummy_decl;
#define G_LOCK_NAME(name) (g__ ## name ## _lock)
#ifdef G_THREADS_ENABLED
# define G_LOCK_DECLARE_STATIC(name) static G_LOCK_DECLARE (name)
# define G_LOCK_DECLARE(name) \
GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT
/* these are some convenience macros, for using StaticMutex'es, you # ifdef G_DEBUG_LOCKS
* define them by G_LOCK_DEFINE(name), where name could for example be the # define G_LOCK(name) G_STMT_START{ \
* name of the protected varibale, and you (un)lock them with g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
* g_(un)lock(name) */ "file %s: line %d (%s): locking: %s ", \
#define g_lock_name(name) (name ## _lock) __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
#define G_LOCK_DEFINE(name) GStaticMutex g_lock_name(name)=G_STATIC_MUTEX_INIT #name); \
g_static_mutex_lock (G_LOCK_NAME (name)); \
#ifdef G_DEBUG_LOCKS
#define g_lock(name) G_STMT_START{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_MESSAGE, \
"file %s: line %d (%s): locking: %s ", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__, \
#name); \
g_static_mutex_lock(g_lock_name(name)); \
}G_STMT_END }G_STMT_END
#define g_unlock(name) G_STMT_START{ \ # define G_UNLOCK(name) G_STMT_START{ \
g_log (G_LOG_DOMAIN, \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
G_LOG_LEVEL_MESSAGE, \ "file %s: line %d (%s): unlocking: %s ", \
"file %s: line %d (%s): unlocking: %s ", \ __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
__FILE__, \ #name); \
__LINE__, \ g_static_mutex_unlock (G_LOCK_NAME (name)); \
__PRETTY_FUNCTION__, \
#name); \
g_static_mutex_unlock(g_lock_name(name)); \
}G_STMT_END }G_STMT_END
#define g_trylock(name) G_STMT_START{ \ # define G_TRYLOCK(name) G_STMT_START{ \
g_log (G_LOG_DOMAIN, \ g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
G_LOG_LEVEL_MESSAGE, \ "file %s: line %d (%s): try locking: %s ", \
"file %s: line %d (%s): try locking: %s ", \ __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
__FILE__, \ #name); \
__LINE__, \ }G_STMT_END, g_static_mutex_trylock (G_LOCK_NAME (name))
__PRETTY_FUNCTION__, \ # else /* !G_DEBUG_LOCKS */
#name); \ # define G_LOCK(name) g_static_mutex_lock (G_LOCK_NAME (name))
}G_STMT_END, g_static_mutex_trylock(g_lock_name(name)) # define G_UNLOCK(name) g_static_mutex_unlock (G_LOCK_NAME (name))
#else /* !G_DEBUG_LOCKS */ # define G_TRYLOCK(name) g_static_mutex_trylock (G_LOCK_NAME (name))
#define g_lock(name) g_static_mutex_lock(g_lock_name(name)) # endif /* !G_DEBUG_LOCKS */
#define g_unlock(name) g_static_mutex_unlock(g_lock_name(name)) #else /* !G_THREADS_ENABLED */
#define g_trylock(name) g_static_mutex_trylock(g_lock_name(name)) # define G_LOCK_DECLARE_STATIC(name) extern gboolean glib_dummy_decl
#endif # define G_LOCK_DECLARE(name) extern gboolean glib_dummy_decl
# define G_LOCK(name)
# define G_UNLOCK(name)
# define G_TRYLOCK(name) (FALSE)
#endif /* !G_THREADS_ENABLED */
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -36,7 +36,7 @@ struct _GAllocator /* from gmem.c */
}; };
static GAllocator *current_allocator = NULL; static GAllocator *current_allocator = NULL;
static G_LOCK_DEFINE(current_allocator); G_LOCK_DECLARE_STATIC (current_allocator);
/* HOLDS: current_allocator_lock */ /* HOLDS: current_allocator_lock */
static void static void
@@ -70,17 +70,17 @@ g_list_validate_allocator (GAllocator *allocator)
void void
g_list_push_allocator(GAllocator *allocator) g_list_push_allocator(GAllocator *allocator)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
g_list_validate_allocator ( allocator ); g_list_validate_allocator ( allocator );
allocator->last = current_allocator; allocator->last = current_allocator;
current_allocator = allocator; current_allocator = allocator;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
void void
g_list_pop_allocator (void) g_list_pop_allocator (void)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
if (current_allocator) if (current_allocator)
{ {
GAllocator *allocator; GAllocator *allocator;
@@ -90,7 +90,7 @@ g_list_pop_allocator (void)
allocator->last = NULL; allocator->last = NULL;
allocator->is_unused = TRUE; allocator->is_unused = TRUE;
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
GList* GList*
@@ -98,7 +98,7 @@ g_list_alloc (void)
{ {
GList *list; GList *list;
g_lock (current_allocator); G_LOCK (current_allocator);
if (!current_allocator) if (!current_allocator)
{ {
GAllocator *allocator = g_allocator_new ("GLib default GList allocator", GAllocator *allocator = g_allocator_new ("GLib default GList allocator",
@@ -126,7 +126,7 @@ g_list_alloc (void)
current_allocator->free_lists = list->next; current_allocator->free_lists = list->next;
} }
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
list->next = NULL; list->next = NULL;
list->prev = NULL; list->prev = NULL;
@@ -139,10 +139,10 @@ g_list_free (GList *list)
if (list) if (list)
{ {
list->data = list->next; list->data = list->next;
g_lock (current_allocator); G_LOCK (current_allocator);
list->next = current_allocator->free_lists; list->next = current_allocator->free_lists;
current_allocator->free_lists = list; current_allocator->free_lists = list;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
} }
@@ -152,10 +152,10 @@ g_list_free_1 (GList *list)
if (list) if (list)
{ {
list->data = NULL; list->data = NULL;
g_lock (current_allocator); G_LOCK (current_allocator);
list->next = current_allocator->free_lists; list->next = current_allocator->free_lists;
current_allocator->free_lists = list; current_allocator->free_lists = list;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
} }

View File

@@ -101,7 +101,7 @@ static GHookList source_list = { 0 };
/* The following lock is used for both the list of sources /* The following lock is used for both the list of sources
* and the list of poll records * and the list of poll records
*/ */
static G_LOCK_DEFINE (main_loop); G_LOCK_DECLARE_STATIC (main_loop);
static GSourceFuncs timeout_funcs = { static GSourceFuncs timeout_funcs = {
g_timeout_prepare, g_timeout_prepare,
@@ -232,7 +232,7 @@ g_source_add (gint priority,
guint return_val; guint return_val;
GSource *source; GSource *source;
g_lock (main_loop); G_LOCK (main_loop);
if (!source_list.is_setup) if (!source_list.is_setup)
g_hook_list_init (&source_list, sizeof(GSource)); g_hook_list_init (&source_list, sizeof(GSource));
@@ -261,7 +261,7 @@ g_source_add (gint priority,
write (wake_up_pipe[1], "A", 1); write (wake_up_pipe[1], "A", 1);
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
return return_val; return return_val;
} }
@@ -271,7 +271,7 @@ g_source_remove (guint tag)
{ {
GHook *hook; GHook *hook;
g_lock (main_loop); G_LOCK (main_loop);
hook = g_hook_get (&source_list, tag); hook = g_hook_get (&source_list, tag);
if (hook) if (hook)
@@ -281,7 +281,7 @@ g_source_remove (guint tag)
g_hook_destroy_link (&source_list, hook); g_hook_destroy_link (&source_list, hook);
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
void void
@@ -289,7 +289,7 @@ g_source_remove_by_user_data (gpointer user_data)
{ {
GHook *hook; GHook *hook;
g_lock (main_loop); G_LOCK (main_loop);
hook = g_hook_find_data (&source_list, TRUE, user_data); hook = g_hook_find_data (&source_list, TRUE, user_data);
if (hook) if (hook)
@@ -299,7 +299,7 @@ g_source_remove_by_user_data (gpointer user_data)
g_hook_destroy_link (&source_list, hook); g_hook_destroy_link (&source_list, hook);
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
static gboolean static gboolean
@@ -315,7 +315,7 @@ g_source_remove_by_source_data (gpointer source_data)
{ {
GHook *hook; GHook *hook;
g_lock (main_loop); G_LOCK (main_loop);
hook = g_hook_find (&source_list, TRUE, hook = g_hook_find (&source_list, TRUE,
g_source_find_source_data, source_data); g_source_find_source_data, source_data);
@@ -326,7 +326,7 @@ g_source_remove_by_source_data (gpointer source_data)
g_hook_destroy_link (&source_list, hook); g_hook_destroy_link (&source_list, hook);
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
void g_get_current_time (GTimeVal *result) void g_get_current_time (GTimeVal *result)
@@ -360,11 +360,11 @@ g_main_dispatch (GTimeVal *current_time)
source->hook.flags |= G_HOOK_FLAG_IN_CALL; source->hook.flags |= G_HOOK_FLAG_IN_CALL;
g_unlock (main_loop); G_UNLOCK (main_loop);
need_destroy = ! dispatch(source_data, need_destroy = ! dispatch(source_data,
current_time, current_time,
hook_data); hook_data);
g_lock (main_loop); G_LOCK (main_loop);
source->hook.flags &= ~G_HOOK_FLAG_IN_CALL; source->hook.flags &= ~G_HOOK_FLAG_IN_CALL;
@@ -394,7 +394,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
g_get_current_time (&current_time); g_get_current_time (&current_time);
g_lock (main_loop); G_LOCK (main_loop);
/* If recursing, finish up current dispatch, before starting over */ /* If recursing, finish up current dispatch, before starting over */
if (pending_dispatches) if (pending_dispatches)
@@ -402,7 +402,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
if (dispatch) if (dispatch)
g_main_dispatch (&current_time); g_main_dispatch (&current_time);
g_unlock (main_loop); G_UNLOCK (main_loop);
return TRUE; return TRUE;
} }
@@ -434,7 +434,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
if (!dispatch) if (!dispatch)
{ {
g_hook_unref (&source_list, hook); g_hook_unref (&source_list, hook);
g_unlock (main_loop); G_UNLOCK (main_loop);
return TRUE; return TRUE;
} }
else else
@@ -499,7 +499,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
else else
{ {
g_hook_unref (&source_list, hook); g_hook_unref (&source_list, hook);
g_unlock (main_loop); G_UNLOCK (main_loop);
return TRUE; return TRUE;
} }
} }
@@ -519,7 +519,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
retval = TRUE; retval = TRUE;
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
return retval; return retval;
} }
@@ -605,10 +605,10 @@ g_main_poll (gint timeout, gboolean use_priority, gint priority)
poll_waiting = TRUE; poll_waiting = TRUE;
g_unlock (main_loop); G_UNLOCK (main_loop);
npoll = i; npoll = i;
(*poll_func) (fd_array, npoll, timeout); (*poll_func) (fd_array, npoll, timeout);
g_lock (main_loop); G_LOCK (main_loop);
if (!poll_waiting) if (!poll_waiting)
{ {
@@ -634,9 +634,9 @@ void
g_main_poll_add (gint priority, g_main_poll_add (gint priority,
GPollFD *fd) GPollFD *fd)
{ {
g_lock (main_loop); G_LOCK (main_loop);
g_main_poll_add_unlocked (priority, fd); g_main_poll_add_unlocked (priority, fd);
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
static void static void
@@ -676,7 +676,7 @@ g_main_poll_add_unlocked (gint priority,
n_poll_records++; n_poll_records++;
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
void void
@@ -684,7 +684,7 @@ g_main_poll_remove (GPollFD *fd)
{ {
GPollRec *pollrec, *lastrec; GPollRec *pollrec, *lastrec;
g_lock (main_loop); G_LOCK (main_loop);
lastrec = NULL; lastrec = NULL;
pollrec = poll_records; pollrec = poll_records;
@@ -708,7 +708,7 @@ g_main_poll_remove (GPollFD *fd)
pollrec = pollrec->next; pollrec = pollrec->next;
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
void void

View File

@@ -39,7 +39,7 @@ struct _GAllocator /* from gmem.c */
GNode *free_nodes; /* implementation specific */ GNode *free_nodes; /* implementation specific */
}; };
static G_LOCK_DEFINE(current_allocator); G_LOCK_DECLARE_STATIC (current_allocator);
static GAllocator *current_allocator = NULL; static GAllocator *current_allocator = NULL;
/* HOLDS: current_allocator_lock */ /* HOLDS: current_allocator_lock */
@@ -74,17 +74,17 @@ g_node_validate_allocator (GAllocator *allocator)
void void
g_node_push_allocator (GAllocator *allocator) g_node_push_allocator (GAllocator *allocator)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
g_node_validate_allocator ( allocator ); g_node_validate_allocator ( allocator );
allocator->last = current_allocator; allocator->last = current_allocator;
current_allocator = allocator; current_allocator = allocator;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
void void
g_node_pop_allocator (void) g_node_pop_allocator (void)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
if (current_allocator) if (current_allocator)
{ {
GAllocator *allocator; GAllocator *allocator;
@@ -94,7 +94,7 @@ g_node_pop_allocator (void)
allocator->last = NULL; allocator->last = NULL;
allocator->is_unused = TRUE; allocator->is_unused = TRUE;
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
@@ -104,7 +104,7 @@ g_node_new (gpointer data)
{ {
GNode *node; GNode *node;
g_lock (current_allocator); G_LOCK (current_allocator);
if (!current_allocator) if (!current_allocator)
{ {
GAllocator *allocator = g_allocator_new ("GLib default GNode allocator", GAllocator *allocator = g_allocator_new ("GLib default GNode allocator",
@@ -120,7 +120,7 @@ g_node_new (gpointer data)
node = current_allocator->free_nodes; node = current_allocator->free_nodes;
current_allocator->free_nodes = node->next; current_allocator->free_nodes = node->next;
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
node->data = data; node->data = data;
node->next = NULL; node->next = NULL;
@@ -147,10 +147,10 @@ g_nodes_free (GNode *node)
break; break;
} }
g_lock (current_allocator); G_LOCK (current_allocator);
parent->next = current_allocator->free_nodes; parent->next = current_allocator->free_nodes;
current_allocator->free_nodes = node; current_allocator->free_nodes = node;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
void void

View File

@@ -35,7 +35,7 @@ struct _GAllocator /* from gmem.c */
GSList *free_lists; /* implementation specific */ GSList *free_lists; /* implementation specific */
}; };
static G_LOCK_DEFINE(current_allocator); G_LOCK_DECLARE_STATIC (current_allocator);
static GAllocator *current_allocator = NULL; static GAllocator *current_allocator = NULL;
/* HOLDS: current_allocator_lock */ /* HOLDS: current_allocator_lock */
@@ -70,17 +70,17 @@ g_slist_validate_allocator (GAllocator *allocator)
void void
g_slist_push_allocator (GAllocator *allocator) g_slist_push_allocator (GAllocator *allocator)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
g_slist_validate_allocator (allocator); g_slist_validate_allocator (allocator);
allocator->last = current_allocator; allocator->last = current_allocator;
current_allocator = allocator; current_allocator = allocator;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
void void
g_slist_pop_allocator (void) g_slist_pop_allocator (void)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
if (current_allocator) if (current_allocator)
{ {
GAllocator *allocator; GAllocator *allocator;
@@ -90,7 +90,7 @@ g_slist_pop_allocator (void)
allocator->last = NULL; allocator->last = NULL;
allocator->is_unused = TRUE; allocator->is_unused = TRUE;
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
GSList* GSList*
@@ -98,7 +98,7 @@ g_slist_alloc (void)
{ {
GSList *list; GSList *list;
g_lock (current_allocator); G_LOCK (current_allocator);
if (!current_allocator) if (!current_allocator)
{ {
GAllocator *allocator = g_allocator_new ("GLib default GSList allocator", GAllocator *allocator = g_allocator_new ("GLib default GSList allocator",
@@ -126,7 +126,7 @@ g_slist_alloc (void)
current_allocator->free_lists = list->next; current_allocator->free_lists = list->next;
} }
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
list->next = NULL; list->next = NULL;
@@ -139,10 +139,10 @@ g_slist_free (GSList *list)
if (list) if (list)
{ {
list->data = list->next; list->data = list->next;
g_lock (current_allocator); G_LOCK (current_allocator);
list->next = current_allocator->free_lists; list->next = current_allocator->free_lists;
current_allocator->free_lists = list; current_allocator->free_lists = list;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
} }
@@ -152,10 +152,10 @@ g_slist_free_1 (GSList *list)
if (list) if (list)
{ {
list->data = NULL; list->data = NULL;
g_lock (current_allocator); G_LOCK (current_allocator);
list->next = current_allocator->free_lists; list->next = current_allocator->free_lists;
current_allocator->free_lists = list; current_allocator->free_lists = list;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
} }

View File

@@ -48,7 +48,7 @@ struct _GRealString
gint alloc; gint alloc;
}; };
static G_LOCK_DEFINE(string_mem_chunk); G_LOCK_DECLARE_STATIC (string_mem_chunk);
static GMemChunk *string_mem_chunk = NULL; static GMemChunk *string_mem_chunk = NULL;
/* Hash Functions. /* Hash Functions.
@@ -207,14 +207,14 @@ g_string_sized_new (guint dfl_size)
{ {
GRealString *string; GRealString *string;
g_lock (string_mem_chunk); G_LOCK (string_mem_chunk);
if (!string_mem_chunk) if (!string_mem_chunk)
string_mem_chunk = g_mem_chunk_new ("string mem chunk", string_mem_chunk = g_mem_chunk_new ("string mem chunk",
sizeof (GRealString), sizeof (GRealString),
1024, G_ALLOC_AND_FREE); 1024, G_ALLOC_AND_FREE);
string = g_chunk_new (GRealString, string_mem_chunk); string = g_chunk_new (GRealString, string_mem_chunk);
g_unlock (string_mem_chunk); G_UNLOCK (string_mem_chunk);
string->alloc = 0; string->alloc = 0;
string->len = 0; string->len = 0;
@@ -248,9 +248,9 @@ g_string_free (GString *string,
if (free_segment) if (free_segment)
g_free (string->str); g_free (string->str);
g_lock (string_mem_chunk); G_LOCK (string_mem_chunk);
g_mem_chunk_free (string_mem_chunk, string); g_mem_chunk_free (string_mem_chunk, string);
g_unlock (string_mem_chunk); G_UNLOCK (string_mem_chunk);
} }
GString* GString*

View File

@@ -83,7 +83,7 @@ static GTreeNode* g_tree_node_rotate_right (GTreeNode *node);
static void g_tree_node_check (GTreeNode *node); static void g_tree_node_check (GTreeNode *node);
static G_LOCK_DEFINE(g_tree_global); G_LOCK_DECLARE_STATIC (g_tree_global);
static GMemChunk *node_mem_chunk = NULL; static GMemChunk *node_mem_chunk = NULL;
static GTreeNode *node_free_list = NULL; static GTreeNode *node_free_list = NULL;
@@ -94,7 +94,7 @@ g_tree_node_new (gpointer key,
{ {
GTreeNode *node; GTreeNode *node;
g_lock (g_tree_global); G_LOCK (g_tree_global);
if (node_free_list) if (node_free_list)
{ {
node = node_free_list; node = node_free_list;
@@ -110,7 +110,7 @@ g_tree_node_new (gpointer key,
node = g_chunk_new (GTreeNode, node_mem_chunk); node = g_chunk_new (GTreeNode, node_mem_chunk);
} }
g_unlock (g_tree_global); G_UNLOCK (g_tree_global);
node->balance = 0; node->balance = 0;
node->left = NULL; node->left = NULL;
@@ -128,10 +128,10 @@ g_tree_node_destroy (GTreeNode *node)
{ {
g_tree_node_destroy (node->right); g_tree_node_destroy (node->right);
g_tree_node_destroy (node->left); g_tree_node_destroy (node->left);
g_lock (g_tree_global); G_LOCK (g_tree_global);
node->right = node_free_list; node->right = node_free_list;
node_free_list = node; node_free_list = node;
g_unlock (g_tree_global); G_UNLOCK (g_tree_global);
} }
} }
@@ -385,10 +385,10 @@ g_tree_node_remove (GTreeNode *node,
node = g_tree_node_restore_right_balance (new_root, old_balance); node = g_tree_node_restore_right_balance (new_root, old_balance);
} }
g_lock (g_tree_global); G_LOCK (g_tree_global);
garbage->right = node_free_list; garbage->right = node_free_list;
node_free_list = garbage; node_free_list = garbage;
g_unlock (g_tree_global); G_UNLOCK (g_tree_global);
} }
else if (cmp < 0) else if (cmp < 0)
{ {

View File

@@ -371,7 +371,7 @@ g_getenv (const gchar *variable)
#endif #endif
} }
static G_LOCK_DEFINE(g_utils_global); G_LOCK_DECLARE_STATIC (g_utils_global);
static gchar *g_tmp_dir = NULL; static gchar *g_tmp_dir = NULL;
static gchar *g_user_name = NULL; static gchar *g_user_name = NULL;
@@ -455,10 +455,10 @@ g_get_any_init (void)
gchar* gchar*
g_get_user_name (void) g_get_user_name (void)
{ {
g_lock (g_utils_global); G_LOCK (g_utils_global);
if (!g_tmp_dir) if (!g_tmp_dir)
g_get_any_init (); g_get_any_init ();
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return g_user_name; return g_user_name;
} }
@@ -466,10 +466,10 @@ g_get_user_name (void)
gchar* gchar*
g_get_real_name (void) g_get_real_name (void)
{ {
g_lock (g_utils_global); G_LOCK (g_utils_global);
if (!g_tmp_dir) if (!g_tmp_dir)
g_get_any_init (); g_get_any_init ();
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return g_real_name; return g_real_name;
} }
@@ -483,10 +483,10 @@ g_get_real_name (void)
gchar* gchar*
g_get_home_dir (void) g_get_home_dir (void)
{ {
g_lock (g_utils_global); G_LOCK (g_utils_global);
if (!g_tmp_dir) if (!g_tmp_dir)
g_get_any_init (); g_get_any_init ();
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return g_home_dir; return g_home_dir;
} }
@@ -501,10 +501,10 @@ g_get_home_dir (void)
gchar* gchar*
g_get_tmp_dir (void) g_get_tmp_dir (void)
{ {
g_lock (g_utils_global); G_LOCK (g_utils_global);
if (!g_tmp_dir) if (!g_tmp_dir)
g_get_any_init (); g_get_any_init ();
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return g_tmp_dir; return g_tmp_dir;
} }
@@ -516,9 +516,9 @@ g_get_prgname (void)
{ {
gchar* retval; gchar* retval;
g_lock (g_utils_global); G_LOCK (g_utils_global);
retval = g_prgname; retval = g_prgname;
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return retval; return retval;
} }
@@ -528,11 +528,11 @@ g_set_prgname (const gchar *prgname)
{ {
gchar *c; gchar *c;
g_lock (g_utils_global); G_LOCK (g_utils_global);
c = g_prgname; c = g_prgname;
g_prgname = g_strdup (prgname); g_prgname = g_strdup (prgname);
g_free (c); g_free (c);
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
} }
guint guint

22
glist.c
View File

@@ -36,7 +36,7 @@ struct _GAllocator /* from gmem.c */
}; };
static GAllocator *current_allocator = NULL; static GAllocator *current_allocator = NULL;
static G_LOCK_DEFINE(current_allocator); G_LOCK_DECLARE_STATIC (current_allocator);
/* HOLDS: current_allocator_lock */ /* HOLDS: current_allocator_lock */
static void static void
@@ -70,17 +70,17 @@ g_list_validate_allocator (GAllocator *allocator)
void void
g_list_push_allocator(GAllocator *allocator) g_list_push_allocator(GAllocator *allocator)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
g_list_validate_allocator ( allocator ); g_list_validate_allocator ( allocator );
allocator->last = current_allocator; allocator->last = current_allocator;
current_allocator = allocator; current_allocator = allocator;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
void void
g_list_pop_allocator (void) g_list_pop_allocator (void)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
if (current_allocator) if (current_allocator)
{ {
GAllocator *allocator; GAllocator *allocator;
@@ -90,7 +90,7 @@ g_list_pop_allocator (void)
allocator->last = NULL; allocator->last = NULL;
allocator->is_unused = TRUE; allocator->is_unused = TRUE;
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
GList* GList*
@@ -98,7 +98,7 @@ g_list_alloc (void)
{ {
GList *list; GList *list;
g_lock (current_allocator); G_LOCK (current_allocator);
if (!current_allocator) if (!current_allocator)
{ {
GAllocator *allocator = g_allocator_new ("GLib default GList allocator", GAllocator *allocator = g_allocator_new ("GLib default GList allocator",
@@ -126,7 +126,7 @@ g_list_alloc (void)
current_allocator->free_lists = list->next; current_allocator->free_lists = list->next;
} }
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
list->next = NULL; list->next = NULL;
list->prev = NULL; list->prev = NULL;
@@ -139,10 +139,10 @@ g_list_free (GList *list)
if (list) if (list)
{ {
list->data = list->next; list->data = list->next;
g_lock (current_allocator); G_LOCK (current_allocator);
list->next = current_allocator->free_lists; list->next = current_allocator->free_lists;
current_allocator->free_lists = list; current_allocator->free_lists = list;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
} }
@@ -152,10 +152,10 @@ g_list_free_1 (GList *list)
if (list) if (list)
{ {
list->data = NULL; list->data = NULL;
g_lock (current_allocator); G_LOCK (current_allocator);
list->next = current_allocator->free_lists; list->next = current_allocator->free_lists;
current_allocator->free_lists = list; current_allocator->free_lists = list;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
} }

46
gmain.c
View File

@@ -101,7 +101,7 @@ static GHookList source_list = { 0 };
/* The following lock is used for both the list of sources /* The following lock is used for both the list of sources
* and the list of poll records * and the list of poll records
*/ */
static G_LOCK_DEFINE (main_loop); G_LOCK_DECLARE_STATIC (main_loop);
static GSourceFuncs timeout_funcs = { static GSourceFuncs timeout_funcs = {
g_timeout_prepare, g_timeout_prepare,
@@ -232,7 +232,7 @@ g_source_add (gint priority,
guint return_val; guint return_val;
GSource *source; GSource *source;
g_lock (main_loop); G_LOCK (main_loop);
if (!source_list.is_setup) if (!source_list.is_setup)
g_hook_list_init (&source_list, sizeof(GSource)); g_hook_list_init (&source_list, sizeof(GSource));
@@ -261,7 +261,7 @@ g_source_add (gint priority,
write (wake_up_pipe[1], "A", 1); write (wake_up_pipe[1], "A", 1);
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
return return_val; return return_val;
} }
@@ -271,7 +271,7 @@ g_source_remove (guint tag)
{ {
GHook *hook; GHook *hook;
g_lock (main_loop); G_LOCK (main_loop);
hook = g_hook_get (&source_list, tag); hook = g_hook_get (&source_list, tag);
if (hook) if (hook)
@@ -281,7 +281,7 @@ g_source_remove (guint tag)
g_hook_destroy_link (&source_list, hook); g_hook_destroy_link (&source_list, hook);
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
void void
@@ -289,7 +289,7 @@ g_source_remove_by_user_data (gpointer user_data)
{ {
GHook *hook; GHook *hook;
g_lock (main_loop); G_LOCK (main_loop);
hook = g_hook_find_data (&source_list, TRUE, user_data); hook = g_hook_find_data (&source_list, TRUE, user_data);
if (hook) if (hook)
@@ -299,7 +299,7 @@ g_source_remove_by_user_data (gpointer user_data)
g_hook_destroy_link (&source_list, hook); g_hook_destroy_link (&source_list, hook);
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
static gboolean static gboolean
@@ -315,7 +315,7 @@ g_source_remove_by_source_data (gpointer source_data)
{ {
GHook *hook; GHook *hook;
g_lock (main_loop); G_LOCK (main_loop);
hook = g_hook_find (&source_list, TRUE, hook = g_hook_find (&source_list, TRUE,
g_source_find_source_data, source_data); g_source_find_source_data, source_data);
@@ -326,7 +326,7 @@ g_source_remove_by_source_data (gpointer source_data)
g_hook_destroy_link (&source_list, hook); g_hook_destroy_link (&source_list, hook);
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
void g_get_current_time (GTimeVal *result) void g_get_current_time (GTimeVal *result)
@@ -360,11 +360,11 @@ g_main_dispatch (GTimeVal *current_time)
source->hook.flags |= G_HOOK_FLAG_IN_CALL; source->hook.flags |= G_HOOK_FLAG_IN_CALL;
g_unlock (main_loop); G_UNLOCK (main_loop);
need_destroy = ! dispatch(source_data, need_destroy = ! dispatch(source_data,
current_time, current_time,
hook_data); hook_data);
g_lock (main_loop); G_LOCK (main_loop);
source->hook.flags &= ~G_HOOK_FLAG_IN_CALL; source->hook.flags &= ~G_HOOK_FLAG_IN_CALL;
@@ -394,7 +394,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
g_get_current_time (&current_time); g_get_current_time (&current_time);
g_lock (main_loop); G_LOCK (main_loop);
/* If recursing, finish up current dispatch, before starting over */ /* If recursing, finish up current dispatch, before starting over */
if (pending_dispatches) if (pending_dispatches)
@@ -402,7 +402,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
if (dispatch) if (dispatch)
g_main_dispatch (&current_time); g_main_dispatch (&current_time);
g_unlock (main_loop); G_UNLOCK (main_loop);
return TRUE; return TRUE;
} }
@@ -434,7 +434,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
if (!dispatch) if (!dispatch)
{ {
g_hook_unref (&source_list, hook); g_hook_unref (&source_list, hook);
g_unlock (main_loop); G_UNLOCK (main_loop);
return TRUE; return TRUE;
} }
else else
@@ -499,7 +499,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
else else
{ {
g_hook_unref (&source_list, hook); g_hook_unref (&source_list, hook);
g_unlock (main_loop); G_UNLOCK (main_loop);
return TRUE; return TRUE;
} }
} }
@@ -519,7 +519,7 @@ g_main_iterate (gboolean block, gboolean dispatch)
retval = TRUE; retval = TRUE;
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
return retval; return retval;
} }
@@ -605,10 +605,10 @@ g_main_poll (gint timeout, gboolean use_priority, gint priority)
poll_waiting = TRUE; poll_waiting = TRUE;
g_unlock (main_loop); G_UNLOCK (main_loop);
npoll = i; npoll = i;
(*poll_func) (fd_array, npoll, timeout); (*poll_func) (fd_array, npoll, timeout);
g_lock (main_loop); G_LOCK (main_loop);
if (!poll_waiting) if (!poll_waiting)
{ {
@@ -634,9 +634,9 @@ void
g_main_poll_add (gint priority, g_main_poll_add (gint priority,
GPollFD *fd) GPollFD *fd)
{ {
g_lock (main_loop); G_LOCK (main_loop);
g_main_poll_add_unlocked (priority, fd); g_main_poll_add_unlocked (priority, fd);
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
static void static void
@@ -676,7 +676,7 @@ g_main_poll_add_unlocked (gint priority,
n_poll_records++; n_poll_records++;
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
void void
@@ -684,7 +684,7 @@ g_main_poll_remove (GPollFD *fd)
{ {
GPollRec *pollrec, *lastrec; GPollRec *pollrec, *lastrec;
g_lock (main_loop); G_LOCK (main_loop);
lastrec = NULL; lastrec = NULL;
pollrec = poll_records; pollrec = poll_records;
@@ -708,7 +708,7 @@ g_main_poll_remove (GPollFD *fd)
pollrec = pollrec->next; pollrec = pollrec->next;
} }
g_unlock (main_loop); G_UNLOCK (main_loop);
} }
void void

View File

@@ -64,7 +64,7 @@ static inline GModule* g_module_find_by_name (const gchar *name);
/* --- variables --- */ /* --- variables --- */
static G_LOCK_DEFINE (g_module_global); G_LOCK_DECLARE_STATIC (GModule);
const char *g_log_domain_gmodule = "GModule"; const char *g_log_domain_gmodule = "GModule";
static GModule *modules = NULL; static GModule *modules = NULL;
static GModule *main_module = NULL; static GModule *main_module = NULL;
@@ -78,7 +78,7 @@ g_module_find_by_handle (gpointer handle)
GModule *module; GModule *module;
GModule *retval = NULL; GModule *retval = NULL;
g_lock (g_module_global); G_LOCK (GModule);
if (main_module && main_module->handle == handle) if (main_module && main_module->handle == handle)
retval = main_module; retval = main_module;
else else
@@ -88,7 +88,7 @@ g_module_find_by_handle (gpointer handle)
retval = module; retval = module;
break; break;
} }
g_unlock (g_module_global); G_UNLOCK (GModule);
return retval; return retval;
} }
@@ -99,14 +99,14 @@ g_module_find_by_name (const gchar *name)
GModule *module; GModule *module;
GModule *retval = NULL; GModule *retval = NULL;
g_lock (g_module_global); G_LOCK (GModule);
for (module = modules; module; module = module->next) for (module = modules; module; module = module->next)
if (strcmp (name, module->file_name) == 0) if (strcmp (name, module->file_name) == 0)
{ {
retval = module; retval = module;
break; break;
} }
g_unlock (g_module_global); G_UNLOCK (GModule);
return retval; return retval;
} }
@@ -198,7 +198,7 @@ g_module_open (const gchar *file_name,
if (!file_name) if (!file_name)
{ {
g_lock (g_module_global); G_LOCK (GModule);
if (!main_module) if (!main_module)
{ {
handle = _g_module_self (); handle = _g_module_self ();
@@ -213,7 +213,7 @@ g_module_open (const gchar *file_name,
main_module->next = NULL; main_module->next = NULL;
} }
} }
g_unlock (g_module_global); G_UNLOCK (GModule);
return main_module; return main_module;
} }
@@ -256,10 +256,10 @@ g_module_open (const gchar *file_name,
module->ref_count = 1; module->ref_count = 1;
module->is_resident = FALSE; module->is_resident = FALSE;
module->unload = NULL; module->unload = NULL;
g_lock (g_module_global); G_LOCK (GModule);
module->next = modules; module->next = modules;
modules = module; modules = module;
g_unlock (g_module_global); G_UNLOCK (GModule);
/* check initialization */ /* check initialization */
if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init)) if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init))
@@ -313,7 +313,7 @@ g_module_close (GModule *module)
last = NULL; last = NULL;
g_lock (g_module_global); G_LOCK (GModule);
node = modules; node = modules;
while (node) while (node)
{ {
@@ -329,7 +329,7 @@ g_module_close (GModule *module)
node = last->next; node = last->next;
} }
module->next = NULL; module->next = NULL;
g_unlock (g_module_global); G_UNLOCK (GModule);
_g_module_close (module->handle, FALSE); _g_module_close (module->handle, FALSE);
g_free (module->file_name); g_free (module->file_name);

View File

@@ -40,7 +40,7 @@ static void g_thread_fail (void);
/* Global variables */ /* Global variables */
gboolean g_thread_use_default_impl = TRUE; gboolean g_thread_use_default_impl = TRUE;
gboolean g_thread_supported = FALSE; gboolean g_threads_got_initialized = FALSE;
GThreadFunctions g_thread_functions_for_glib_use = { GThreadFunctions g_thread_functions_for_glib_use = {
(GMutex*(*)())g_thread_fail, /* mutex_new */ (GMutex*(*)())g_thread_fail, /* mutex_new */
@@ -76,7 +76,7 @@ g_mutex_init (void)
gpointer private_old = g_thread_specific_private; gpointer private_old = g_thread_specific_private;
g_thread_specific_private = g_private_new (g_static_private_free_data); g_thread_specific_private = g_private_new (g_static_private_free_data);
/* we can not use g_private_set here, as g_thread_supported is not /* we can not use g_private_set here, as g_threads_got_initialized is not
yet set TRUE, whereas the private_set function is already set. */ yet set TRUE, whereas the private_set function is already set. */
g_thread_functions_for_glib_use.private_set (g_thread_specific_private, g_thread_functions_for_glib_use.private_set (g_thread_specific_private,
private_old); private_old);
@@ -88,7 +88,7 @@ g_mutex_init (void)
GMutex * GMutex *
g_static_mutex_get_mutex_impl (GMutex** mutex) g_static_mutex_get_mutex_impl (GMutex** mutex)
{ {
if (!g_thread_supported) if (!g_thread_supported ())
return NULL; return NULL;
g_assert (g_mutex_protect_static_mutex_allocation); g_assert (g_mutex_protect_static_mutex_allocation);

18
gnode.c
View File

@@ -39,7 +39,7 @@ struct _GAllocator /* from gmem.c */
GNode *free_nodes; /* implementation specific */ GNode *free_nodes; /* implementation specific */
}; };
static G_LOCK_DEFINE(current_allocator); G_LOCK_DECLARE_STATIC (current_allocator);
static GAllocator *current_allocator = NULL; static GAllocator *current_allocator = NULL;
/* HOLDS: current_allocator_lock */ /* HOLDS: current_allocator_lock */
@@ -74,17 +74,17 @@ g_node_validate_allocator (GAllocator *allocator)
void void
g_node_push_allocator (GAllocator *allocator) g_node_push_allocator (GAllocator *allocator)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
g_node_validate_allocator ( allocator ); g_node_validate_allocator ( allocator );
allocator->last = current_allocator; allocator->last = current_allocator;
current_allocator = allocator; current_allocator = allocator;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
void void
g_node_pop_allocator (void) g_node_pop_allocator (void)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
if (current_allocator) if (current_allocator)
{ {
GAllocator *allocator; GAllocator *allocator;
@@ -94,7 +94,7 @@ g_node_pop_allocator (void)
allocator->last = NULL; allocator->last = NULL;
allocator->is_unused = TRUE; allocator->is_unused = TRUE;
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
@@ -104,7 +104,7 @@ g_node_new (gpointer data)
{ {
GNode *node; GNode *node;
g_lock (current_allocator); G_LOCK (current_allocator);
if (!current_allocator) if (!current_allocator)
{ {
GAllocator *allocator = g_allocator_new ("GLib default GNode allocator", GAllocator *allocator = g_allocator_new ("GLib default GNode allocator",
@@ -120,7 +120,7 @@ g_node_new (gpointer data)
node = current_allocator->free_nodes; node = current_allocator->free_nodes;
current_allocator->free_nodes = node->next; current_allocator->free_nodes = node->next;
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
node->data = data; node->data = data;
node->next = NULL; node->next = NULL;
@@ -147,10 +147,10 @@ g_nodes_free (GNode *node)
break; break;
} }
g_lock (current_allocator); G_LOCK (current_allocator);
parent->next = current_allocator->free_nodes; parent->next = current_allocator->free_nodes;
current_allocator->free_nodes = node; current_allocator->free_nodes = node;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
void void

View File

@@ -35,7 +35,7 @@ struct _GAllocator /* from gmem.c */
GSList *free_lists; /* implementation specific */ GSList *free_lists; /* implementation specific */
}; };
static G_LOCK_DEFINE(current_allocator); G_LOCK_DECLARE_STATIC (current_allocator);
static GAllocator *current_allocator = NULL; static GAllocator *current_allocator = NULL;
/* HOLDS: current_allocator_lock */ /* HOLDS: current_allocator_lock */
@@ -70,17 +70,17 @@ g_slist_validate_allocator (GAllocator *allocator)
void void
g_slist_push_allocator (GAllocator *allocator) g_slist_push_allocator (GAllocator *allocator)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
g_slist_validate_allocator (allocator); g_slist_validate_allocator (allocator);
allocator->last = current_allocator; allocator->last = current_allocator;
current_allocator = allocator; current_allocator = allocator;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
void void
g_slist_pop_allocator (void) g_slist_pop_allocator (void)
{ {
g_lock (current_allocator); G_LOCK (current_allocator);
if (current_allocator) if (current_allocator)
{ {
GAllocator *allocator; GAllocator *allocator;
@@ -90,7 +90,7 @@ g_slist_pop_allocator (void)
allocator->last = NULL; allocator->last = NULL;
allocator->is_unused = TRUE; allocator->is_unused = TRUE;
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
GSList* GSList*
@@ -98,7 +98,7 @@ g_slist_alloc (void)
{ {
GSList *list; GSList *list;
g_lock (current_allocator); G_LOCK (current_allocator);
if (!current_allocator) if (!current_allocator)
{ {
GAllocator *allocator = g_allocator_new ("GLib default GSList allocator", GAllocator *allocator = g_allocator_new ("GLib default GSList allocator",
@@ -126,7 +126,7 @@ g_slist_alloc (void)
current_allocator->free_lists = list->next; current_allocator->free_lists = list->next;
} }
} }
g_unlock (current_allocator); G_UNLOCK (current_allocator);
list->next = NULL; list->next = NULL;
@@ -139,10 +139,10 @@ g_slist_free (GSList *list)
if (list) if (list)
{ {
list->data = list->next; list->data = list->next;
g_lock (current_allocator); G_LOCK (current_allocator);
list->next = current_allocator->free_lists; list->next = current_allocator->free_lists;
current_allocator->free_lists = list; current_allocator->free_lists = list;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
} }
@@ -152,10 +152,10 @@ g_slist_free_1 (GSList *list)
if (list) if (list)
{ {
list->data = NULL; list->data = NULL;
g_lock (current_allocator); G_LOCK (current_allocator);
list->next = current_allocator->free_lists; list->next = current_allocator->free_lists;
current_allocator->free_lists = list; current_allocator->free_lists = list;
g_unlock (current_allocator); G_UNLOCK (current_allocator);
} }
} }

View File

@@ -48,7 +48,7 @@ struct _GRealString
gint alloc; gint alloc;
}; };
static G_LOCK_DEFINE(string_mem_chunk); G_LOCK_DECLARE_STATIC (string_mem_chunk);
static GMemChunk *string_mem_chunk = NULL; static GMemChunk *string_mem_chunk = NULL;
/* Hash Functions. /* Hash Functions.
@@ -207,14 +207,14 @@ g_string_sized_new (guint dfl_size)
{ {
GRealString *string; GRealString *string;
g_lock (string_mem_chunk); G_LOCK (string_mem_chunk);
if (!string_mem_chunk) if (!string_mem_chunk)
string_mem_chunk = g_mem_chunk_new ("string mem chunk", string_mem_chunk = g_mem_chunk_new ("string mem chunk",
sizeof (GRealString), sizeof (GRealString),
1024, G_ALLOC_AND_FREE); 1024, G_ALLOC_AND_FREE);
string = g_chunk_new (GRealString, string_mem_chunk); string = g_chunk_new (GRealString, string_mem_chunk);
g_unlock (string_mem_chunk); G_UNLOCK (string_mem_chunk);
string->alloc = 0; string->alloc = 0;
string->len = 0; string->len = 0;
@@ -248,9 +248,9 @@ g_string_free (GString *string,
if (free_segment) if (free_segment)
g_free (string->str); g_free (string->str);
g_lock (string_mem_chunk); G_LOCK (string_mem_chunk);
g_mem_chunk_free (string_mem_chunk, string); g_mem_chunk_free (string_mem_chunk, string);
g_unlock (string_mem_chunk); G_UNLOCK (string_mem_chunk);
} }
GString* GString*

View File

@@ -1,3 +1,9 @@
Wed Dec 16 03:16:16 1998 Tim Janik <timj@gtk.org>
* testgthread.c: s/g_thread_supported/g_thread_supported ()/
* gthread.c: s/g_thread_supported/g_threads_got_initialized/
(g_thread_init): bail out if G_THREADS_ENABLED is not defined.
1998-12-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 1998-12-15 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* Makefile.am (EXTRA_DIST): updated. * Makefile.am (EXTRA_DIST): updated.

View File

@@ -17,8 +17,7 @@ libgthread_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \ -version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) \
-release $(LT_RELEASE) -release $(LT_RELEASE)
libgthread_la_LIBADD = \ libgthread_la_LIBADD = @G_THREAD_LIBS@
@G_THREAD_LIBS@
noinst_PROGRAMS = testgthread noinst_PROGRAMS = testgthread
testgthread_LDADD = ../libglib.la libgthread.la testgthread_LDADD = ../libglib.la libgthread.la

View File

@@ -40,12 +40,16 @@ void g_mem_init (void);
void g_messages_init (void); void g_messages_init (void);
void void
g_thread_init(GThreadFunctions* init) g_thread_init (GThreadFunctions* init)
{ {
gboolean supported; gboolean supported;
#ifndef G_THREADS_ENABLED
g_error ("GLib thread support is disabled.");
#endif /* !G_THREADS_ENABLED */
if (thread_system_already_initialized) if (thread_system_already_initialized)
g_error ("the glib thread system may only be initialized once."); g_error ("GThread system may only be initialized once.");
thread_system_already_initialized = TRUE; thread_system_already_initialized = TRUE;
@@ -56,29 +60,28 @@ g_thread_init(GThreadFunctions* init)
g_thread_functions_for_glib_use = *init; g_thread_functions_for_glib_use = *init;
/* It is important, that g_thread_supported is not set before the /* It is important, that g_threads_got_initialized is not set before the
thread initialization functions of the different modules are * thread initialization functions of the different modules are called
called */ */
supported = supported = (init->mutex_new &&
init->mutex_new && init->mutex_lock &&
init->mutex_lock && init->mutex_trylock &&
init->mutex_trylock && init->mutex_unlock &&
init->mutex_unlock && init->mutex_free &&
init->mutex_free && init->cond_new &&
init->cond_new && init->cond_signal &&
init->cond_signal && init->cond_broadcast &&
init->cond_broadcast && init->cond_wait &&
init->cond_wait && init->cond_timed_wait &&
init->cond_timed_wait && init->cond_free &&
init->cond_free && init->private_new &&
init->private_new && init->private_get &&
init->private_get && init->private_get);
init->private_get;
/* if somebody is calling g_thread_init (), it means that he wants to /* if somebody is calling g_thread_init (), it means that he wants to
have thread support, so check this */ * have thread support, so check this
*/
if (!supported) if (!supported)
{ {
if (g_thread_use_default_impl) if (g_thread_use_default_impl)
@@ -88,14 +91,14 @@ g_thread_init(GThreadFunctions* init)
} }
/* now call the thread initialization functions of the different /* now call the thread initialization functions of the different
glib modules. BTW: order does matter, g_mutex_init MUST be first */ * glib modules. order does matter, g_mutex_init MUST come first.
*/
g_mutex_init (); g_mutex_init ();
g_mem_init (); g_mem_init ();
g_messages_init (); g_messages_init ();
/* now we can set g_thread_supported and thus enable all the thread /* now we can set g_threads_got_initialized and thus enable
functions */ * all the thread functions
*/
g_thread_supported = TRUE; g_threads_got_initialized = TRUE;
} }

View File

@@ -13,9 +13,9 @@ test_mutexes ()
GMutex *mutex = NULL; GMutex *mutex = NULL;
GCond *cond = NULL; GCond *cond = NULL;
GStaticMutex static_mutex = G_STATIC_MUTEX_INIT; GStaticMutex static_mutex = G_STATIC_MUTEX_INIT;
G_LOCK_DEFINE (test_me); G_LOCK_DECLARE (test_me);
if (g_thread_supported) if (g_thread_supported ())
{ {
mutex = g_mutex_new (); mutex = g_mutex_new ();
cond = g_cond_new (); cond = g_cond_new ();
@@ -30,10 +30,10 @@ test_mutexes ()
g_cond_signal (cond); g_cond_signal (cond);
g_cond_broadcast (cond); g_cond_broadcast (cond);
g_lock (test_me); G_LOCK (test_me);
g_unlock (test_me); G_UNLOCK (test_me);
if (g_thread_supported) if (g_thread_supported ())
{ {
g_cond_free (cond); g_cond_free (cond);
g_mutex_free (mutex); g_mutex_free (mutex);

14
gtree.c
View File

@@ -83,7 +83,7 @@ static GTreeNode* g_tree_node_rotate_right (GTreeNode *node);
static void g_tree_node_check (GTreeNode *node); static void g_tree_node_check (GTreeNode *node);
static G_LOCK_DEFINE(g_tree_global); G_LOCK_DECLARE_STATIC (g_tree_global);
static GMemChunk *node_mem_chunk = NULL; static GMemChunk *node_mem_chunk = NULL;
static GTreeNode *node_free_list = NULL; static GTreeNode *node_free_list = NULL;
@@ -94,7 +94,7 @@ g_tree_node_new (gpointer key,
{ {
GTreeNode *node; GTreeNode *node;
g_lock (g_tree_global); G_LOCK (g_tree_global);
if (node_free_list) if (node_free_list)
{ {
node = node_free_list; node = node_free_list;
@@ -110,7 +110,7 @@ g_tree_node_new (gpointer key,
node = g_chunk_new (GTreeNode, node_mem_chunk); node = g_chunk_new (GTreeNode, node_mem_chunk);
} }
g_unlock (g_tree_global); G_UNLOCK (g_tree_global);
node->balance = 0; node->balance = 0;
node->left = NULL; node->left = NULL;
@@ -128,10 +128,10 @@ g_tree_node_destroy (GTreeNode *node)
{ {
g_tree_node_destroy (node->right); g_tree_node_destroy (node->right);
g_tree_node_destroy (node->left); g_tree_node_destroy (node->left);
g_lock (g_tree_global); G_LOCK (g_tree_global);
node->right = node_free_list; node->right = node_free_list;
node_free_list = node; node_free_list = node;
g_unlock (g_tree_global); G_UNLOCK (g_tree_global);
} }
} }
@@ -385,10 +385,10 @@ g_tree_node_remove (GTreeNode *node,
node = g_tree_node_restore_right_balance (new_root, old_balance); node = g_tree_node_restore_right_balance (new_root, old_balance);
} }
g_lock (g_tree_global); G_LOCK (g_tree_global);
garbage->right = node_free_list; garbage->right = node_free_list;
node_free_list = garbage; node_free_list = garbage;
g_unlock (g_tree_global); G_UNLOCK (g_tree_global);
} }
else if (cmp < 0) else if (cmp < 0)
{ {

View File

@@ -371,7 +371,7 @@ g_getenv (const gchar *variable)
#endif #endif
} }
static G_LOCK_DEFINE(g_utils_global); G_LOCK_DECLARE_STATIC (g_utils_global);
static gchar *g_tmp_dir = NULL; static gchar *g_tmp_dir = NULL;
static gchar *g_user_name = NULL; static gchar *g_user_name = NULL;
@@ -455,10 +455,10 @@ g_get_any_init (void)
gchar* gchar*
g_get_user_name (void) g_get_user_name (void)
{ {
g_lock (g_utils_global); G_LOCK (g_utils_global);
if (!g_tmp_dir) if (!g_tmp_dir)
g_get_any_init (); g_get_any_init ();
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return g_user_name; return g_user_name;
} }
@@ -466,10 +466,10 @@ g_get_user_name (void)
gchar* gchar*
g_get_real_name (void) g_get_real_name (void)
{ {
g_lock (g_utils_global); G_LOCK (g_utils_global);
if (!g_tmp_dir) if (!g_tmp_dir)
g_get_any_init (); g_get_any_init ();
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return g_real_name; return g_real_name;
} }
@@ -483,10 +483,10 @@ g_get_real_name (void)
gchar* gchar*
g_get_home_dir (void) g_get_home_dir (void)
{ {
g_lock (g_utils_global); G_LOCK (g_utils_global);
if (!g_tmp_dir) if (!g_tmp_dir)
g_get_any_init (); g_get_any_init ();
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return g_home_dir; return g_home_dir;
} }
@@ -501,10 +501,10 @@ g_get_home_dir (void)
gchar* gchar*
g_get_tmp_dir (void) g_get_tmp_dir (void)
{ {
g_lock (g_utils_global); G_LOCK (g_utils_global);
if (!g_tmp_dir) if (!g_tmp_dir)
g_get_any_init (); g_get_any_init ();
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return g_tmp_dir; return g_tmp_dir;
} }
@@ -516,9 +516,9 @@ g_get_prgname (void)
{ {
gchar* retval; gchar* retval;
g_lock (g_utils_global); G_LOCK (g_utils_global);
retval = g_prgname; retval = g_prgname;
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
return retval; return retval;
} }
@@ -528,11 +528,11 @@ g_set_prgname (const gchar *prgname)
{ {
gchar *c; gchar *c;
g_lock (g_utils_global); G_LOCK (g_utils_global);
c = g_prgname; c = g_prgname;
g_prgname = g_strdup (prgname); g_prgname = g_strdup (prgname);
g_free (c); g_free (c);
g_unlock (g_utils_global); G_UNLOCK (g_utils_global);
} }
guint guint