Made the debugging G_TRYLOCK call also work for compilers with funnt

2000-04-19  Sebastian Wilhelmi  <wilhelmi@ira.uka.de>

	* glib.h (G_TRYLOCK): Made the debugging G_TRYLOCK call also work
	for compilers with funnt G_STMT_(START|END) macros.

	* tests/thread-test.c: Implemented a check for that.
This commit is contained in:
Sebastian Wilhelmi 2000-04-19 09:29:19 +00:00 committed by Sebastian Wilhelmi
parent e366512775
commit 1383e5b642
11 changed files with 50 additions and 8 deletions

View File

@ -1,5 +1,10 @@
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* glib.h (G_TRYLOCK): Made the debugging G_TRYLOCK call also work
for compilers with funnt G_STMT_(START|END) macros.
* tests/thread-test.c: Implemented a check for that.
* gutils.c (g_getenv): Changed the win32 part of this function to * gutils.c (g_getenv): Changed the win32 part of this function to
be thread safe and to make the returned environment string be thread safe and to make the returned environment string
persistent to match the UN*X behavior. This is again a response to persistent to match the UN*X behavior. This is again a response to

View File

@ -1,5 +1,10 @@
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* glib.h (G_TRYLOCK): Made the debugging G_TRYLOCK call also work
for compilers with funnt G_STMT_(START|END) macros.
* tests/thread-test.c: Implemented a check for that.
* gutils.c (g_getenv): Changed the win32 part of this function to * gutils.c (g_getenv): Changed the win32 part of this function to
be thread safe and to make the returned environment string be thread safe and to make the returned environment string
persistent to match the UN*X behavior. This is again a response to persistent to match the UN*X behavior. This is again a response to

View File

@ -1,5 +1,10 @@
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* glib.h (G_TRYLOCK): Made the debugging G_TRYLOCK call also work
for compilers with funnt G_STMT_(START|END) macros.
* tests/thread-test.c: Implemented a check for that.
* gutils.c (g_getenv): Changed the win32 part of this function to * gutils.c (g_getenv): Changed the win32 part of this function to
be thread safe and to make the returned environment string be thread safe and to make the returned environment string
persistent to match the UN*X behavior. This is again a response to persistent to match the UN*X behavior. This is again a response to

View File

@ -1,5 +1,10 @@
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* glib.h (G_TRYLOCK): Made the debugging G_TRYLOCK call also work
for compilers with funnt G_STMT_(START|END) macros.
* tests/thread-test.c: Implemented a check for that.
* gutils.c (g_getenv): Changed the win32 part of this function to * gutils.c (g_getenv): Changed the win32 part of this function to
be thread safe and to make the returned environment string be thread safe and to make the returned environment string
persistent to match the UN*X behavior. This is again a response to persistent to match the UN*X behavior. This is again a response to

View File

@ -1,5 +1,10 @@
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* glib.h (G_TRYLOCK): Made the debugging G_TRYLOCK call also work
for compilers with funnt G_STMT_(START|END) macros.
* tests/thread-test.c: Implemented a check for that.
* gutils.c (g_getenv): Changed the win32 part of this function to * gutils.c (g_getenv): Changed the win32 part of this function to
be thread safe and to make the returned environment string be thread safe and to make the returned environment string
persistent to match the UN*X behavior. This is again a response to persistent to match the UN*X behavior. This is again a response to

View File

@ -1,5 +1,10 @@
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* glib.h (G_TRYLOCK): Made the debugging G_TRYLOCK call also work
for compilers with funnt G_STMT_(START|END) macros.
* tests/thread-test.c: Implemented a check for that.
* gutils.c (g_getenv): Changed the win32 part of this function to * gutils.c (g_getenv): Changed the win32 part of this function to
be thread safe and to make the returned environment string be thread safe and to make the returned environment string
persistent to match the UN*X behavior. This is again a response to persistent to match the UN*X behavior. This is again a response to

View File

@ -1,5 +1,10 @@
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* glib.h (G_TRYLOCK): Made the debugging G_TRYLOCK call also work
for compilers with funnt G_STMT_(START|END) macros.
* tests/thread-test.c: Implemented a check for that.
* gutils.c (g_getenv): Changed the win32 part of this function to * gutils.c (g_getenv): Changed the win32 part of this function to
be thread safe and to make the returned environment string be thread safe and to make the returned environment string
persistent to match the UN*X behavior. This is again a response to persistent to match the UN*X behavior. This is again a response to

View File

@ -1,5 +1,10 @@
2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de> 2000-04-19 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* glib.h (G_TRYLOCK): Made the debugging G_TRYLOCK call also work
for compilers with funnt G_STMT_(START|END) macros.
* tests/thread-test.c: Implemented a check for that.
* gutils.c (g_getenv): Changed the win32 part of this function to * gutils.c (g_getenv): Changed the win32 part of this function to
be thread safe and to make the returned environment string be thread safe and to make the returned environment string
persistent to match the UN*X behavior. This is again a response to persistent to match the UN*X behavior. This is again a response to

7
glib.h
View File

@ -3152,12 +3152,11 @@ extern void glib_dummy_decl (void);
#name); \ #name); \
g_static_mutex_unlock (&G_LOCK_NAME (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_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
"file %s: line %d (%s): try locking: %s ", \ "file %s: line %d (%s): try locking: %s ", \
__FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \ __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
#name); \ #name), g_static_mutex_trylock (&G_LOCK_NAME (name)))
}G_STMT_END, g_static_mutex_trylock (&G_LOCK_NAME (name))
# else /* !G_DEBUG_LOCKS */ # else /* !G_DEBUG_LOCKS */
# define G_LOCK(name) g_static_mutex_lock (&G_LOCK_NAME (name)) # define G_LOCK(name) g_static_mutex_lock (&G_LOCK_NAME (name))
# define G_UNLOCK(name) g_static_mutex_unlock (&G_LOCK_NAME (name)) # define G_UNLOCK(name) g_static_mutex_unlock (&G_LOCK_NAME (name))

View File

@ -3152,12 +3152,11 @@ extern void glib_dummy_decl (void);
#name); \ #name); \
g_static_mutex_unlock (&G_LOCK_NAME (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_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \ (g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
"file %s: line %d (%s): try locking: %s ", \ "file %s: line %d (%s): try locking: %s ", \
__FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \ __FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
#name); \ #name), g_static_mutex_trylock (&G_LOCK_NAME (name)))
}G_STMT_END, g_static_mutex_trylock (&G_LOCK_NAME (name))
# else /* !G_DEBUG_LOCKS */ # else /* !G_DEBUG_LOCKS */
# define G_LOCK(name) g_static_mutex_lock (&G_LOCK_NAME (name)) # define G_LOCK(name) g_static_mutex_lock (&G_LOCK_NAME (name))
# define G_UNLOCK(name) g_static_mutex_unlock (&G_LOCK_NAME (name)) # define G_UNLOCK(name) g_static_mutex_unlock (&G_LOCK_NAME (name))

View File

@ -4,12 +4,14 @@
static GMutex* test_g_mutex_mutex = NULL; static GMutex* test_g_mutex_mutex = NULL;
static guint test_g_mutex_int = 0; static guint test_g_mutex_int = 0;
G_LOCK_DEFINE_STATIC (test_g_mutex);
static void static void
test_g_mutex_thread (gpointer data) test_g_mutex_thread (gpointer data)
{ {
g_assert (GPOINTER_TO_INT (data) == 42); g_assert (GPOINTER_TO_INT (data) == 42);
g_assert (g_mutex_trylock (test_g_mutex_mutex) == FALSE); g_assert (g_mutex_trylock (test_g_mutex_mutex) == FALSE);
g_assert (G_TRYLOCK (test_g_mutex) == FALSE);
g_mutex_lock (test_g_mutex_mutex); g_mutex_lock (test_g_mutex_mutex);
g_assert (test_g_mutex_int == 42); g_assert (test_g_mutex_int == 42);
g_mutex_unlock (test_g_mutex_mutex); g_mutex_unlock (test_g_mutex_mutex);
@ -22,11 +24,13 @@ test_g_mutex (void)
test_g_mutex_mutex = g_mutex_new (); test_g_mutex_mutex = g_mutex_new ();
g_assert (g_mutex_trylock (test_g_mutex_mutex)); g_assert (g_mutex_trylock (test_g_mutex_mutex));
g_assert (G_TRYLOCK (test_g_mutex));
thread = g_thread_create (test_g_mutex_thread, thread = g_thread_create (test_g_mutex_thread,
GINT_TO_POINTER (42), GINT_TO_POINTER (42),
0, TRUE, TRUE, G_THREAD_PRIORITY_NORMAL); 0, TRUE, TRUE, G_THREAD_PRIORITY_NORMAL);
g_usleep (G_MICROSEC); g_usleep (G_MICROSEC);
test_g_mutex_int = 42; test_g_mutex_int = 42;
G_UNLOCK (test_g_mutex);
g_mutex_unlock (test_g_mutex_mutex); g_mutex_unlock (test_g_mutex_mutex);
g_thread_join (thread); g_thread_join (thread);
g_mutex_free (test_g_mutex_mutex); g_mutex_free (test_g_mutex_mutex);