diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 21d31f7b7..34aa64995 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,10 @@ +2009-06-17 Michael Eager + + * libc/include/pthread.h: Support XMK (Xilinx) BSP, add RTEMS to + PTHREAD_MUTEX_NORMAL. + * libc/include/sys/features.h: Same. + * libc/include/sys/types.h: Same. + 2009-06-16 Corinna Vinschen * libc/include/locale.h (struct lconv): Add missing members required diff --git a/newlib/libc/include/pthread.h b/newlib/libc/include/pthread.h index de61bf535..8dc787244 100644 --- a/newlib/libc/include/pthread.h +++ b/newlib/libc/include/pthread.h @@ -44,7 +44,7 @@ extern "C" { NOTE: RTEMS does not provide pthread_atfork(). */ -#if !defined(__rtems__) +#if !defined(__rtems__) && !defined(__XMK__) #warning "Add pthread_atfork() prototype" #endif diff --git a/newlib/libc/include/sys/features.h b/newlib/libc/include/sys/features.h index 866044f60..1fa542789 100644 --- a/newlib/libc/include/sys/features.h +++ b/newlib/libc/include/sys/features.h @@ -75,6 +75,13 @@ extern "C" { #endif +/* XMK loosely adheres to POSIX -- 1003.1 */ +#ifdef __XMK__ +#define _POSIX_THREADS 1 +#define _POSIX_THREAD_PRIORITY_SCHEDULING 1 +#endif + + #ifdef __svr4__ # define _POSIX_JOB_CONTROL 1 # define _POSIX_SAVED_IDS 1 diff --git a/newlib/libc/include/sys/types.h b/newlib/libc/include/sys/types.h index 3f1893c20..290c77a2b 100644 --- a/newlib/libc/include/sys/types.h +++ b/newlib/libc/include/sys/types.h @@ -165,7 +165,12 @@ typedef __uid_t uid_t; typedef __gid_t gid_t; #endif +#if defined(__XMK__) +typedef signed char pid_t; +#else typedef int pid_t; +#endif + #ifndef __CYGWIN__ typedef long key_t; #endif @@ -271,7 +276,11 @@ typedef long suseconds_t; * 2.5 Primitive System Data Types, P1003.1c/D10, p. 19. */ +#if defined(__XMK__) +typedef unsigned int pthread_t; /* identify a thread */ +#else typedef __uint32_t pthread_t; /* identify a thread */ +#endif /* P1003.1c/D10, p. 118-119 */ #define PTHREAD_SCOPE_PROCESS 0 @@ -287,6 +296,51 @@ typedef __uint32_t pthread_t; /* identify a thread */ #define PTHREAD_CREATE_DETACHED 0 #define PTHREAD_CREATE_JOINABLE 1 +#if defined(__XMK__) || defined(__rtems__) +/* The following defines are part of the X/Open System Interface (XSI). */ + +/* This type of mutex does not detect deadlock. A thread attempting to relock this mutex without first unlocking + * it shall deadlock. Attempting to unlock a mutex locked by a different thread results in undefined behavior. + * Attempting to unlock an unlocked mutex results in undefined behavior. + */ +#define PTHREAD_MUTEX_NORMAL 1 + +/* + * This type of mutex provides error checking. A thread attempting to relock this mutex without first unlocking + * it shall return with an error. A thread attempting to unlock a mutex which another thread has locked shall return + * with an error. A thread attempting to unlock an unlocked mutex shall return with an error. + */ +#define PTHREAD_MUTEX_ERRORCHECK 2 + +/* A thread attempting to relock this mutex without first unlocking it shall succeed in locking the mutex. + * The relocking deadlock which can occur with mutexes of type PTHREAD_MUTEX_NORMAL cannot occur with this type of mutex. + * Multiple locks of this mutex shall require the same number of unlocks to release the mutex before another thread can + * acquire the mutex. A thread attempting to unlock a mutex which another thread has locked shall return with an error. + * A thread attempting to unlock an unlocked mutex shall return with an error. + */ +#define PTHREAD_MUTEX_RECURSIVE 3 + +/* Attempting to recursively lock a mutex of this type results in undefined behavior. Attempting to unlock a + * mutex of this type which was not locked by the calling thread results in undefined behavior. Attempting to + * unlock a mutex of this type which is not locked results in undefined behavior. An implementation may map this + * mutex to one of the other mutex types. + */ +#define PTHREAD_MUTEX_DEFAULT 4 + +#endif /* defined(__XMK__) || defined(__rtems__) */ + +#if defined(__XMK__) +typedef struct pthread_attr_s { + int contentionscope; + struct sched_param schedparam; + int detachstate; + void *stackaddr; + size_t stacksize; +} pthread_attr_t; + +#define PTHREAD_STACK_MIN 200 + +#else /* !defined(__XMK__) */ typedef struct { int is_initialized; void *stackaddr; @@ -295,6 +349,7 @@ typedef struct { int inheritsched; int schedpolicy; struct sched_param schedparam; +#endif /* !defined(__XMK__) */ /* P1003.4b/D8, p. 54 adds cputime_clock_allowed attribute. */ #if defined(_POSIX_THREAD_CPUTIME) @@ -334,6 +389,13 @@ typedef struct { #endif +#if defined(__XMK__) +typedef unsigned int pthread_mutex_t; /* identify a mutex */ + +typedef struct { + int type; +} pthread_mutexattr_t; +#else /* !defined(__XMK__) */ typedef __uint32_t pthread_mutex_t; /* identify a mutex */ typedef struct { @@ -350,6 +412,7 @@ typedef struct { #endif int recursive; } pthread_mutexattr_t; +#endif /* !defined(__XMK__) */ /* Condition Variables */