mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-26 14:06:15 +01:00
Add @GLIB_DEBUG_FLAGS@ to INCLUDES for accessing -DG_ENABLE_DEBUG as
2000-10-25 Sebastian Wilhelmi <wilhelmi@ira.uka.de> * Makefile.am : Add @GLIB_DEBUG_FLAGS@ to INCLUDES for accessing -DG_ENABLE_DEBUG as needed in gthread-posix.c. * gthread-posix.c: Revamped error handling for native thread function calls. Now EPERM errors are ignored for some commands and only a warning message is output once (at first occurrence).
This commit is contained in:
parent
151fa40582
commit
b13320f78b
@ -1,3 +1,12 @@
|
|||||||
|
2000-10-25 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
|
||||||
|
|
||||||
|
* Makefile.am : Add @GLIB_DEBUG_FLAGS@ to INCLUDES for accessing
|
||||||
|
-DG_ENABLE_DEBUG as needed in gthread-posix.c.
|
||||||
|
|
||||||
|
* gthread-posix.c: Revamped error handling for native thread
|
||||||
|
function calls. Now EPERM errors are ignored for some commands and
|
||||||
|
only a warning message is output once (at first occurrence).
|
||||||
|
|
||||||
2000-10-15 Raja R Harinath <harinath@cs.umn.edu>
|
2000-10-15 Raja R Harinath <harinath@cs.umn.edu>
|
||||||
|
|
||||||
* Makefile.am (BUILT_EXTRA_DIST): New variable.
|
* Makefile.am (BUILT_EXTRA_DIST): New variable.
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
## Process this file with automake to produce Makefile.in
|
## Process this file with automake to produce Makefile.in
|
||||||
|
|
||||||
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/gthread \
|
INCLUDES = -I$(top_srcdir) -I$(top_srcdir)/gthread \
|
||||||
-DG_LOG_DOMAIN=\"GThread\" @GTHREAD_COMPILE_IMPL_DEFINES@
|
-DG_LOG_DOMAIN=\"GThread\" @GTHREAD_COMPILE_IMPL_DEFINES@ \
|
||||||
|
@GLIB_DEBUG_FLAGS@
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
makefile.mingw.in \
|
makefile.mingw.in \
|
||||||
|
@ -41,33 +41,56 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define posix_print_error( name, num ) \
|
#define posix_check_err(err, name) G_STMT_START{ \
|
||||||
g_error( "file %s: line %d (%s): error %s during %s", \
|
int error = (err); \
|
||||||
|
if (error) \
|
||||||
|
g_error ("file %s: line %d (%s): error %s during %s", \
|
||||||
__FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
|
__FILE__, __LINE__, G_GNUC_PRETTY_FUNCTION, \
|
||||||
g_strerror((num)), #name )
|
g_strerror (error), name); \
|
||||||
|
}G_STMT_END
|
||||||
|
|
||||||
|
#define posix_check_cmd(cmd) posix_check_err (posix_error (cmd), #cmd)
|
||||||
|
|
||||||
|
#ifdef G_ENABLE_DEBUG
|
||||||
|
static gboolean posix_check_cmd_prio_warned = FALSE;
|
||||||
|
# define posix_check_cmd_prio(cmd) G_STMT_START{ \
|
||||||
|
int err = posix_error (cmd); \
|
||||||
|
if (err == EPERM) \
|
||||||
|
{ \
|
||||||
|
if (!posix_check_cmd_prio_warned) \
|
||||||
|
{ \
|
||||||
|
posix_check_cmd_prio_warned = TRUE; \
|
||||||
|
g_warning ("Priorities can only be changed by root."); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
posix_check_err (err, #cmd); \
|
||||||
|
}G_STMT_END
|
||||||
|
#else /* G_ENABLE_DEBUG */
|
||||||
|
# define posix_check_cmd_prio(cmd) G_STMT_START{ \
|
||||||
|
int err = posix_error (cmd); \
|
||||||
|
if (err != EPERM) \
|
||||||
|
posix_check_err (err, #cmd); \
|
||||||
|
}G_STMT_END
|
||||||
|
#endif /* G_ENABLE_DEBUG */
|
||||||
|
|
||||||
#if defined(G_THREADS_IMPL_POSIX)
|
#if defined(G_THREADS_IMPL_POSIX)
|
||||||
# define posix_check_for_error( what ) G_STMT_START{ \
|
# define posix_error(what) (what)
|
||||||
int error = (what); \
|
|
||||||
if( error ) { posix_print_error( what, error ); } \
|
|
||||||
}G_STMT_END
|
|
||||||
# define mutexattr_default NULL
|
# define mutexattr_default NULL
|
||||||
# define condattr_default NULL
|
# define condattr_default NULL
|
||||||
#elif defined(G_THREADS_IMPL_DCE)
|
#elif defined(G_THREADS_IMPL_DCE)
|
||||||
# define posix_check_for_error( what ) G_STMT_START{ \
|
# define posix_error(what) ((what) == -1 ? errno : 0)
|
||||||
if( (what) == -1 ) { posix_print_error( what, errno ); } \
|
|
||||||
}G_STMT_END
|
|
||||||
# define pthread_key_create(a, b) pthread_keycreate (a, b)
|
# define pthread_key_create(a, b) pthread_keycreate (a, b)
|
||||||
# define pthread_attr_init(a) pthread_attr_create (a)
|
# define pthread_attr_init(a) pthread_attr_create (a)
|
||||||
# define pthread_attr_destroy(a) pthread_attr_delete (a)
|
# define pthread_attr_destroy(a) pthread_attr_delete (a)
|
||||||
# define pthread_create(a, b, c, d) pthread_create(a, *b, c, d)
|
# define pthread_create(a, b, c, d) pthread_create (a, *b, c, d)
|
||||||
# define mutexattr_default (pthread_mutexattr_default)
|
# define mutexattr_default (pthread_mutexattr_default)
|
||||||
# define condattr_default (pthread_condattr_default)
|
# define condattr_default (pthread_condattr_default)
|
||||||
#else /* neither G_THREADS_IMPL_POSIX nor G_THREADS_IMPL_DCE are defined */
|
#else /* neither G_THREADS_IMPL_POSIX nor G_THREADS_IMPL_DCE are defined */
|
||||||
# error This should not happen. Contact the GLib team.
|
# error This should not happen. Contact the GLib team.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(POSIX_MIN_PRIORITY) && defined(POSIX_MAX_PRIORITY)
|
#if defined (POSIX_MIN_PRIORITY) && defined (POSIX_MAX_PRIORITY)
|
||||||
# define HAVE_PRIORITIES 1
|
# define HAVE_PRIORITIES 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -92,7 +115,7 @@ static GMutex *
|
|||||||
g_mutex_new_posix_impl (void)
|
g_mutex_new_posix_impl (void)
|
||||||
{
|
{
|
||||||
GMutex *result = (GMutex *) g_new (pthread_mutex_t, 1);
|
GMutex *result = (GMutex *) g_new (pthread_mutex_t, 1);
|
||||||
posix_check_for_error (pthread_mutex_init ((pthread_mutex_t *) result,
|
posix_check_cmd (pthread_mutex_init ((pthread_mutex_t *) result,
|
||||||
mutexattr_default));
|
mutexattr_default));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -100,7 +123,7 @@ g_mutex_new_posix_impl (void)
|
|||||||
static void
|
static void
|
||||||
g_mutex_free_posix_impl (GMutex * mutex)
|
g_mutex_free_posix_impl (GMutex * mutex)
|
||||||
{
|
{
|
||||||
posix_check_for_error (pthread_mutex_destroy ((pthread_mutex_t *) mutex));
|
posix_check_cmd (pthread_mutex_destroy ((pthread_mutex_t *) mutex));
|
||||||
g_free (mutex);
|
g_free (mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,7 +149,7 @@ g_mutex_trylock_posix_impl (GMutex * mutex)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
posix_check_for_error (result);
|
posix_check_err (posix_error (result), "pthread_mutex_trylock");
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,7 +157,7 @@ static GCond *
|
|||||||
g_cond_new_posix_impl (void)
|
g_cond_new_posix_impl (void)
|
||||||
{
|
{
|
||||||
GCond *result = (GCond *) g_new (pthread_cond_t, 1);
|
GCond *result = (GCond *) g_new (pthread_cond_t, 1);
|
||||||
posix_check_for_error (pthread_cond_init ((pthread_cond_t *) result,
|
posix_check_cmd (pthread_cond_init ((pthread_cond_t *) result,
|
||||||
condattr_default));
|
condattr_default));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -178,14 +201,14 @@ g_cond_timed_wait_posix_impl (GCond * cond,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!timed_out)
|
if (!timed_out)
|
||||||
posix_check_for_error (result);
|
posix_check_err (posix_error (result), "pthread_cond_timedwait");
|
||||||
return !timed_out;
|
return !timed_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
g_cond_free_posix_impl (GCond * cond)
|
g_cond_free_posix_impl (GCond * cond)
|
||||||
{
|
{
|
||||||
posix_check_for_error (pthread_cond_destroy ((pthread_cond_t *) cond));
|
posix_check_cmd (pthread_cond_destroy ((pthread_cond_t *) cond));
|
||||||
g_free (cond);
|
g_free (cond);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,8 +216,7 @@ static GPrivate *
|
|||||||
g_private_new_posix_impl (GDestroyNotify destructor)
|
g_private_new_posix_impl (GDestroyNotify destructor)
|
||||||
{
|
{
|
||||||
GPrivate *result = (GPrivate *) g_new (pthread_key_t, 1);
|
GPrivate *result = (GPrivate *) g_new (pthread_key_t, 1);
|
||||||
posix_check_for_error (pthread_key_create ((pthread_key_t *) result,
|
posix_check_cmd (pthread_key_create ((pthread_key_t *) result, destructor));
|
||||||
destructor));
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,8 +241,8 @@ g_private_get_posix_impl (GPrivate * private_key)
|
|||||||
#else /* G_THREADS_IMPL_DCE */
|
#else /* G_THREADS_IMPL_DCE */
|
||||||
{
|
{
|
||||||
void* data;
|
void* data;
|
||||||
posix_check_for_error (pthread_getspecific (*(pthread_key_t *)
|
posix_check_cmd (pthread_getspecific (*(pthread_key_t *) private_key,
|
||||||
private_key, &data));
|
&data));
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -241,13 +263,13 @@ g_thread_create_posix_impl (GThreadFunc thread_func,
|
|||||||
|
|
||||||
g_return_if_fail (thread_func);
|
g_return_if_fail (thread_func);
|
||||||
|
|
||||||
posix_check_for_error (pthread_attr_init (&attr));
|
posix_check_cmd (pthread_attr_init (&attr));
|
||||||
|
|
||||||
#ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
|
#ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
|
||||||
if (stack_size)
|
if (stack_size)
|
||||||
{
|
{
|
||||||
stack_size = MAX (g_thread_min_stack_size, stack_size);
|
stack_size = MAX (g_thread_min_stack_size, stack_size);
|
||||||
posix_check_for_error (pthread_attr_setstacksize (&attr, stack_size));
|
posix_check_cmd (pthread_attr_setstacksize (&attr, stack_size));
|
||||||
}
|
}
|
||||||
#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
|
#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
|
||||||
|
|
||||||
@ -259,7 +281,7 @@ g_thread_create_posix_impl (GThreadFunc thread_func,
|
|||||||
#endif /* PTHREAD_SCOPE_SYSTEM */
|
#endif /* PTHREAD_SCOPE_SYSTEM */
|
||||||
|
|
||||||
#ifdef G_THREADS_IMPL_POSIX
|
#ifdef G_THREADS_IMPL_POSIX
|
||||||
posix_check_for_error (pthread_attr_setdetachstate (&attr,
|
posix_check_cmd (pthread_attr_setdetachstate (&attr,
|
||||||
joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
|
joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
|
||||||
#endif /* G_THREADS_IMPL_POSIX */
|
#endif /* G_THREADS_IMPL_POSIX */
|
||||||
|
|
||||||
@ -267,26 +289,20 @@ g_thread_create_posix_impl (GThreadFunc thread_func,
|
|||||||
# ifdef G_THREADS_IMPL_POSIX
|
# ifdef G_THREADS_IMPL_POSIX
|
||||||
{
|
{
|
||||||
struct sched_param sched;
|
struct sched_param sched;
|
||||||
posix_check_for_error (pthread_attr_getschedparam (&attr, &sched));
|
posix_check_cmd (pthread_attr_getschedparam (&attr, &sched));
|
||||||
sched.sched_priority = g_thread_map_priority (priority);
|
sched.sched_priority = g_thread_map_priority (priority);
|
||||||
posix_check_for_error (pthread_attr_setschedparam (&attr, &sched));
|
posix_check_cmd_prio (pthread_attr_setschedparam (&attr, &sched));
|
||||||
}
|
}
|
||||||
# else /* G_THREADS_IMPL_DCE */
|
# else /* G_THREADS_IMPL_DCE */
|
||||||
posix_check_for_error
|
posix_check_cmd_prio
|
||||||
(pthread_attr_setprio (&attr, g_thread_map_priority (priority)));
|
(pthread_attr_setprio (&attr, g_thread_map_priority (priority)));
|
||||||
# endif /* G_THREADS_IMPL_DCE */
|
# endif /* G_THREADS_IMPL_DCE */
|
||||||
#endif /* HAVE_PRIORITIES */
|
#endif /* HAVE_PRIORITIES */
|
||||||
|
|
||||||
ret = pthread_create (thread, &attr, (void* (*)(void*))thread_func, arg);
|
ret = posix_error (pthread_create (thread, &attr,
|
||||||
|
(void* (*)(void*))thread_func, arg));
|
||||||
|
|
||||||
#ifdef G_THREADS_IMPL_DCE
|
posix_check_cmd (pthread_attr_destroy (&attr));
|
||||||
if (ret == -1)
|
|
||||||
ret = errno;
|
|
||||||
else
|
|
||||||
ret = 0;
|
|
||||||
#endif /* G_THREADS_IMPL_DCE */
|
|
||||||
|
|
||||||
posix_check_for_error (pthread_attr_destroy (&attr));
|
|
||||||
|
|
||||||
if (ret == EAGAIN)
|
if (ret == EAGAIN)
|
||||||
{
|
{
|
||||||
@ -295,11 +311,11 @@ g_thread_create_posix_impl (GThreadFunc thread_func,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
posix_check_for_error (ret);
|
posix_check_err (ret, "pthread_create");
|
||||||
|
|
||||||
#ifdef G_THREADS_IMPL_DCE
|
#ifdef G_THREADS_IMPL_DCE
|
||||||
if (!joinable)
|
if (!joinable)
|
||||||
posix_check_for_error (pthread_detach (thread));
|
posix_check_cmd (pthread_detach (thread));
|
||||||
#endif /* G_THREADS_IMPL_DCE */
|
#endif /* G_THREADS_IMPL_DCE */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,8 +329,7 @@ static void
|
|||||||
g_thread_join_posix_impl (gpointer thread)
|
g_thread_join_posix_impl (gpointer thread)
|
||||||
{
|
{
|
||||||
gpointer ignore;
|
gpointer ignore;
|
||||||
posix_check_for_error (pthread_join (*(pthread_t*)thread,
|
posix_check_cmd (pthread_join (*(pthread_t*)thread, &ignore));
|
||||||
&ignore));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -330,13 +345,13 @@ g_thread_set_priority_posix_impl (gpointer thread, GThreadPriority priority)
|
|||||||
# ifdef G_THREADS_IMPL_POSIX
|
# ifdef G_THREADS_IMPL_POSIX
|
||||||
struct sched_param sched;
|
struct sched_param sched;
|
||||||
int policy;
|
int policy;
|
||||||
posix_check_for_error (pthread_getschedparam (*(pthread_t*)thread,
|
posix_check_cmd (pthread_getschedparam (*(pthread_t*)thread, &policy,
|
||||||
&policy, &sched));
|
&sched));
|
||||||
sched.sched_priority = g_thread_map_priority (priority);
|
sched.sched_priority = g_thread_map_priority (priority);
|
||||||
posix_check_for_error (pthread_setschedparam (*(pthread_t*)thread,
|
posix_check_cmd_prio (pthread_setschedparam (*(pthread_t*)thread, policy,
|
||||||
policy, &sched));
|
&sched));
|
||||||
# else /* G_THREADS_IMPL_DCE */
|
# else /* G_THREADS_IMPL_DCE */
|
||||||
posix_check_for_error (pthread_setprio (*(pthread_t*)thread,
|
posix_check_cmd_prio (pthread_setprio (*(pthread_t*)thread,
|
||||||
g_thread_map_priority (priority)));
|
g_thread_map_priority (priority)));
|
||||||
# endif
|
# endif
|
||||||
#endif /* HAVE_PRIORITIES */
|
#endif /* HAVE_PRIORITIES */
|
||||||
|
Loading…
Reference in New Issue
Block a user