1998-12-15 06:28:02 +01:00
|
|
|
/* GLIB - Library of useful routines for C programming
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* gthread.c: posix thread system implementation
|
|
|
|
* Copyright 1998 Sebastian Wilhelmi; University of Karlsruhe
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2000-07-26 13:02:02 +02:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
1998-12-15 06:28:02 +01:00
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2000-07-26 13:02:02 +02:00
|
|
|
* Lesser General Public License for more details.
|
1998-12-15 06:28:02 +01:00
|
|
|
*
|
2000-07-26 13:02:02 +02:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
1998-12-15 06:28:02 +01:00
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
1999-02-24 07:14:27 +01:00
|
|
|
/*
|
2000-07-26 13:02:02 +02:00
|
|
|
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:14:27 +01:00
|
|
|
* file for a list of people on the GLib Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
2006-05-11 02:08:31 +02:00
|
|
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
1999-02-24 07:14:27 +01:00
|
|
|
*/
|
|
|
|
|
2006-05-11 02:08:31 +02:00
|
|
|
/*
|
1998-12-15 06:28:02 +01:00
|
|
|
* MT safe
|
|
|
|
*/
|
|
|
|
|
2006-05-10 01:07:27 +02:00
|
|
|
#include "config.h"
|
2002-11-04 21:09:48 +01:00
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
Merge in current Win32 version. Almost no Unix code touched.
* README.win32: More text.
* config.h.win32 glibconfig.h.win32: Update to match the
corresponding generated files on Unix.
* makefile.msc: Update with new source files, and gthread
library. Use the compiler flag -MD instead of using -D_DLL and
"/nodefaultlib:libc msvcrt.lib" in the link phase.
* glib.def: Include new functions, drop removed ones.
* glib.h: Add comments about main loop and polling on Win32. (In
general, it's only for the GIMP's use.) Add Win32 IO Channel
functions. Remove the obsoleted old IO Channel stuff (which was
in #if 0 already).
* giowin32.c: New file.
* gmain.c: Include config.h, conditionalize <sys/time.h>
inclusion. Add g_poll implementation for Win32 (only for the
GIMP's needs for now, it's hard or even impossible to be as clean
and generic as on Unix). Implement g_get_current_time on Win32. If
threads aren't supported, don't try to wake up main thread's
loop. On Win32, use a semaphore and not a pipe to wake up the main
loop.
* gmessages.c: On Win32, allocate a console window if the standard
output handle is invalid before writing to stdout, and reopen stdout
to that console window.
* giochannel.c: Conditionalize unistd.h inclusion. Some indentation
cleanup.
* gstrfuncs.c: Include <signal.h>.
* gutils.c: On Win32, also check the HOMEDRIVE and HOMEPATH
environment variables.
* gmodule-dl.c gmodule-dld.c: In
_g_module_build_path, don't add the "lib" prefix and
".so" or ".sl" suffix if already there.
* gmodule-win32.c: Likewise for the ".dll" suffix.
* gthread-posix.c: Conditionalize <sys/time.h> inclusion.
1999-01-17 00:46:42 +01:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
2000-11-21 16:27:44 +01:00
|
|
|
# include <sys/time.h>
|
Merge in current Win32 version. Almost no Unix code touched.
* README.win32: More text.
* config.h.win32 glibconfig.h.win32: Update to match the
corresponding generated files on Unix.
* makefile.msc: Update with new source files, and gthread
library. Use the compiler flag -MD instead of using -D_DLL and
"/nodefaultlib:libc msvcrt.lib" in the link phase.
* glib.def: Include new functions, drop removed ones.
* glib.h: Add comments about main loop and polling on Win32. (In
general, it's only for the GIMP's use.) Add Win32 IO Channel
functions. Remove the obsoleted old IO Channel stuff (which was
in #if 0 already).
* giowin32.c: New file.
* gmain.c: Include config.h, conditionalize <sys/time.h>
inclusion. Add g_poll implementation for Win32 (only for the
GIMP's needs for now, it's hard or even impossible to be as clean
and generic as on Unix). Implement g_get_current_time on Win32. If
threads aren't supported, don't try to wake up main thread's
loop. On Win32, use a semaphore and not a pipe to wake up the main
loop.
* gmessages.c: On Win32, allocate a console window if the standard
output handle is invalid before writing to stdout, and reopen stdout
to that console window.
* giochannel.c: Conditionalize unistd.h inclusion. Some indentation
cleanup.
* gstrfuncs.c: Include <signal.h>.
* gutils.c: On Win32, also check the HOMEDRIVE and HOMEPATH
environment variables.
* gmodule-dl.c gmodule-dld.c: In
_g_module_build_path, don't add the "lib" prefix and
".so" or ".sl" suffix if already there.
* gmodule-win32.c: Likewise for the ".dll" suffix.
* gthread-posix.c: Conditionalize <sys/time.h> inclusion.
1999-01-17 00:46:42 +01:00
|
|
|
#endif
|
2000-02-22 14:11:24 +01:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2000-11-21 16:27:44 +01:00
|
|
|
# include <unistd.h>
|
2000-02-22 14:11:24 +01:00
|
|
|
#endif
|
2000-11-21 16:27:44 +01:00
|
|
|
|
2000-11-15 18:48:43 +01:00
|
|
|
#ifdef HAVE_SCHED_H
|
|
|
|
#include <sched.h>
|
|
|
|
#endif
|
1998-12-15 06:28:02 +01:00
|
|
|
|
2000-10-25 12:58:46 +02:00
|
|
|
#define posix_check_err(err, name) G_STMT_START{ \
|
|
|
|
int error = (err); \
|
|
|
|
if (error) \
|
2000-11-21 16:27:44 +01:00
|
|
|
g_error ("file %s: line %d (%s): error '%s' during '%s'", \
|
2008-02-10 05:41:25 +01:00
|
|
|
__FILE__, __LINE__, G_STRFUNC, \
|
2000-10-25 12:58:46 +02:00
|
|
|
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; \
|
2000-11-21 16:27:44 +01:00
|
|
|
g_warning ("Priorities can only be changed " \
|
|
|
|
"(resp. increased) by root."); \
|
2000-10-25 12:58:46 +02:00
|
|
|
} \
|
|
|
|
} \
|
|
|
|
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 */
|
1998-12-15 06:28:02 +01:00
|
|
|
|
2011-08-31 22:41:24 +02:00
|
|
|
#define posix_error(what) (what)
|
|
|
|
#define mutexattr_default NULL
|
|
|
|
#define condattr_default NULL
|
1998-12-15 06:28:02 +01:00
|
|
|
|
2001-02-15 17:43:02 +01:00
|
|
|
#if defined (POSIX_MIN_PRIORITY) && defined (POSIX_MAX_PRIORITY)
|
2000-11-21 16:27:44 +01:00
|
|
|
# define HAVE_PRIORITIES 1
|
2002-08-06 15:31:26 +02:00
|
|
|
static gint priority_normal_value;
|
2001-04-03 14:49:44 +02:00
|
|
|
# ifdef __FreeBSD__
|
|
|
|
/* FreeBSD threads use different priority values from the POSIX_
|
|
|
|
* defines so we just set them here. The corresponding macros
|
|
|
|
* PTHREAD_MIN_PRIORITY and PTHREAD_MAX_PRIORITY are implied to be
|
|
|
|
* exported by the docs, but they aren't.
|
|
|
|
*/
|
|
|
|
# define PRIORITY_LOW_VALUE 0
|
|
|
|
# define PRIORITY_URGENT_VALUE 31
|
|
|
|
# else /* !__FreeBSD__ */
|
2002-08-06 15:31:26 +02:00
|
|
|
# define PRIORITY_LOW_VALUE POSIX_MIN_PRIORITY
|
|
|
|
# define PRIORITY_URGENT_VALUE POSIX_MAX_PRIORITY
|
2001-04-03 14:49:44 +02:00
|
|
|
# endif /* !__FreeBSD__ */
|
2002-08-06 15:31:26 +02:00
|
|
|
# define PRIORITY_NORMAL_VALUE priority_normal_value
|
2000-11-21 16:27:44 +01:00
|
|
|
#endif /* POSIX_MIN_PRIORITY && POSIX_MAX_PRIORITY */
|
Added the missing POSIX_NO_YIELD and POSIX_NO_PRIORITIES warning messages.
2000-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added the missing POSIX_NO_YIELD and
POSIX_NO_PRIORITIES warning messages.
* configure.in: Use AC_TRY_RUN instead of AC_TRY_LINK, to test for
real thread support. On solaris pthread_create can be linked to
even in -lc, but it doesn't work then.
* configure.in: Don't use priorities for threads, when the
minimal/maximal priorities couldn't be determined at configure
time.
* configure.in, gthread.c: Always define GSystemThread in
glibconfig.h to represent a system thread.
* configure.in: Do not use native recursive threads, when
possibe. We use some features, that they do not expose (namely the
depth counter).
* glib.h, gthread.c: Redefined GStaticRecMutex. The functions are
now implemented in a different way, which should be way
faster. Alsothere are now functions g_static_rec_mutex_unlock_full
and g_static_rec_mutex_lock_full to leave/enter a recursive mutex
completly.
* gthread.c (g_thread_self): Do not test the system_thread to be
non-zero to speed things up.
* gthread.c (g_mutex_init): Therefore set the system_thread of the
main thread here.
* tests/thread-test.c: Rerun all tests once again, but this time
we fool the system into thinking, that the available thread system
is not native, but userprovided.
* gthread/gthread-posix.c: Don't use priorities for threads,
when the minimal/maximal priorities couldn't be determined at
configure time.
* gthread/gthread-posix.c: Don't check for errors, when
setting the scope of a tread to system, as some posix
implementations can't do that and we don't want the thing to
fail because of that.
2000-03-17 15:49:59 +01:00
|
|
|
|
2001-01-03 18:00:43 +01:00
|
|
|
static gulong g_thread_min_stack_size = 0;
|
2000-02-22 14:11:24 +01:00
|
|
|
|
2000-09-29 15:10:41 +02:00
|
|
|
#define G_MUTEX_SIZE (sizeof (pthread_mutex_t))
|
|
|
|
|
2011-08-31 21:49:35 +02:00
|
|
|
#if defined(_SC_THREAD_STACK_MIN) || defined (HAVE_PRIORITIES)
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
#define HAVE_G_THREAD_IMPL_INIT
|
2006-05-11 02:08:31 +02:00
|
|
|
static void
|
2004-11-01 19:47:12 +01:00
|
|
|
g_thread_impl_init(void)
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
{
|
2002-08-06 15:31:26 +02:00
|
|
|
#ifdef _SC_THREAD_STACK_MIN
|
2000-02-22 14:11:24 +01:00
|
|
|
g_thread_min_stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), 0);
|
2000-11-21 16:27:44 +01:00
|
|
|
#endif /* _SC_THREAD_STACK_MIN */
|
2002-08-06 15:31:26 +02:00
|
|
|
#ifdef HAVE_PRIORITIES
|
|
|
|
{
|
|
|
|
struct sched_param sched;
|
|
|
|
int policy;
|
|
|
|
posix_check_cmd (pthread_getschedparam (pthread_self(), &policy, &sched));
|
|
|
|
priority_normal_value = sched.sched_priority;
|
|
|
|
}
|
|
|
|
#endif /* HAVE_PRIORITIES */
|
|
|
|
}
|
|
|
|
#endif /* _SC_THREAD_STACK_MIN || HAVE_PRIORITIES */
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
static GMutex *
|
|
|
|
g_mutex_new_posix_impl (void)
|
|
|
|
{
|
|
|
|
GMutex *result = (GMutex *) g_new (pthread_mutex_t, 1);
|
2006-05-11 02:08:31 +02:00
|
|
|
posix_check_cmd (pthread_mutex_init ((pthread_mutex_t *) result,
|
2000-10-25 12:58:46 +02:00
|
|
|
mutexattr_default));
|
1998-12-15 06:28:02 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_mutex_free_posix_impl (GMutex * mutex)
|
|
|
|
{
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_cmd (pthread_mutex_destroy ((pthread_mutex_t *) mutex));
|
1998-12-17 05:36:04 +01:00
|
|
|
g_free (mutex);
|
1998-12-15 06:28:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: the functions g_mutex_lock and g_mutex_unlock may not use
|
|
|
|
functions from gmem.c and gmessages.c; */
|
|
|
|
|
|
|
|
/* pthread_mutex_lock, pthread_mutex_unlock can be taken directly, as
|
|
|
|
signature and semantic are right, but without error check then!!!!,
|
|
|
|
we might want to change this therefore. */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_mutex_trylock_posix_impl (GMutex * mutex)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
result = pthread_mutex_trylock ((pthread_mutex_t *) mutex);
|
1999-03-11 18:38:51 +01:00
|
|
|
|
|
|
|
if (result == EBUSY)
|
1998-12-15 06:28:02 +01:00
|
|
|
return FALSE;
|
|
|
|
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_err (posix_error (result), "pthread_mutex_trylock");
|
1998-12-15 06:28:02 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GCond *
|
|
|
|
g_cond_new_posix_impl (void)
|
|
|
|
{
|
|
|
|
GCond *result = (GCond *) g_new (pthread_cond_t, 1);
|
2006-05-11 02:08:31 +02:00
|
|
|
posix_check_cmd (pthread_cond_init ((pthread_cond_t *) result,
|
2000-10-25 12:58:46 +02:00
|
|
|
condattr_default));
|
1998-12-15 06:28:02 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
2006-05-11 02:08:31 +02:00
|
|
|
therefore. */
|
1998-12-15 06:28:02 +01:00
|
|
|
|
2000-09-06 15:56:17 +02:00
|
|
|
#define G_NSEC_PER_SEC 1000000000
|
1998-12-15 06:28:02 +01:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
g_cond_timed_wait_posix_impl (GCond * cond,
|
|
|
|
GMutex * entered_mutex,
|
|
|
|
GTimeVal * abs_time)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
struct timespec end_time;
|
|
|
|
gboolean timed_out;
|
|
|
|
|
|
|
|
g_return_val_if_fail (cond != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (entered_mutex != NULL, FALSE);
|
|
|
|
|
|
|
|
if (!abs_time)
|
|
|
|
{
|
2006-05-11 02:08:31 +02:00
|
|
|
result = pthread_cond_wait ((pthread_cond_t *)cond,
|
|
|
|
(pthread_mutex_t *) entered_mutex);
|
|
|
|
timed_out = FALSE;
|
1998-12-15 06:28:02 +01:00
|
|
|
}
|
2006-05-11 02:08:31 +02:00
|
|
|
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);
|
1998-12-15 06:28:02 +01:00
|
|
|
|
2006-05-11 02:08:31 +02:00
|
|
|
g_return_val_if_fail (end_time.tv_nsec < G_NSEC_PER_SEC, TRUE);
|
1999-03-11 18:38:51 +01:00
|
|
|
|
2006-05-11 02:08:31 +02:00
|
|
|
result = pthread_cond_timedwait ((pthread_cond_t *) cond,
|
|
|
|
(pthread_mutex_t *) entered_mutex,
|
|
|
|
&end_time);
|
|
|
|
timed_out = (result == ETIMEDOUT);
|
|
|
|
}
|
1999-03-11 18:38:51 +01:00
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
if (!timed_out)
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_err (posix_error (result), "pthread_cond_timedwait");
|
2006-05-11 02:08:31 +02:00
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
return !timed_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_cond_free_posix_impl (GCond * cond)
|
|
|
|
{
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_cmd (pthread_cond_destroy ((pthread_cond_t *) cond));
|
1998-12-15 06:28:02 +01:00
|
|
|
g_free (cond);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GPrivate *
|
|
|
|
g_private_new_posix_impl (GDestroyNotify destructor)
|
|
|
|
{
|
|
|
|
GPrivate *result = (GPrivate *) g_new (pthread_key_t, 1);
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_cmd (pthread_key_create ((pthread_key_t *) result, destructor));
|
1998-12-15 06:28:02 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* NOTE: the functions g_private_get and g_private_set may not use
|
|
|
|
functions from gmem.c and gmessages.c */
|
|
|
|
|
|
|
|
static void
|
1998-12-15 18:49:30 +01:00
|
|
|
g_private_set_posix_impl (GPrivate * private_key, gpointer value)
|
1998-12-15 06:28:02 +01:00
|
|
|
{
|
1998-12-15 18:49:30 +01:00
|
|
|
if (!private_key)
|
1998-12-15 06:28:02 +01:00
|
|
|
return;
|
1998-12-15 18:49:30 +01:00
|
|
|
pthread_setspecific (*(pthread_key_t *) private_key, value);
|
1998-12-15 06:28:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
1998-12-15 18:49:30 +01:00
|
|
|
g_private_get_posix_impl (GPrivate * private_key)
|
1998-12-15 06:28:02 +01:00
|
|
|
{
|
1998-12-15 18:49:30 +01:00
|
|
|
if (!private_key)
|
1998-12-15 06:28:02 +01:00
|
|
|
return NULL;
|
2011-08-31 22:41:24 +02:00
|
|
|
|
1998-12-15 18:49:30 +01:00
|
|
|
return pthread_getspecific (*(pthread_key_t *) private_key);
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
}
|
|
|
|
|
1999-11-16 11:29:27 +01:00
|
|
|
static void
|
2006-05-11 02:08:31 +02:00
|
|
|
g_thread_create_posix_impl (GThreadFunc thread_func,
|
|
|
|
gpointer arg,
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
gulong stack_size,
|
|
|
|
gboolean joinable,
|
|
|
|
gboolean bound,
|
1999-11-16 11:29:27 +01:00
|
|
|
GThreadPriority priority,
|
2000-09-01 15:03:23 +02:00
|
|
|
gpointer thread,
|
|
|
|
GError **error)
|
1999-11-16 11:29:27 +01:00
|
|
|
{
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
pthread_attr_t attr;
|
2000-09-01 15:03:23 +02:00
|
|
|
gint ret;
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
|
1999-11-16 11:29:27 +01:00
|
|
|
g_return_if_fail (thread_func);
|
2000-11-21 16:27:44 +01:00
|
|
|
g_return_if_fail (priority >= G_THREAD_PRIORITY_LOW);
|
|
|
|
g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_cmd (pthread_attr_init (&attr));
|
2006-05-11 02:08:31 +02:00
|
|
|
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
#ifdef HAVE_PTHREAD_ATTR_SETSTACKSIZE
|
|
|
|
if (stack_size)
|
2000-02-22 14:11:24 +01:00
|
|
|
{
|
|
|
|
stack_size = MAX (g_thread_min_stack_size, stack_size);
|
2005-06-09 17:25:01 +02:00
|
|
|
/* No error check here, because some systems can't do it and
|
|
|
|
* we simply don't want threads to fail because of that. */
|
|
|
|
pthread_attr_setstacksize (&attr, stack_size);
|
2000-02-22 14:11:24 +01:00
|
|
|
}
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
#endif /* HAVE_PTHREAD_ATTR_SETSTACKSIZE */
|
|
|
|
|
1999-11-16 11:29:27 +01:00
|
|
|
#ifdef PTHREAD_SCOPE_SYSTEM
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
if (bound)
|
Added the missing POSIX_NO_YIELD and POSIX_NO_PRIORITIES warning messages.
2000-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added the missing POSIX_NO_YIELD and
POSIX_NO_PRIORITIES warning messages.
* configure.in: Use AC_TRY_RUN instead of AC_TRY_LINK, to test for
real thread support. On solaris pthread_create can be linked to
even in -lc, but it doesn't work then.
* configure.in: Don't use priorities for threads, when the
minimal/maximal priorities couldn't be determined at configure
time.
* configure.in, gthread.c: Always define GSystemThread in
glibconfig.h to represent a system thread.
* configure.in: Do not use native recursive threads, when
possibe. We use some features, that they do not expose (namely the
depth counter).
* glib.h, gthread.c: Redefined GStaticRecMutex. The functions are
now implemented in a different way, which should be way
faster. Alsothere are now functions g_static_rec_mutex_unlock_full
and g_static_rec_mutex_lock_full to leave/enter a recursive mutex
completly.
* gthread.c (g_thread_self): Do not test the system_thread to be
non-zero to speed things up.
* gthread.c (g_mutex_init): Therefore set the system_thread of the
main thread here.
* tests/thread-test.c: Rerun all tests once again, but this time
we fool the system into thinking, that the available thread system
is not native, but userprovided.
* gthread/gthread-posix.c: Don't use priorities for threads,
when the minimal/maximal priorities couldn't be determined at
configure time.
* gthread/gthread-posix.c: Don't check for errors, when
setting the scope of a tread to system, as some posix
implementations can't do that and we don't want the thing to
fail because of that.
2000-03-17 15:49:59 +01:00
|
|
|
/* No error check here, because some systems can't do it and we
|
|
|
|
* simply don't want threads to fail because of that. */
|
|
|
|
pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
|
1999-11-16 11:29:27 +01:00
|
|
|
#endif /* PTHREAD_SCOPE_SYSTEM */
|
1999-06-21 00:20:43 +02:00
|
|
|
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_cmd (pthread_attr_setdetachstate (&attr,
|
1999-11-16 11:29:27 +01:00
|
|
|
joinable ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED));
|
2006-05-11 02:08:31 +02:00
|
|
|
|
2001-02-15 17:43:02 +01:00
|
|
|
#ifdef HAVE_PRIORITIES
|
1999-11-16 11:29:27 +01:00
|
|
|
{
|
|
|
|
struct sched_param sched;
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_cmd (pthread_attr_getschedparam (&attr, &sched));
|
2000-11-21 16:27:44 +01:00
|
|
|
sched.sched_priority = g_thread_priority_map [priority];
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_cmd_prio (pthread_attr_setschedparam (&attr, &sched));
|
1999-11-16 11:29:27 +01:00
|
|
|
}
|
2001-02-15 17:43:02 +01:00
|
|
|
#endif /* HAVE_PRIORITIES */
|
2006-05-11 02:08:31 +02:00
|
|
|
ret = posix_error (pthread_create (thread, &attr,
|
2000-10-25 12:58:46 +02:00
|
|
|
(void* (*)(void*))thread_func, arg));
|
2000-11-21 16:27:44 +01:00
|
|
|
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_cmd (pthread_attr_destroy (&attr));
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
|
2000-09-01 15:33:04 +02:00
|
|
|
if (ret == EAGAIN)
|
2000-09-01 15:03:23 +02:00
|
|
|
{
|
|
|
|
g_set_error (error, G_THREAD_ERROR, G_THREAD_ERROR_AGAIN,
|
|
|
|
"Error creating thread: %s", g_strerror (ret));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_err (ret, "pthread_create");
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
}
|
|
|
|
|
2006-05-11 02:08:31 +02:00
|
|
|
static void
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
g_thread_yield_posix_impl (void)
|
|
|
|
{
|
|
|
|
POSIX_YIELD_FUNC;
|
|
|
|
}
|
|
|
|
|
1999-11-16 11:29:27 +01:00
|
|
|
static void
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
g_thread_join_posix_impl (gpointer thread)
|
2006-05-11 02:08:31 +02:00
|
|
|
{
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
gpointer ignore;
|
2000-10-25 12:58:46 +02:00
|
|
|
posix_check_cmd (pthread_join (*(pthread_t*)thread, &ignore));
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
}
|
|
|
|
|
2006-05-11 02:08:31 +02:00
|
|
|
static void
|
|
|
|
g_thread_exit_posix_impl (void)
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
{
|
|
|
|
pthread_exit (NULL);
|
1998-12-15 06:28:02 +01:00
|
|
|
}
|
|
|
|
|
1999-11-16 11:29:27 +01:00
|
|
|
static void
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
g_thread_set_priority_posix_impl (gpointer thread, GThreadPriority priority)
|
|
|
|
{
|
2000-11-21 16:27:44 +01:00
|
|
|
g_return_if_fail (priority >= G_THREAD_PRIORITY_LOW);
|
|
|
|
g_return_if_fail (priority <= G_THREAD_PRIORITY_URGENT);
|
Added the missing POSIX_NO_YIELD and POSIX_NO_PRIORITIES warning messages.
2000-03-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in: Added the missing POSIX_NO_YIELD and
POSIX_NO_PRIORITIES warning messages.
* configure.in: Use AC_TRY_RUN instead of AC_TRY_LINK, to test for
real thread support. On solaris pthread_create can be linked to
even in -lc, but it doesn't work then.
* configure.in: Don't use priorities for threads, when the
minimal/maximal priorities couldn't be determined at configure
time.
* configure.in, gthread.c: Always define GSystemThread in
glibconfig.h to represent a system thread.
* configure.in: Do not use native recursive threads, when
possibe. We use some features, that they do not expose (namely the
depth counter).
* glib.h, gthread.c: Redefined GStaticRecMutex. The functions are
now implemented in a different way, which should be way
faster. Alsothere are now functions g_static_rec_mutex_unlock_full
and g_static_rec_mutex_lock_full to leave/enter a recursive mutex
completly.
* gthread.c (g_thread_self): Do not test the system_thread to be
non-zero to speed things up.
* gthread.c (g_mutex_init): Therefore set the system_thread of the
main thread here.
* tests/thread-test.c: Rerun all tests once again, but this time
we fool the system into thinking, that the available thread system
is not native, but userprovided.
* gthread/gthread-posix.c: Don't use priorities for threads,
when the minimal/maximal priorities couldn't be determined at
configure time.
* gthread/gthread-posix.c: Don't check for errors, when
setting the scope of a tread to system, as some posix
implementations can't do that and we don't want the thing to
fail because of that.
2000-03-17 15:49:59 +01:00
|
|
|
#ifdef HAVE_PRIORITIES
|
2000-11-21 16:27:44 +01:00
|
|
|
{
|
|
|
|
struct sched_param sched;
|
|
|
|
int policy;
|
2006-05-11 02:08:31 +02:00
|
|
|
posix_check_cmd (pthread_getschedparam (*(pthread_t*)thread, &policy,
|
2000-11-21 16:27:44 +01:00
|
|
|
&sched));
|
|
|
|
sched.sched_priority = g_thread_priority_map [priority];
|
2006-05-11 02:08:31 +02:00
|
|
|
posix_check_cmd_prio (pthread_setschedparam (*(pthread_t*)thread, policy,
|
2000-11-21 16:27:44 +01:00
|
|
|
&sched));
|
|
|
|
}
|
2001-02-15 17:43:02 +01:00
|
|
|
#endif /* HAVE_PRIORITIES */
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
}
|
|
|
|
|
1999-11-16 11:29:27 +01:00
|
|
|
static void
|
|
|
|
g_thread_self_posix_impl (gpointer thread)
|
|
|
|
{
|
|
|
|
*(pthread_t*)thread = pthread_self();
|
|
|
|
}
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
|
2001-09-19 14:46:39 +02:00
|
|
|
static gboolean
|
|
|
|
g_thread_equal_posix_impl (gpointer thread1, gpointer thread2)
|
|
|
|
{
|
|
|
|
return (pthread_equal (*(pthread_t*)thread1, *(pthread_t*)thread2) != 0);
|
|
|
|
}
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
static GThreadFunctions g_thread_functions_for_glib_use_default =
|
|
|
|
{
|
|
|
|
g_mutex_new_posix_impl,
|
|
|
|
(void (*)(GMutex *)) pthread_mutex_lock,
|
|
|
|
g_mutex_trylock_posix_impl,
|
|
|
|
(void (*)(GMutex *)) pthread_mutex_unlock,
|
|
|
|
g_mutex_free_posix_impl,
|
|
|
|
g_cond_new_posix_impl,
|
|
|
|
(void (*)(GCond *)) pthread_cond_signal,
|
|
|
|
(void (*)(GCond *)) pthread_cond_broadcast,
|
|
|
|
(void (*)(GCond *, GMutex *)) pthread_cond_wait,
|
|
|
|
g_cond_timed_wait_posix_impl,
|
|
|
|
g_cond_free_posix_impl,
|
|
|
|
g_private_new_posix_impl,
|
|
|
|
g_private_get_posix_impl,
|
Completed the thread support in GLib. Thread creation, prioritizing
1999-06-17 Sebastian Wilhelmi <wilhelmi@ira.uka.de>
* configure.in, acglib.m4, acconfig.h, glib.h, gthread.c:
Completed the thread support in GLib. Thread creation,
prioritizing threads, yielding, joining threads as well as
reader/writer locks and recursive mutexes are now in place. Please
test heavily on your platform. It is so far tested on
Linux/i386/pthreads, Solaris/Sparc/pthreads and
Solaris/Sparc/solaristhreads.
* gtimer.c, glib.h: Implement g_usleep (gulong microseconds) for
thread safe sleeping. (sleep() is not MT-safe at all!)
* gutils.c: Avoid compiler warning.
* tests/Makefile.am, tests/thread-test.c: New program to test some
aspects of the thread implementation.
* gthread.c, Makefile.am: Renamed from gmutex.c to reflect the
change of content.
* configure.in: Purged all appearances of nspr.
* gthread/gthread-posix.c, gthread-solaris.c: Added the native
implementations for the GLib's extended thread support.
* gthread/gthread-nspr.c: Removed for good. NSPR is nothing we
would want to build upon.
* gthread/gthread.c: Renamed to gthread-impl.c to avoid
confusion with ../gthread.c (Formerly known as the file called
gmutex.c)
* gthread/testgthread.c: Removed. The new and much extended
tests are in ../tests/thread-test.c.
* gthread/Makefile.am: Changed to reflect the changes above.
1999-06-17 17:39:31 +02:00
|
|
|
g_private_set_posix_impl,
|
|
|
|
g_thread_create_posix_impl,
|
|
|
|
g_thread_yield_posix_impl,
|
|
|
|
g_thread_join_posix_impl,
|
|
|
|
g_thread_exit_posix_impl,
|
|
|
|
g_thread_set_priority_posix_impl,
|
2001-09-19 14:46:39 +02:00
|
|
|
g_thread_self_posix_impl,
|
2007-01-16 22:25:03 +01:00
|
|
|
g_thread_equal_posix_impl
|
1998-12-15 06:28:02 +01:00
|
|
|
};
|