source: rtems/cpukit/posix/src/nanosleep.c @ 9b4422a2

4.115
Last change on this file since 9b4422a2 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was 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
10#if HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <time.h>
15#include <errno.h>
16
17#include <rtems/system.h>
18#include <rtems/score/isr.h>
19#include <rtems/score/scheduler.h>
20#include <rtems/score/thread.h>
21#include <rtems/score/tod.h>
22
23#include <rtems/seterr.h>
24#include <rtems/score/timespec.h>
25
26/*
27 *  14.2.5 High Resolution Sleep, P1003.1b-1993, p. 269
28 */
29
30int nanosleep(
31  const struct timespec  *rqtp,
32  struct timespec        *rmtp
33)
34{
35  Watchdog_Interval  ticks;
36
37
38  /*
39   *  Return EINVAL if the delay interval is negative.
40   *
41   *  NOTE:  This behavior is beyond the POSIX specification.
42   *         FSU and GNU/Linux pthreads shares this behavior.
43   */
44  if ( !_Timespec_Is_valid( rqtp ) )
45    rtems_set_errno_and_return_minus_one( EINVAL );
46
47  ticks = _Timespec_To_ticks( rqtp );
48
49  /*
50   *  A nanosleep for zero time is implemented as a yield.
51   *  This behavior is also beyond the POSIX specification but is
52   *  consistent with the RTEMS API and yields desirable behavior.
53   */
54
55  if ( !ticks ) {
56    _Thread_Disable_dispatch();
57      _Scheduler_Yield();
58    _Thread_Enable_dispatch();
59    if ( rmtp ) {
60       rmtp->tv_sec = 0;
61       rmtp->tv_nsec = 0;
62    }
63    return 0;
64  }
65
66  /*
67   *  Block for the desired amount of time
68   */
69  _Thread_Disable_dispatch();
70    _Thread_Set_state(
71      _Thread_Executing,
72      STATES_DELAYING | STATES_INTERRUPTIBLE_BY_SIGNAL
73    );
74    _Watchdog_Initialize(
75      &_Thread_Executing->Timer,
76      _Thread_Delay_ended,
77      _Thread_Executing->Object.id,
78      NULL
79    );
80    _Watchdog_Insert_ticks( &_Thread_Executing->Timer, ticks );
81  _Thread_Enable_dispatch();
82
83  /* calculate time remaining */
84
85  if ( rmtp ) {
86    ticks -=
87      _Thread_Executing->Timer.stop_time - _Thread_Executing->Timer.start_time;
88
89    _Timespec_From_ticks( ticks, rmtp );
90
91    /*
92     *  Only when POSIX is enabled, can a sleep be interrupted.
93     */
94    #if defined(RTEMS_POSIX_API)
95        /*
96         *  If there is time remaining, then we were interrupted by a signal.
97         */
98        if ( ticks )
99          rtems_set_errno_and_return_minus_one( EINTR );
100    #endif
101  }
102
103  return 0;
104}
Note: See TracBrowser for help on using the repository browser.