source: rtems/cpukit/posix/src/nanosleep.c @ 412dbff6

4.104.114.84.95
Last change on this file since 412dbff6 was 412dbff6, checked in by Joel Sherrill <joel.sherrill@…>, on 04/05/07 at 21:17:27

2007-04-05 Joel Sherrill <joel@…>

  • posix/Makefile.am, posix/include/rtems/posix/time.h, posix/src/adjtime.c, posix/src/alarm.c, posix/src/clockgetres.c, posix/src/condtimedwait.c, posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c, posix/src/nanosleep.c, posix/src/posixtimespecabsolutetimeout.c, posix/src/pthread.c, posix/src/pthreadcreate.c, posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c, posix/src/sched.c, posix/src/semtimedwait.c, posix/src/sigtimedwait.c, posix/src/ualarm.c, rtems/src/clocktodtoseconds.c, score/Makefile.am, score/preinstall.am, score/include/rtems/score/tod.h, score/inline/rtems/score/tod.inl, score/src/coretod.c, score/src/coretodget.c, score/src/coretodgetuptime.c, score/src/coretodset.c, score/src/coretodtickle.c: Provide timespec manipulation routines in the SuperCore?. Use them everywhere possible. This lead to significant cleanup in the API routines and eliminated some of the same code from the POSIX API. At this point, the SuperCore? keeps time in POSIX timespec format properly from 1970. You just cannot set it before 1988 in keeping with RTEMS traditional behavior.
  • score/include/rtems/score/timespec.h, score/src/timespecaddto.c, score/src/timespecfromticks.c, score/src/timespecisvalid.c, score/src/timespeclessthan.c, score/src/timespecsubtract.c, score/src/timespectoticks.c: New files.
  • posix/src/posixintervaltotimespec.c, posix/src/posixtimespecsubtract.c, posix/src/posixtimespectointerval.c: Removed.
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2007.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <time.h>
17#include <errno.h>
18
19#include <rtems/system.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/thread.h>
22#include <rtems/score/tod.h>
23
24#include <rtems/seterr.h>
25#include <rtems/posix/time.h>
26
27/*PAGE
28 *
29 *  14.2.5 High Resolution Sleep, P1003.1b-1993, p. 269
30 */
31
32int nanosleep(
33  const struct timespec  *rqtp,
34  struct timespec        *rmtp
35)
36{
37  Watchdog_Interval  ticks;
38
39  if ( !_Timespec_Is_valid( rqtp ) )
40    rtems_set_errno_and_return_minus_one( EINVAL );
41
42  /*
43   *  Return EINVAL if the delay interval is negative.
44   *
45   *  NOTE:  This behavior is beyond the POSIX specification.
46   *         FSU and GNU/Linux pthreads shares this behavior.
47   */
48  if ( rqtp->tv_sec < 0 || rqtp->tv_nsec < 0 )
49    rtems_set_errno_and_return_minus_one( EINVAL );
50
51  ticks = _Timespec_To_ticks( rqtp );
52
53  /*
54   *  A nanosleep for zero time is implemented as a yield.
55   *  This behavior is also beyond the POSIX specification but is
56   *  consistent with the RTEMS API and yields desirable behavior.
57   */
58
59  if ( !ticks ) {
60    _Thread_Disable_dispatch();
61      _Thread_Yield_processor();
62    _Thread_Enable_dispatch();
63    if ( rmtp ) {
64       rmtp->tv_sec = 0;
65       rmtp->tv_nsec = 0;
66    }
67    return 0;
68  }
69
70  /*
71   *  Block for the desired amount of time
72   */
73  _Thread_Disable_dispatch();
74    _Thread_Set_state(
75      _Thread_Executing,
76      STATES_DELAYING | STATES_INTERRUPTIBLE_BY_SIGNAL
77    );
78    _Watchdog_Initialize(
79      &_Thread_Executing->Timer,
80      _Thread_Delay_ended,
81      _Thread_Executing->Object.id,
82      NULL
83    );
84    _Watchdog_Insert_ticks( &_Thread_Executing->Timer, ticks );
85  _Thread_Enable_dispatch();
86
87  /* calculate time remaining */
88
89  if ( rmtp ) {
90    ticks -=
91      _Thread_Executing->Timer.stop_time - _Thread_Executing->Timer.start_time;
92
93    _Timespec_From_ticks( ticks, rmtp );
94
95    /*
96     *  If there is time remaining, then we were interrupted by a signal.
97     */
98
99    if ( ticks )
100      rtems_set_errno_and_return_minus_one( EINTR );
101  }
102
103  return 0;
104}
Note: See TracBrowser for help on using the repository browser.