From e72d995a80461203e99c812afc7e0b660ed341d7 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Fri, 31 May 1996 19:01:26 +0000 Subject: moved sleep() from psignal.c to unistd.c implemented sigemptyset() sigfillset(), sigaddset(), sigdelset(), and sigismember(). added checks for valid attribute values to some of the pthread_attr_t sets. --- c/src/exec/posix/src/psignal.c | 74 +++++++++++++++++++++++++++++------------- c/src/exec/posix/src/pthread.c | 32 ++++++++++++++++++ c/src/exec/posix/src/time.c | 14 ++++++-- c/src/exec/posix/src/unistd.c | 21 ++++++++++++ 4 files changed, 115 insertions(+), 26 deletions(-) (limited to 'c/src') diff --git a/c/src/exec/posix/src/psignal.c b/c/src/exec/posix/src/psignal.c index 5224601e32..5a4222b075 100644 --- a/c/src/exec/posix/src/psignal.c +++ b/c/src/exec/posix/src/psignal.c @@ -2,11 +2,24 @@ * $Id$ */ +#include +#include #include #include #include +/* + * Currently only 20 signals numbered 1-20 are defined + */ + +#define SIGNAL_ALL_MASK 0x000fffff + +#define signo_to_mask( _sig ) (1 << ((_sig) - 1)) + +#define is_valid_signo( _sig ) \ + ((signo_to_mask(_sig) & SIGNAL_ALL_MASK) != 0 ) + /* * 3.3.2 Send a Signal to a Process, P1003.1b-1993, p. 68 * @@ -33,7 +46,10 @@ int sigemptyset( sigset_t *set ) { - return POSIX_NOT_IMPLEMENTED(); + assert( set ); /* no word from posix, solaris returns EFAULT */ + + *set = 0; + return 0; } /* @@ -44,7 +60,10 @@ int sigfillset( sigset_t *set ) { - return POSIX_NOT_IMPLEMENTED(); + assert( set ); + + *set = SIGNAL_ALL_MASK; + return 0; } /* @@ -56,7 +75,15 @@ int sigaddset( int signo ) { - return POSIX_NOT_IMPLEMENTED(); + assert( set ); + + if ( !is_valid_signo(signo) ) { + errno = EINVAL; + return -1; + } + + *set |= signo_to_mask(signo); + return 0; } /* @@ -68,7 +95,15 @@ int sigdelset( int signo ) { - return POSIX_NOT_IMPLEMENTED(); + assert( set ); + + if ( !is_valid_signo(signo) ) { + errno = EINVAL; + return -1; + } + + *set &= ~signo_to_mask(signo); + return 0; } /* @@ -80,7 +115,17 @@ int sigismember( int signo ) { - return POSIX_NOT_IMPLEMENTED(); + assert( set ); + + if ( !is_valid_signo(signo) ) { + errno = EINVAL; + return -1; + } + + if ( *set & signo_to_mask(signo) ) + return 1; + + return 0; } /* @@ -228,27 +273,10 @@ unsigned int alarm( } /* - * 3.4.2 Suspend Process Execution, P1003.1b-1993, p. 80 + * 3.4.2 Suspend Process Execution, P1003.1b-1993, p. 81 */ int pause( void ) { return POSIX_NOT_IMPLEMENTED(); } - -/* - * 3.4.3 Delay Process Execution, P1003.1b-1993, p. 73 - */ - -unsigned int sleep( - unsigned int seconds -) -{ - /* XXX can we get away with this implementation? */ - struct timespec tp; - - tp.tv_sec = seconds; - tp.tv_nsec = 0; - - return nanosleep( &tp, NULL ); -} diff --git a/c/src/exec/posix/src/pthread.c b/c/src/exec/posix/src/pthread.c index 4b8a4977d8..9fa1428282 100644 --- a/c/src/exec/posix/src/pthread.c +++ b/c/src/exec/posix/src/pthread.c @@ -222,6 +222,14 @@ int pthread_attr_setscope( if ( !attr || !attr->is_initialized ) return EINVAL; + switch ( contentionscope ) { + case PTHREAD_SCOPE_PROCESS: + case PTHREAD_SCOPE_SYSTEM: + break; + default: + return EINVAL; + } + attr->contentionscope = contentionscope; return 0; } @@ -256,6 +264,14 @@ int pthread_attr_setinheritsched( if ( !attr || !attr->is_initialized ) return EINVAL; + switch ( inheritsched ) { + case PTHREAD_INHERIT_SCHED: + case PTHREAD_EXPLICIT_SCHED: + break; + default: + return EINVAL; + } + attr->inheritsched = inheritsched; return 0; } @@ -568,6 +584,22 @@ int pthread_create( int detachstate; #endif + /* + * P1003.1c/D10, p. 121. + * + * If inheritsched is set to PTHREAD_INHERIT_SCHED, then this thread + * inherits scheduling attributes from the creating thread. If it is + * PTHREAD_EXPLICIT_SCHED, then scheduling parameters come from the + * attributes structure. + */ + + switch ( attrp->inheritsched ) { + case PTHREAD_INHERIT_SCHED: + break; + case PTHREAD_EXPLICIT_SCHED: + break; + } + /* * Validate the RTEMS API priority and convert it to the core priority range. */ diff --git a/c/src/exec/posix/src/time.c b/c/src/exec/posix/src/time.c index 7397635786..f9e5ce835f 100644 --- a/c/src/exec/posix/src/time.c +++ b/c/src/exec/posix/src/time.c @@ -298,12 +298,15 @@ int nanosleep( { Watchdog_Interval ticks; + if ( rqtp->tv_nsec < 0 || rqtp->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) { + errno = EINVAL; + return -1; + } + /* XXX this is interruptible by a posix signal */ /* XXX rmtp is the time remaining on the timer -- we do not support this */ -/* XXX rmtp may be NULL */ - ticks = _POSIX_Time_Spec_to_interval( rqtp ); _Thread_Disable_dispatch(); @@ -316,7 +319,12 @@ int nanosleep( ); _Watchdog_Insert_ticks( &_Thread_Executing->Timer, ticks ); _Thread_Enable_dispatch(); - return 0; /* XXX should account for signal/remaining */ + + if ( rmtp ) { + /* XXX calculate time remaining */ + } + + return 0; /* XXX should account for signal */ } diff --git a/c/src/exec/posix/src/unistd.c b/c/src/exec/posix/src/unistd.c index f5d13b3adf..44d08e592b 100644 --- a/c/src/exec/posix/src/unistd.c +++ b/c/src/exec/posix/src/unistd.c @@ -2,10 +2,31 @@ * $Id$ */ +#include #include #include + +/* + * 3.4.3 Delay Process Execution, P1003.1b-1993, p. 73 + */ + +unsigned int sleep( + unsigned int seconds +) +{ + /* XXX can we get away with this implementation? */ + struct timespec tp; + struct timespec tm; + + tp.tv_sec = seconds; + tp.tv_nsec = 0; + + nanosleep( &tp, &tm ); + + return tm->tv_sec; /* seconds remaining */ +} /* * 4.8.1 Get Configurable System Variables, P1003.1b-1993, p. 95 */ -- cgit v1.2.3