From a311086d622d3c778e1da57cfae167c0ab1c0fb4 Mon Sep 17 00:00:00 2001 From: rpj Date: Sun, 1 Jul 2001 13:23:10 +0000 Subject: 2001-06-25 Ross Johnson * create.c (pthread_create): Add priority inheritance attributes. * mutex.c (pthread_mutex_lock): Remove some overhead for PTHREAD_MUTEX_NORMAL mutex types. Specifically, avoid calling pthread_self() and pthread_equal() to check/set the mutex owner. Introduce a new pseudo owner for this type. Test results suggest increases in speed of up to 90% for non-blocking locks. This is the default type of mutex used internally by other synchronising objects, ie. condition variables and read-write locks. The test rwlock7.c shows about a 30-35% speed increase over snapshot 2001-06-06. The price of this is that the application developer must ensure correct behaviour, or explicitly set the mutex to a safer type such as PTHREAD_MUTEX_ERRORCHECK. For example, PTHREAD_MUTEX_NORMAL (or PTHREAD_MUTEX_DEFAULT) type mutexes will not return an error if a thread which is not the owner calls pthread_mutex_unlock. The call will succeed in unlocking the mutex if it is currently locked, but a subsequent unlock by the true owner will then fail with EPERM. This is however consistent with some other implementations. (pthread_mutex_unlock): Likewise. (pthread_mutex_trylock): Likewise. (pthread_mutex_destroy): Likewise. * attr.c (pthread_attr_init): PTHREAD_EXPLICIT_SCHED is the default inheritance attribute; THREAD_PRIORITY_NORMAL is the default priority for new threads. * sched.c (pthread_attr_setschedpolicy): Added routine. (pthread_attr_getschedpolicy): Added routine. (pthread_attr_setinheritsched): Added routine. (pthread_attr_getinheritsched): Added routine. * pthread.h (sched_rr_set_interval): Added as a macro; returns -1 with errno set to ENOSYS. 2001-06-23 Ross Johnson *sched.c (pthread_attr_setschedparam): Add priority range check. (sched_setscheduler): New function; checks for a valid pid and policy; checks for permission to set information in the target process; expects pid to be a Win32 process ID, not a process handle; the only scheduler policy allowed is SCHED_OTHER. (sched_getscheduler): Likewise, but checks for permission to query. * pthread.h (SCHED_*): Moved to sched.h as defined in the POSIX standard. * sched.h (SCHED_*): Moved from pthread.h. (pid_t): Defined if necessary. (sched_setscheduler): Defined. (sched_getscheduler): Defined. * pthread.def (sched_setscheduler): Exported. (sched_getscheduler): Likewise. 2001-06-23 Ross Johnson Contributed by - Ralf Brese * create.c (pthread_create): Set thread priority from thread attributes. --- pthread.h | 98 +++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 41 deletions(-) (limited to 'pthread.h') diff --git a/pthread.h b/pthread.h index d4cfd13..a860cd1 100644 --- a/pthread.h +++ b/pthread.h @@ -22,6 +22,9 @@ #if !defined( PTHREAD_H ) #define PTHREAD_H +#if !defined( PTW32_HEADER ) +#define PTW32_HEADER + #ifdef _UWIN # define HAVE_STRUCT_TIMESPEC 1 # define HAVE_SIGNAL_H 1 @@ -29,6 +32,8 @@ # pragma comment(lib, "pthread") #endif +#endif /* PTW32_HEADER */ + /* * ------------------------------------------------------------- * @@ -120,7 +125,8 @@ #include -#ifndef HAVE_STRUCT_TIMESPEC +#if ! defined(HAVE_STRUCT_TIMESPEC) && ! defined(PTW32_TIMESPEC) +#define PTW32_TIMESPEC struct timespec { long tv_sec; long tv_nsec; @@ -145,11 +151,13 @@ struct timespec { #include #ifdef NEED_ERRNO -#include "need_errno.h" +# include "need_errno.h" #else -#include +# include #endif +#include + /* * In case ETIMEDOUT hasn't been defined above somehow. */ @@ -157,6 +165,15 @@ struct timespec { #define ETIMEDOUT 10060 /* This is the value in winsock.h. */ #endif +/* + * Several systems don't define ENOTSUP. If not, we use + * the same value as Solaris. + */ +#ifndef ENOTSUP +# define ENOTSUP 48 +#endif + + #ifdef __cplusplus extern "C" { @@ -185,7 +202,7 @@ extern "C" * pthread_attr_getstackaddr * pthread_attr_setstackaddr * - * _POSIX_THREAD_PRIORITY_SCHEDULING (not set) + * _POSIX_THREAD_PRIORITY_SCHEDULING (set) * If set, you can use realtime scheduling. * Indicates the availability of: * pthread_attr_getinheritsched @@ -198,8 +215,9 @@ extern "C" * pthread_attr_setscope * pthread_getschedparam * pthread_setschedparam - * pthread_get_priority_max - * pthread_get_priority_min + * sched_get_priority_max + * sched_get_priority_min + * sched_rr_set_interval * * _POSIX_THREAD_PRIO_INHERIT (not set) * If set, you can create priority inheritance @@ -263,16 +281,16 @@ extern "C" #ifndef _POSIX_THREADS #define _POSIX_THREADS #endif -#define _POSIX_THREAD_SAFE_FUNCTIONS +#define _POSIX_THREAD_SAFE_FUNCTIONS #define _POSIX_THREAD_ATTR_STACKSIZE +#define _POSIX_THREAD_PRIORITY_SCHEDULING #if defined( KLUDGE ) /* * The following are not supported */ #define _POSIX_THREAD_ATTR_STACKADDR -#define _POSIX_THREAD_PRIORITY_SCHEDULING #define _POSIX_THREAD_PRIO_INHERIT #define _POSIX_THREAD_PRIO_PROTECT #define _POSIX_THREAD_PROCESS_SHARED @@ -335,36 +353,44 @@ typedef struct pthread_rwlockattr_t_ *pthread_rwlockattr_t; * ==================== */ +enum { /* * pthread_attr_{get,set}detachstate */ -#define PTHREAD_CREATE_JOINABLE 0 -#define PTHREAD_CREATE_DETACHED 1 + PTHREAD_CREATE_JOINABLE = 0, /* Default */ + PTHREAD_CREATE_DETACHED = 1, + +/* + * pthread_attr_{get,set}inheritsched + */ + PTHREAD_INHERIT_SCHED = 0, + PTHREAD_EXPLICIT_SCHED = 1, /* Default */ /* - * pthread_attr{get,set}inheritsched + * pthread_{get,set}scope */ -#define PTHREAD_INHERIT_SCHED 0 -#define PTHREAD_EXPLICIT_SCHED 1 + PTHREAD_SCOPE_PROCESS = 0, + PTHREAD_SCOPE_SYSTEM = 1, /* Default */ /* * pthread_setcancelstate paramters */ -#define PTHREAD_CANCEL_ENABLE 0 -#define PTHREAD_CANCEL_DISABLE 1 + PTHREAD_CANCEL_ENABLE = 0, /* Default */ + PTHREAD_CANCEL_DISABLE = 1, /* * pthread_setcanceltype parameters */ -#define PTHREAD_CANCEL_ASYNCHRONOUS 0 -#define PTHREAD_CANCEL_DEFERRED 1 + PTHREAD_CANCEL_ASYNCHRONOUS = 0, + PTHREAD_CANCEL_DEFERRED = 1, /* Default */ /* * pthread_mutexattr_{get,set}pshared * pthread_condattr_{get,set}pshared */ -#define PTHREAD_PROCESS_PRIVATE 0 -#define PTHREAD_PROCESS_SHARED 1 + PTHREAD_PROCESS_PRIVATE = 0, + PTHREAD_PROCESS_SHARED = 1 +}; /* * ==================== @@ -411,28 +437,6 @@ enum }; -/* - * ==================== - * ==================== - * Scheduling - * ==================== - * ==================== - */ - -/* Thread scheduling policies */ - -#define SCHED_OTHER 0 -#define SCHED_FIFO 1 -#define SCHED_RR 2 - -#define SCHED_MIN SCHED_OTHER -#define SCHED_MAX SCHED_RR - -struct sched_param { - int sched_priority; -}; - - /* There are three implementations of cancel cleanup. * Note that pthread.h is included in both application * compilation units and also internally for the library. @@ -657,6 +661,18 @@ int pthread_attr_getschedparam (const pthread_attr_t *attr, int pthread_attr_setschedparam (pthread_attr_t *attr, const struct sched_param *param); +int pthread_attr_setschedpolicy (pthread_attr_t *, + int); + +int pthread_attr_getschedpolicy (pthread_attr_t *, + int *); + +int pthread_attr_setinheritsched(pthread_attr_t * attr, + int inheritsched); + +int pthread_attr_getinheritsched(pthread_attr_t * attr, + int * inheritsched); + int pthread_attr_setscope (pthread_attr_t *, int); -- cgit v1.2.3