Makefile.am: Corrected INCLUDES/DEFS bug also corrected in trunk.

acconfig.h: CVS thinks it has changed, but it really hasn't.
configure.in: Added pthreads.h test and processing,
	      plus G_THREAD_* and g_thread_* macros to
	      the generated glibconfig.h output.
garray.c, gcache.c: Updated module header, made thread safe.
glib.h: Include pthread.h if we're doing threads.
This commit is contained in:
Jeff Garzik 1998-11-12 04:43:24 +00:00
parent c4261064d6
commit 7ebf437b34
9 changed files with 131 additions and 14 deletions

View File

@ -12,7 +12,7 @@ bin_SCRIPTS=glib-config
BUILT_SOURCES=glib-config
glib-config: glib-config.in
DEFS += -DG_LOG_DOMAIN=g_log_domain_glib
INCLUDES = -DG_LOG_DOMAIN=g_log_domain_glib
EXTRA_DIST = \
glib.m4 \
@ -63,7 +63,6 @@ stamp-gc-h: config.status
libglib_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -release $(LT_RELEASE)
INCLUDES = -I$(top_srcdir)
noinst_PROGRAMS = testglib
testglib_LDADD = libglib.la

View File

@ -246,6 +246,13 @@ AC_CHECK_HEADERS(sys/times.h, AC_DEFINE(HAVE_SYS_TIMES_H))
AC_CHECK_HEADERS(unistd.h, AC_DEFINE(HAVE_UNISTD_H))
AC_CHECK_HEADERS(values.h, AC_DEFINE(HAVE_VALUES_H))
if test "x$glib_use_threads" = "xyes"; then
AC_CHECK_HEADERS(pthread.h, have_pthreads_h=yes, have_pthreads_h=no)
if test "x$have_pthreads_h" = "xno"; then
AC_MSG_ERROR(pthread.h required for thread support)
fi
fi
# Check for some functions
AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf strcasecmp strncasecmp)
@ -845,10 +852,18 @@ if test x$glib_working_wctype = xno; then
fi
if test x$glib_use_threads = xyes; then
glib_threads='
#define G_THREAD_SAFE 1'
#define G_THREAD_SAFE 1
#define G_THREAD_PROTECT(var) pthread_mutex_t var##_mutex = PTHREAD_MUTEX_INITIALIZER;
#define G_THREAD_SPROTECT(var) static pthread_mutex_t var##_mutex = PTHREAD_MUTEX_INITIALIZER;
#define g_thread_lock(var) pthread_mutex_lock(&var##_mutex)
#define g_thread_unlock(var) pthread_mutex_unlock(&var##_mutex)'
else
glib_threads='
#undef G_THREAD_SAFE'
#undef G_THREAD_SAFE
#define G_THREAD_PROTECT(var)
#define G_THREAD_SPROTECT(var)
#define g_thread_lock(var)
#define g_thread_unlock(var)'
fi
])

View File

@ -1,5 +1,11 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
/*
* garray.c - Dynamically-growing arrays for fast index-based access
*
* MT-Level: Safe
*
* GLIB - Library of useful routines for C programming
* Copyright 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright 1998 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -16,6 +22,11 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include "glib.h"
@ -42,6 +53,7 @@ static void g_array_maybe_expand (GRealArray *array,
static GMemChunk *array_mem_chunk = NULL;
G_THREAD_SPROTECT(array_mem_chunk)
GArray*
@ -51,6 +63,8 @@ g_array_new (gboolean zero_terminated,
{
GRealArray *array;
g_thread_lock(array_mem_chunk);
if (!array_mem_chunk)
array_mem_chunk = g_mem_chunk_new ("array mem chunk",
sizeof (GRealArray),
@ -58,6 +72,8 @@ g_array_new (gboolean zero_terminated,
array = g_chunk_new (GRealArray, array_mem_chunk);
g_thread_unlock(array_mem_chunk);
array->data = NULL;
array->len = 0;
array->alloc = 0;
@ -75,7 +91,11 @@ g_array_free (GArray *array,
if (free_segment)
g_free (array->data);
g_thread_lock(array_mem_chunk);
g_mem_chunk_free (array_mem_chunk, array);
g_thread_unlock(array_mem_chunk);
}
GArray*
@ -222,6 +242,7 @@ static void g_ptr_array_maybe_expand (GRealPtrArray *array,
static GMemChunk *ptr_array_mem_chunk = NULL;
G_THREAD_SPROTECT(ptr_array_mem_chunk)
@ -230,6 +251,8 @@ g_ptr_array_new (void)
{
GRealPtrArray *array;
g_thread_lock(ptr_array_mem_chunk);
if (!ptr_array_mem_chunk)
ptr_array_mem_chunk = g_mem_chunk_new ("array mem chunk",
sizeof (GRealPtrArray),
@ -237,6 +260,8 @@ g_ptr_array_new (void)
array = g_chunk_new (GRealPtrArray, ptr_array_mem_chunk);
g_thread_unlock(ptr_array_mem_chunk);
array->pdata = NULL;
array->len = 0;
array->alloc = 0;
@ -253,7 +278,11 @@ g_ptr_array_free (GPtrArray *array,
if (free_segment)
g_free (array->pdata);
g_thread_lock(ptr_array_mem_chunk);
g_mem_chunk_free (ptr_array_mem_chunk, array);
g_thread_unlock(ptr_array_mem_chunk);
}
static void

View File

@ -1,5 +1,11 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
/*
* gcache.c - Share data structures in order to save resources
*
* MT-Level: Safe
*
* GLIB - Library of useful routines for C programming
* Copyright 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright 1998 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -56,6 +62,7 @@ static void g_cache_node_destroy (GCacheNode *node);
static GMemChunk *node_mem_chunk = NULL;
G_THREAD_SPROTECT(node_mem_chunk)
GCache*
@ -193,12 +200,16 @@ g_cache_node_new (gpointer value)
{
GCacheNode *node;
g_thread_lock(node_mem_chunk);
if (!node_mem_chunk)
node_mem_chunk = g_mem_chunk_new ("cache node mem chunk", sizeof (GCacheNode),
1024, G_ALLOC_AND_FREE);
node = g_chunk_new (GCacheNode, node_mem_chunk);
g_thread_unlock(node_mem_chunk);
node->value = value;
node->ref_count = 1;
@ -208,5 +219,10 @@ g_cache_node_new (gpointer value)
static void
g_cache_node_destroy (GCacheNode *node)
{
g_thread_lock(node_mem_chunk);
g_mem_chunk_free (node_mem_chunk, node);
g_thread_unlock(node_mem_chunk);
}

7
glib.h
View File

@ -67,6 +67,13 @@
#include "dmalloc.h"
#endif
/* optionally yank in the pthreads info we need.
* Note that G_THREAD_SAFE implies HAVE_PTHREAD_H.
*/
#if G_THREAD_SAFE
# include <pthread.h>
#endif
#ifdef NATIVE_WIN32

View File

@ -12,7 +12,7 @@ bin_SCRIPTS=glib-config
BUILT_SOURCES=glib-config
glib-config: glib-config.in
DEFS += -DG_LOG_DOMAIN=g_log_domain_glib
INCLUDES = -DG_LOG_DOMAIN=g_log_domain_glib
EXTRA_DIST = \
glib.m4 \
@ -63,7 +63,6 @@ stamp-gc-h: config.status
libglib_la_LDFLAGS = \
-version-info $(LT_CURRENT):$(LT_REVISION):$(LT_AGE) -release $(LT_RELEASE)
INCLUDES = -I$(top_srcdir)
noinst_PROGRAMS = testglib
testglib_LDADD = libglib.la

View File

@ -1,5 +1,11 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
/*
* garray.c - Dynamically-growing arrays for fast index-based access
*
* MT-Level: Safe
*
* GLIB - Library of useful routines for C programming
* Copyright 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright 1998 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -16,6 +22,11 @@
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <string.h>
#include "glib.h"
@ -42,6 +53,7 @@ static void g_array_maybe_expand (GRealArray *array,
static GMemChunk *array_mem_chunk = NULL;
G_THREAD_SPROTECT(array_mem_chunk)
GArray*
@ -51,6 +63,8 @@ g_array_new (gboolean zero_terminated,
{
GRealArray *array;
g_thread_lock(array_mem_chunk);
if (!array_mem_chunk)
array_mem_chunk = g_mem_chunk_new ("array mem chunk",
sizeof (GRealArray),
@ -58,6 +72,8 @@ g_array_new (gboolean zero_terminated,
array = g_chunk_new (GRealArray, array_mem_chunk);
g_thread_unlock(array_mem_chunk);
array->data = NULL;
array->len = 0;
array->alloc = 0;
@ -75,7 +91,11 @@ g_array_free (GArray *array,
if (free_segment)
g_free (array->data);
g_thread_lock(array_mem_chunk);
g_mem_chunk_free (array_mem_chunk, array);
g_thread_unlock(array_mem_chunk);
}
GArray*
@ -222,6 +242,7 @@ static void g_ptr_array_maybe_expand (GRealPtrArray *array,
static GMemChunk *ptr_array_mem_chunk = NULL;
G_THREAD_SPROTECT(ptr_array_mem_chunk)
@ -230,6 +251,8 @@ g_ptr_array_new (void)
{
GRealPtrArray *array;
g_thread_lock(ptr_array_mem_chunk);
if (!ptr_array_mem_chunk)
ptr_array_mem_chunk = g_mem_chunk_new ("array mem chunk",
sizeof (GRealPtrArray),
@ -237,6 +260,8 @@ g_ptr_array_new (void)
array = g_chunk_new (GRealPtrArray, ptr_array_mem_chunk);
g_thread_unlock(ptr_array_mem_chunk);
array->pdata = NULL;
array->len = 0;
array->alloc = 0;
@ -253,7 +278,11 @@ g_ptr_array_free (GPtrArray *array,
if (free_segment)
g_free (array->pdata);
g_thread_lock(ptr_array_mem_chunk);
g_mem_chunk_free (ptr_array_mem_chunk, array);
g_thread_unlock(ptr_array_mem_chunk);
}
static void

View File

@ -1,5 +1,11 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
/*
* gcache.c - Share data structures in order to save resources
*
* MT-Level: Safe
*
* GLIB - Library of useful routines for C programming
* Copyright 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright 1998 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -56,6 +62,7 @@ static void g_cache_node_destroy (GCacheNode *node);
static GMemChunk *node_mem_chunk = NULL;
G_THREAD_SPROTECT(node_mem_chunk)
GCache*
@ -193,12 +200,16 @@ g_cache_node_new (gpointer value)
{
GCacheNode *node;
g_thread_lock(node_mem_chunk);
if (!node_mem_chunk)
node_mem_chunk = g_mem_chunk_new ("cache node mem chunk", sizeof (GCacheNode),
1024, G_ALLOC_AND_FREE);
node = g_chunk_new (GCacheNode, node_mem_chunk);
g_thread_unlock(node_mem_chunk);
node->value = value;
node->ref_count = 1;
@ -208,5 +219,10 @@ g_cache_node_new (gpointer value)
static void
g_cache_node_destroy (GCacheNode *node)
{
g_thread_lock(node_mem_chunk);
g_mem_chunk_free (node_mem_chunk, node);
g_thread_unlock(node_mem_chunk);
}

View File

@ -67,6 +67,13 @@
#include "dmalloc.h"
#endif
/* optionally yank in the pthreads info we need.
* Note that G_THREAD_SAFE implies HAVE_PTHREAD_H.
*/
#if G_THREAD_SAFE
# include <pthread.h>
#endif
#ifdef NATIVE_WIN32