From 9f95a19a57f0f85212c320327636e93d70bbecc8 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 2 Nov 1999 18:35:52 +0000 Subject: Split time.c into multiple files. --- c/src/exec/posix/src/Makefile.in | 6 +- c/src/exec/posix/src/clockgetcpuclockid.c | 28 ++ c/src/exec/posix/src/clockgetenableattr.c | 28 ++ c/src/exec/posix/src/clockgetres.c | 48 ++++ c/src/exec/posix/src/clockgettime.c | 65 +++++ c/src/exec/posix/src/clocksetenableattr.c | 28 ++ c/src/exec/posix/src/clocksettime.c | 84 ++++++ c/src/exec/posix/src/mutexgetprioceiling.c | 33 ++- c/src/exec/posix/src/mutexsetprioceiling.c | 57 +++- c/src/exec/posix/src/nanosleep.c | 100 +++++++ c/src/exec/posix/src/posixintervaltotimespec.c | 34 +++ c/src/exec/posix/src/posixtimespecsubtract.c | 46 ++++ c/src/exec/posix/src/posixtimespectointerval.c | 38 +++ c/src/exec/posix/src/time.c | 349 ------------------------- 14 files changed, 578 insertions(+), 366 deletions(-) create mode 100644 c/src/exec/posix/src/clockgetcpuclockid.c create mode 100644 c/src/exec/posix/src/clockgetenableattr.c create mode 100644 c/src/exec/posix/src/clockgetres.c create mode 100644 c/src/exec/posix/src/clockgettime.c create mode 100644 c/src/exec/posix/src/clocksetenableattr.c create mode 100644 c/src/exec/posix/src/clocksettime.c create mode 100644 c/src/exec/posix/src/nanosleep.c create mode 100644 c/src/exec/posix/src/posixintervaltotimespec.c create mode 100644 c/src/exec/posix/src/posixtimespecsubtract.c create mode 100644 c/src/exec/posix/src/posixtimespectointerval.c (limited to 'c/src/exec/posix') diff --git a/c/src/exec/posix/src/Makefile.in b/c/src/exec/posix/src/Makefile.in index 55c1283afa..9a791dc7a7 100644 --- a/c/src/exec/posix/src/Makefile.in +++ b/c/src/exec/posix/src/Makefile.in @@ -62,11 +62,15 @@ SEMAPHORE_C_PIECES= semaphore semaphorecreatesupp semaphoredeletesupp \ semgetvalue seminit semopen sempost semtimedwait semtrywait \ semunlink semwait +TIME_C_PIECES= time posixtimespecsubtract posixtimespectointerval \ + posixintervaltotimespec clockgetcpuclockid clockgetenableattr \ + clockgetres clockgettime clocksetenableattr clocksettime nanosleep + C_PIECES = adasupp $(CONDITION_VARIABLE_C_PIECES) \ getpid key $(MESSAGE_QUEUE_C_PIECES) \ $(MUTEX_C_PIECES) $(PTHREAD_C_PIECES) \ $(PSIGNAL_C_PIECES) ptimer sched $(SEMAPHORE_C_PIECES) \ - time types unistd $(ENOSYS_C_PIECES) \ + $(TIME_C_PIECES) types unistd $(ENOSYS_C_PIECES) \ $(BUILD_FOR_NOW_C_PIECES) C_FILES = $(C_PIECES:%=%.c) diff --git a/c/src/exec/posix/src/clockgetcpuclockid.c b/c/src/exec/posix/src/clockgetcpuclockid.c new file mode 100644 index 0000000000..fc0a3535b0 --- /dev/null +++ b/c/src/exec/posix/src/clockgetcpuclockid.c @@ -0,0 +1,28 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * 20.1.3 Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 + */ + +int clock_getcpuclockid( + pid_t pid, + clockid_t *clock_id +) +{ + return POSIX_NOT_IMPLEMENTED(); +} diff --git a/c/src/exec/posix/src/clockgetenableattr.c b/c/src/exec/posix/src/clockgetenableattr.c new file mode 100644 index 0000000000..6a7d9c1c46 --- /dev/null +++ b/c/src/exec/posix/src/clockgetenableattr.c @@ -0,0 +1,28 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * 20.1.5 CPU-time Clock Attribute Access, P1003.4b/D8, p. 58 + */ + +int clock_getenable_attr( + clockid_t clock_id, + int *attr +) +{ + return POSIX_NOT_IMPLEMENTED(); +} diff --git a/c/src/exec/posix/src/clockgetres.c b/c/src/exec/posix/src/clockgetres.c new file mode 100644 index 0000000000..3be3439cdb --- /dev/null +++ b/c/src/exec/posix/src/clockgetres.c @@ -0,0 +1,48 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * 14.2.1 Clocks, P1003.1b-1993, p. 263 + */ + +int clock_getres( + clockid_t clock_id, + struct timespec *res +) +{ + if ( !res ) + set_errno_and_return_minus_one( EINVAL ); + + switch ( clock_id ) { + + /* + * All time in rtems is based on the same clock tick. + */ + + case CLOCK_REALTIME: + case CLOCK_PROCESS_CPUTIME: + case CLOCK_THREAD_CPUTIME: + if ( res ) + _POSIX_Interval_to_timespec( _TOD_Microseconds_per_tick, res ); + break; + + default: + set_errno_and_return_minus_one( EINVAL ); + + } + return 0; +} diff --git a/c/src/exec/posix/src/clockgettime.c b/c/src/exec/posix/src/clockgettime.c new file mode 100644 index 0000000000..806a29caa3 --- /dev/null +++ b/c/src/exec/posix/src/clockgettime.c @@ -0,0 +1,65 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * 14.2.1 Clocks, P1003.1b-1993, p. 263 + */ + +int clock_gettime( + clockid_t clock_id, + struct timespec *tp +) +{ + ISR_Level level; + time_t seconds; + long ticks; + + if ( !tp ) + set_errno_and_return_minus_one( EINVAL ); + + switch ( clock_id ) { + + case CLOCK_REALTIME: + + _ISR_Disable( level ); + seconds = _TOD_Seconds_since_epoch; + ticks = _TOD_Current.ticks; + _ISR_Enable( level ); + + tp->tv_sec = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988; + tp->tv_nsec = ticks * _TOD_Microseconds_per_tick * + TOD_NANOSECONDS_PER_MICROSECOND; + break; + +#ifdef _POSIX_CPUTIME + case CLOCK_PROCESS_CPUTIME: + /* don't base this on _Watchdog_Ticks_since_boot--duration is too short*/ + return POSIX_NOT_IMPLEMENTED(); + break; +#endif + +#ifdef _POSIX_THREAD_CPUTIME + case CLOCK_THREAD_CPUTIME: + return POSIX_NOT_IMPLEMENTED(); + break; +#endif + default: + set_errno_and_return_minus_one( EINVAL ); + + } + return 0; +} diff --git a/c/src/exec/posix/src/clocksetenableattr.c b/c/src/exec/posix/src/clocksetenableattr.c new file mode 100644 index 0000000000..2ee5a4ef25 --- /dev/null +++ b/c/src/exec/posix/src/clocksetenableattr.c @@ -0,0 +1,28 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * 20.1.5 CPU-time Clock Attribute Access, P1003.4b/D8, p. 58 + */ + +int clock_setenable_attr( + clockid_t clock_id, + int attr +) +{ + return POSIX_NOT_IMPLEMENTED(); +} diff --git a/c/src/exec/posix/src/clocksettime.c b/c/src/exec/posix/src/clocksettime.c new file mode 100644 index 0000000000..8157bdfda5 --- /dev/null +++ b/c/src/exec/posix/src/clocksettime.c @@ -0,0 +1,84 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * 14.2.1 Clocks, P1003.1b-1993, p. 263 + */ + +int clock_settime( + clockid_t clock_id, + const struct timespec *tp +) +{ + struct tm split_time; + TOD_Control tod; + Watchdog_Interval seconds; + + assert( tp ); + + switch ( clock_id ) { + + case CLOCK_REALTIME: + (void) gmtime_r( &tp->tv_sec, &split_time ); + + /* + * Convert the tm structure format to that used by the TOD Handler + * + * NOTE: TOD Handler does not honor leap seconds. + */ + + tod.year = split_time.tm_year + 1900; /* RHS is years since 1900 */ + tod.month = split_time.tm_mon + 1; /* RHS uses 0-11 */ + tod.day = split_time.tm_mday; + tod.hour = split_time.tm_hour; + tod.minute = split_time.tm_min; + tod.second = split_time.tm_sec; /* RHS allows 0-61 for leap seconds */ + + tod.ticks = (tp->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) / + _TOD_Microseconds_per_tick; + + if ( !_TOD_Validate( &tod ) ) + set_errno_and_return_minus_one( EINVAL ); + + /* + * We can't use the tp->tv_sec field because it is based on + * a different EPOCH. + */ + + seconds = _TOD_To_seconds( &tod ); + _Thread_Disable_dispatch(); + _TOD_Set( &tod, seconds ); + _Thread_Enable_dispatch(); + break; + +#ifdef _POSIX_CPUTIME + case CLOCK_PROCESS_CPUTIME: + return POSIX_NOT_IMPLEMENTED(); + break; +#endif + +#ifdef _POSIX_THREAD_CPUTIME + case CLOCK_THREAD_CPUTIME: + return POSIX_NOT_IMPLEMENTED(); + break; +#endif + default: + set_errno_and_return_minus_one( EINVAL ); + + } + return 0; +} diff --git a/c/src/exec/posix/src/mutexgetprioceiling.c b/c/src/exec/posix/src/mutexgetprioceiling.c index 63181e1764..81fdbeaa9d 100644 --- a/c/src/exec/posix/src/mutexgetprioceiling.c +++ b/c/src/exec/posix/src/mutexgetprioceiling.c @@ -18,17 +18,34 @@ /*PAGE * - * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 + * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 */ - -int pthread_mutexattr_getprioceiling( - const pthread_mutexattr_t *attr, - int *prioceiling + +int pthread_mutex_getprioceiling( + pthread_mutex_t *mutex, + int *prioceiling ) { - if ( !attr || !attr->is_initialized || !prioceiling ) + register POSIX_Mutex_Control *the_mutex; + Objects_Locations location; + + if ( !prioceiling ) return EINVAL; - *prioceiling = attr->prio_ceiling; - return 0; + the_mutex = _POSIX_Mutex_Get( mutex, &location ); + switch ( location ) { + case OBJECTS_REMOTE: +#if defined(RTEMS_MULTIPROCESSING) + return POSIX_MP_NOT_IMPLEMENTED(); /* XXX feels questionable */ +#endif + case OBJECTS_ERROR: + return EINVAL; + case OBJECTS_LOCAL: + *prioceiling = _POSIX_Priority_From_core( + the_mutex->Mutex.Attributes.priority_ceiling + ); + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); } diff --git a/c/src/exec/posix/src/mutexsetprioceiling.c b/c/src/exec/posix/src/mutexsetprioceiling.c index 559d50852f..ff9229f5ec 100644 --- a/c/src/exec/posix/src/mutexsetprioceiling.c +++ b/c/src/exec/posix/src/mutexsetprioceiling.c @@ -18,20 +18,61 @@ /*PAGE * - * 13.6.1 Mutex Initialization Scheduling Attributes, P1003.1c/Draft 10, p. 128 + * 13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131 */ - -int pthread_mutexattr_setprioceiling( - pthread_mutexattr_t *attr, - int prioceiling + +int pthread_mutex_setprioceiling( + pthread_mutex_t *mutex, + int prioceiling, + int *old_ceiling ) { - if ( !attr || !attr->is_initialized ) + register POSIX_Mutex_Control *the_mutex; + Objects_Locations location; + Priority_Control the_priority; + int status; + + if ( !old_ceiling ) return EINVAL; if ( !_POSIX_Priority_Is_valid( prioceiling ) ) return EINVAL; - attr->prio_ceiling = prioceiling; - return 0; + the_priority = _POSIX_Priority_To_core( prioceiling ); + + /* + * Must acquire the mutex before we can change it's ceiling + */ + + status = pthread_mutex_lock( mutex ); + if ( status ) + return status; + + the_mutex = _POSIX_Mutex_Get( mutex, &location ); + switch ( location ) { + case OBJECTS_REMOTE: +#if defined(RTEMS_MULTIPROCESSING) + /* XXX It feels questionable to set the ceiling on a remote mutex. */ + return EINVAL; +#endif + case OBJECTS_ERROR: + return EINVAL; /* impossible to get here */ + case OBJECTS_LOCAL: + *old_ceiling = _POSIX_Priority_From_core( + the_mutex->Mutex.Attributes.priority_ceiling + ); + the_mutex->Mutex.Attributes.priority_ceiling = the_priority; + _CORE_mutex_Surrender( + &the_mutex->Mutex, + the_mutex->Object.id, +#if defined(RTEMS_MULTIPROCESSING) + POSIX_Threads_mutex_MP_support +#else + NULL +#endif + ); + _Thread_Enable_dispatch(); + return 0; + } + return POSIX_BOTTOM_REACHED(); } diff --git a/c/src/exec/posix/src/nanosleep.c b/c/src/exec/posix/src/nanosleep.c new file mode 100644 index 0000000000..7930c016e5 --- /dev/null +++ b/c/src/exec/posix/src/nanosleep.c @@ -0,0 +1,100 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * 14.2.5 High Resolution Sleep, P1003.1b-1993, p. 269 + */ + +int nanosleep( + const struct timespec *rqtp, + struct timespec *rmtp +) +{ + Watchdog_Interval ticks; + struct timespec *the_rqtp; + + if ( !rqtp ) + set_errno_and_return_minus_one( EINVAL ); + + the_rqtp = (struct timespec *)rqtp; + + /* + * Return EAGAIN if the delay interval is negative. + * + * NOTE: This behavior is beyond the POSIX specification. + * FSU pthreads shares this behavior. + */ + + if ( the_rqtp->tv_sec < 0 ) + the_rqtp->tv_sec = 0; + + if ( /* the_rqtp->tv_sec < 0 || */ the_rqtp->tv_nsec < 0 ) + set_errno_and_return_minus_one( EAGAIN ); + + if ( the_rqtp->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) + set_errno_and_return_minus_one( EINVAL ); + + ticks = _POSIX_Timespec_to_interval( the_rqtp ); + + /* + * This behavior is also beyond the POSIX specification but is + * consistent with the RTEMS api and yields desirable behavior. + */ + + if ( !ticks ) { + _Thread_Disable_dispatch(); + _Thread_Yield_processor(); + _Thread_Enable_dispatch(); + if ( rmtp ) { + rmtp->tv_sec = 0; + rmtp->tv_nsec = 0; + } + return 0; + } + + _Thread_Disable_dispatch(); + _Thread_Set_state( + _Thread_Executing, + STATES_DELAYING | STATES_INTERRUPTIBLE_BY_SIGNAL + ); + _Watchdog_Initialize( + &_Thread_Executing->Timer, + _Thread_Delay_ended, + _Thread_Executing->Object.id, + NULL + ); + _Watchdog_Insert_ticks( &_Thread_Executing->Timer, ticks ); + _Thread_Enable_dispatch(); + + /* calculate time remaining */ + + if ( rmtp ) { + ticks -= + _Thread_Executing->Timer.stop_time - _Thread_Executing->Timer.start_time; + + _POSIX_Interval_to_timespec( ticks, rmtp ); + + /* + * If there is time remaining, then we were interrupted by a signal. + */ + + if ( ticks ) + set_errno_and_return_minus_one( EINTR ); + } + + return 0; +} diff --git a/c/src/exec/posix/src/posixintervaltotimespec.c b/c/src/exec/posix/src/posixintervaltotimespec.c new file mode 100644 index 0000000000..e5f883095b --- /dev/null +++ b/c/src/exec/posix/src/posixintervaltotimespec.c @@ -0,0 +1,34 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * _POSIX_Interval_to_timespec + */ + +void _POSIX_Interval_to_timespec( + Watchdog_Interval ticks, + struct timespec *time +) +{ + unsigned32 usecs; + + usecs = ticks * _TOD_Microseconds_per_tick; + + time->tv_sec = usecs / TOD_MICROSECONDS_PER_SECOND; + time->tv_nsec = (usecs % TOD_MICROSECONDS_PER_SECOND) * + TOD_NANOSECONDS_PER_MICROSECOND; +} diff --git a/c/src/exec/posix/src/posixtimespecsubtract.c b/c/src/exec/posix/src/posixtimespecsubtract.c new file mode 100644 index 0000000000..eb5e21d83a --- /dev/null +++ b/c/src/exec/posix/src/posixtimespecsubtract.c @@ -0,0 +1,46 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * _POSIX_Timespec_subtract + */ + +void _POSIX_Timespec_subtract( + const struct timespec *the_start, + const struct timespec *end, + struct timespec *result +) +{ + struct timespec start_struct = *the_start; + struct timespec *start = &start_struct; + unsigned int nsecs_per_sec = TOD_NANOSECONDS_PER_SECOND; + + if (end->tv_nsec < start->tv_nsec) { + int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec + 1; + start->tv_nsec -= nsecs_per_sec * seconds; + start->tv_sec += seconds; + } + + if (end->tv_nsec - start->tv_nsec > nsecs_per_sec) { + int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec; + start->tv_nsec += nsecs_per_sec * seconds; + start->tv_sec -= seconds; + } + + result->tv_sec = end->tv_sec - start->tv_sec; + result->tv_nsec = end->tv_nsec - start->tv_nsec; +} diff --git a/c/src/exec/posix/src/posixtimespectointerval.c b/c/src/exec/posix/src/posixtimespectointerval.c new file mode 100644 index 0000000000..388dd791eb --- /dev/null +++ b/c/src/exec/posix/src/posixtimespectointerval.c @@ -0,0 +1,38 @@ +/* + * $Id$ + */ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/*PAGE + * + * _POSIX_Timespec_to_interval + */ + +Watchdog_Interval _POSIX_Timespec_to_interval( + const struct timespec *time +) +{ + Watchdog_Interval ticks; + + ticks = (time->tv_sec * TOD_MICROSECONDS_PER_SECOND) / + _TOD_Microseconds_per_tick; + + ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) / + _TOD_Microseconds_per_tick; + + if (ticks) + return ticks; + + return 1; +} diff --git a/c/src/exec/posix/src/time.c b/c/src/exec/posix/src/time.c index b4367fac4c..1eb96d5264 100644 --- a/c/src/exec/posix/src/time.c +++ b/c/src/exec/posix/src/time.c @@ -14,79 +14,6 @@ #include #include -/*PAGE - * - * _POSIX_Timespec_subtract - */ - -void _POSIX_Timespec_subtract( - const struct timespec *the_start, - const struct timespec *end, - struct timespec *result -) -{ - struct timespec start_struct = *the_start; - struct timespec *start = &start_struct; - unsigned int nsecs_per_sec = TOD_NANOSECONDS_PER_SECOND; - - if (end->tv_nsec < start->tv_nsec) { - int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec + 1; - start->tv_nsec -= nsecs_per_sec * seconds; - start->tv_sec += seconds; - } - - if (end->tv_nsec - start->tv_nsec > nsecs_per_sec) { - int seconds = (start->tv_nsec - end->tv_nsec) / nsecs_per_sec; - start->tv_nsec += nsecs_per_sec * seconds; - start->tv_sec -= seconds; - } - - result->tv_sec = end->tv_sec - start->tv_sec; - result->tv_nsec = end->tv_nsec - start->tv_nsec; -} - -/*PAGE - * - * _POSIX_Timespec_to_interval - */ - -Watchdog_Interval _POSIX_Timespec_to_interval( - const struct timespec *time -) -{ - Watchdog_Interval ticks; - - ticks = (time->tv_sec * TOD_MICROSECONDS_PER_SECOND) / - _TOD_Microseconds_per_tick; - - ticks += (time->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) / - _TOD_Microseconds_per_tick; - - if (ticks) - return ticks; - - return 1; -} - -/*PAGE - * - * _POSIX_Interval_to_timespec - */ - -void _POSIX_Interval_to_timespec( - Watchdog_Interval ticks, - struct timespec *time -) -{ - unsigned32 usecs; - - usecs = ticks * _TOD_Microseconds_per_tick; - - time->tv_sec = usecs / TOD_MICROSECONDS_PER_SECOND; - time->tv_nsec = (usecs % TOD_MICROSECONDS_PER_SECOND) * - TOD_NANOSECONDS_PER_MICROSECOND; -} - /*PAGE * * 4.5.1 Get System Time, P1003.1b-1993, p. 91 @@ -119,279 +46,3 @@ time_t time( return seconds_since_epoch; } #endif - -/*PAGE - * - * 14.2.1 Clocks, P1003.1b-1993, p. 263 - */ - -int clock_settime( - clockid_t clock_id, - const struct timespec *tp -) -{ - struct tm split_time; - TOD_Control tod; - Watchdog_Interval seconds; - - assert( tp ); - - switch ( clock_id ) { - - case CLOCK_REALTIME: - (void) gmtime_r( &tp->tv_sec, &split_time ); - - /* - * Convert the tm structure format to that used by the TOD Handler - * - * NOTE: TOD Handler does not honor leap seconds. - */ - - tod.year = split_time.tm_year + 1900; /* RHS is years since 1900 */ - tod.month = split_time.tm_mon + 1; /* RHS uses 0-11 */ - tod.day = split_time.tm_mday; - tod.hour = split_time.tm_hour; - tod.minute = split_time.tm_min; - tod.second = split_time.tm_sec; /* RHS allows 0-61 for leap seconds */ - - tod.ticks = (tp->tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND) / - _TOD_Microseconds_per_tick; - - if ( !_TOD_Validate( &tod ) ) - set_errno_and_return_minus_one( EINVAL ); - - /* - * We can't use the tp->tv_sec field because it is based on - * a different EPOCH. - */ - - seconds = _TOD_To_seconds( &tod ); - _Thread_Disable_dispatch(); - _TOD_Set( &tod, seconds ); - _Thread_Enable_dispatch(); - break; - -#ifdef _POSIX_CPUTIME - case CLOCK_PROCESS_CPUTIME: - return POSIX_NOT_IMPLEMENTED(); - break; -#endif - -#ifdef _POSIX_THREAD_CPUTIME - case CLOCK_THREAD_CPUTIME: - return POSIX_NOT_IMPLEMENTED(); - break; -#endif - default: - set_errno_and_return_minus_one( EINVAL ); - - } - return 0; -} - -/*PAGE - * - * 14.2.1 Clocks, P1003.1b-1993, p. 263 - */ - -int clock_gettime( - clockid_t clock_id, - struct timespec *tp -) -{ - ISR_Level level; - time_t seconds; - long ticks; - - if ( !tp ) - set_errno_and_return_minus_one( EINVAL ); - - switch ( clock_id ) { - - case CLOCK_REALTIME: - - _ISR_Disable( level ); - seconds = _TOD_Seconds_since_epoch; - ticks = _TOD_Current.ticks; - _ISR_Enable( level ); - - tp->tv_sec = seconds + POSIX_TIME_SECONDS_1970_THROUGH_1988; - tp->tv_nsec = ticks * _TOD_Microseconds_per_tick * - TOD_NANOSECONDS_PER_MICROSECOND; - break; - -#ifdef _POSIX_CPUTIME - case CLOCK_PROCESS_CPUTIME: - /* don't base this on _Watchdog_Ticks_since_boot--duration is too short*/ - return POSIX_NOT_IMPLEMENTED(); - break; -#endif - -#ifdef _POSIX_THREAD_CPUTIME - case CLOCK_THREAD_CPUTIME: - return POSIX_NOT_IMPLEMENTED(); - break; -#endif - default: - set_errno_and_return_minus_one( EINVAL ); - - } - return 0; -} - -/*PAGE - * - * 14.2.1 Clocks, P1003.1b-1993, p. 263 - */ - -int clock_getres( - clockid_t clock_id, - struct timespec *res -) -{ - if ( !res ) - set_errno_and_return_minus_one( EINVAL ); - - switch ( clock_id ) { - - /* - * All time in rtems is based on the same clock tick. - */ - - case CLOCK_REALTIME: - case CLOCK_PROCESS_CPUTIME: - case CLOCK_THREAD_CPUTIME: - if ( res ) - _POSIX_Interval_to_timespec( _TOD_Microseconds_per_tick, res ); - break; - - default: - set_errno_and_return_minus_one( EINVAL ); - - } - return 0; -} - -/*PAGE - * - * 14.2.5 High Resolution Sleep, P1003.1b-1993, p. 269 - */ - -int nanosleep( - const struct timespec *rqtp, - struct timespec *rmtp -) -{ - Watchdog_Interval ticks; - struct timespec *the_rqtp; - - if ( !rqtp ) - set_errno_and_return_minus_one( EINVAL ); - - the_rqtp = (struct timespec *)rqtp; - - /* - * Return EAGAIN if the delay interval is negative. - * - * NOTE: This behavior is beyond the POSIX specification. - * FSU pthreads shares this behavior. - */ - - if ( the_rqtp->tv_sec < 0 ) - the_rqtp->tv_sec = 0; - - if ( /* the_rqtp->tv_sec < 0 || */ the_rqtp->tv_nsec < 0 ) - set_errno_and_return_minus_one( EAGAIN ); - - if ( the_rqtp->tv_nsec >= TOD_NANOSECONDS_PER_SECOND ) - set_errno_and_return_minus_one( EINVAL ); - - ticks = _POSIX_Timespec_to_interval( the_rqtp ); - - /* - * This behavior is also beyond the POSIX specification but is - * consistent with the RTEMS api and yields desirable behavior. - */ - - if ( !ticks ) { - _Thread_Disable_dispatch(); - _Thread_Yield_processor(); - _Thread_Enable_dispatch(); - if ( rmtp ) { - rmtp->tv_sec = 0; - rmtp->tv_nsec = 0; - } - return 0; - } - - _Thread_Disable_dispatch(); - _Thread_Set_state( - _Thread_Executing, - STATES_DELAYING | STATES_INTERRUPTIBLE_BY_SIGNAL - ); - _Watchdog_Initialize( - &_Thread_Executing->Timer, - _Thread_Delay_ended, - _Thread_Executing->Object.id, - NULL - ); - _Watchdog_Insert_ticks( &_Thread_Executing->Timer, ticks ); - _Thread_Enable_dispatch(); - - /* calculate time remaining */ - - if ( rmtp ) { - ticks -= - _Thread_Executing->Timer.stop_time - _Thread_Executing->Timer.start_time; - - _POSIX_Interval_to_timespec( ticks, rmtp ); - - /* - * If there is time remaining, then we were interrupted by a signal. - */ - - if ( ticks ) - set_errno_and_return_minus_one( EINTR ); - } - - return 0; -} - -/*PAGE - * - * 20.1.3 Accessing a Process CPU-time CLock, P1003.4b/D8, p. 55 - */ - -int clock_getcpuclockid( - pid_t pid, - clockid_t *clock_id -) -{ - return POSIX_NOT_IMPLEMENTED(); -} - -/*PAGE - * - * 20.1.5 CPU-time Clock Attribute Access, P1003.4b/D8, p. 58 - */ - -int clock_setenable_attr( - clockid_t clock_id, - int attr -) -{ - return POSIX_NOT_IMPLEMENTED(); -} - -/*PAGE - * - * 20.1.5 CPU-time Clock Attribute Access, P1003.4b/D8, p. 58 - */ - -int clock_getenable_attr( - clockid_t clock_id, - int *attr -) -{ - return POSIX_NOT_IMPLEMENTED(); -} -- cgit v1.2.3