Prevent calling into g_cond_wait resp. g_mutex_lock/unlock directly to

2006-05-10  Sebastian Wilhelmi  <wilhelmi@google.com>

	* gthread/gthread-posix.c, gthread/gthread-win32.c: Prevent
	calling into g_cond_wait resp. g_mutex_lock/unlock directly to
	avoid recursions into the errorcheking mutex code (and out of
	principle anyway). (#335198, Chris Wilson)
This commit is contained in:
Sebastian Wilhelmi 2006-05-11 00:08:31 +00:00 committed by Sebastian Wilhelmi
parent a194e2e971
commit 685da6b099
4 changed files with 87 additions and 71 deletions

View File

@ -1,5 +1,10 @@
2006-05-10 Sebastian Wilhelmi <wilhelmi@google.com>
* gthread/gthread-posix.c, gthread/gthread-win32.c: Prevent
calling into g_cond_wait resp. g_mutex_lock/unlock directly to
avoid recursions into the errorcheking mutex code (and out of
principle anyway). (#335198, Chris Wilson)
* tests/errorcheck-mutex-test.c: Adapt to GLib coding standards.
2006-05-09 Sebastian Wilhelmi <wilhelmi@google.com>

View File

@ -1,5 +1,10 @@
2006-05-10 Sebastian Wilhelmi <wilhelmi@google.com>
* gthread/gthread-posix.c, gthread/gthread-win32.c: Prevent
calling into g_cond_wait resp. g_mutex_lock/unlock directly to
avoid recursions into the errorcheking mutex code (and out of
principle anyway). (#335198, Chris Wilson)
* tests/errorcheck-mutex-test.c: Adapt to GLib coding standards.
2006-05-09 Sebastian Wilhelmi <wilhelmi@google.com>

View File

@ -199,7 +199,7 @@ g_cond_new_posix_impl (void)
/* pthread_cond_signal, pthread_cond_broadcast and pthread_cond_wait
can be taken directly, as signature and semantic are right, but
without error check then!!!!, we might want to change this
therfore. */
therefore. */
#define G_NSEC_PER_SEC 1000000000
@ -217,10 +217,12 @@ g_cond_timed_wait_posix_impl (GCond * cond,
if (!abs_time)
{
g_cond_wait (cond, entered_mutex);
return TRUE;
result = pthread_cond_wait ((pthread_cond_t *)cond,
(pthread_mutex_t *) entered_mutex);
timed_out = FALSE;
}
else
{
end_time.tv_sec = abs_time->tv_sec;
end_time.tv_nsec = abs_time->tv_usec * (G_NSEC_PER_SEC / G_USEC_PER_SEC);
@ -229,15 +231,16 @@ g_cond_timed_wait_posix_impl (GCond * cond,
result = pthread_cond_timedwait ((pthread_cond_t *) cond,
(pthread_mutex_t *) entered_mutex,
&end_time);
#ifdef G_THREADS_IMPL_POSIX
timed_out = (result == ETIMEDOUT);
#else /* G_THREADS_IMPL_DCE */
timed_out = (result == -1) && (errno == EAGAIN);
#endif
}
if (!timed_out)
posix_check_err (posix_error (result), "pthread_cond_timedwait");
return !timed_out;
}

View File

@ -76,6 +76,9 @@ static GDestroyNotify g_private_destructors[G_PRIVATE_MAX];
static guint g_private_next = 0;
/* A "forward" declaration of this structure */
static GThreadFunctions g_thread_functions_for_glib_use_default;
typedef struct _GThreadData GThreadData;
struct _GThreadData
{
@ -236,12 +239,12 @@ g_cond_wait_internal (GCond *cond,
g_ptr_array_add (cond->array, event);
LeaveCriticalSection (&cond->lock);
g_mutex_unlock (entered_mutex);
g_thread_functions_for_glib_use_default.mutex_unlock (entered_mutex);
win32_check_for_error (WAIT_FAILED !=
(retval = WaitForSingleObject (event, milliseconds)));
g_mutex_lock (entered_mutex);
g_thread_functions_for_glib_use_default.mutex_lock (entered_mutex);
if (retval == WAIT_TIMEOUT)
{