source: rtems/cpukit/posix/src/sigtimedwait.c @ 860c34e

4.104.114.95
Last change on this file since 860c34e 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: 3.3 KB
Line 
1/*
2 *  3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
3 *
4 *  COPYRIGHT (c) 1989-2007.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <pthread.h>
19#include <signal.h>
20#include <errno.h>
21
22#include <rtems/system.h>
23#include <rtems/posix/pthread.h>
24#include <rtems/posix/psignal.h>
25#include <rtems/seterr.h>
26#include <rtems/posix/time.h>
27#include <rtems/score/isr.h>
28
29int _POSIX_signals_Get_highest(
30  sigset_t   set
31)
32{
33  int signo;
34
35  for ( signo = SIGRTMIN ; signo <= SIGRTMAX ; signo++ ) {
36    if ( set & signo_to_mask( signo ) )
37      return signo;
38  }
39
40/* XXX - add __SIGFIRSTNOTRT or something like that to newlib signal .h */
41
42  for ( signo = SIGHUP ; signo <= __SIGLASTNOTRT ; signo++ ) {
43    if ( set & signo_to_mask( signo ) )
44      return signo;
45  }
46
47  return 0;
48}
49
50int sigtimedwait(
51  const sigset_t         *set,
52  siginfo_t              *info,
53  const struct timespec  *timeout
54)
55{
56  Thread_Control    *the_thread;
57  POSIX_API_Control *api;
58  Watchdog_Interval  interval;
59  siginfo_t          signal_information;
60  siginfo_t         *the_info;
61  int                signo;
62  ISR_Level          level;
63
64  /*
65   *  Error check parameters before disabling interrupts.
66   */
67
68  interval = 0;
69  if ( timeout ) {
70
71    if ( !_Timespec_Is_valid( timeout ) ) {
72      rtems_set_errno_and_return_minus_one( EINVAL );
73    }
74
75    interval = _Timespec_To_ticks( timeout );
76  }
77
78  /*
79   *  Initialize local variables.
80   */
81
82  the_info = ( info ) ? info : &signal_information;
83
84  the_thread = _Thread_Executing;
85
86  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
87
88  /*
89   *  What if they are already pending?
90   */
91
92  /* API signals pending? */
93
94  _ISR_Disable( level );
95  if ( *set & api->signals_pending ) {
96    /* XXX real info later */
97    the_info->si_signo = _POSIX_signals_Get_highest( api->signals_pending );
98    _POSIX_signals_Clear_signals(
99      api,
100      the_info->si_signo,
101      the_info,
102      FALSE,
103      FALSE
104    );
105    _ISR_Enable( level );
106
107    the_info->si_code = SI_USER;
108    the_info->si_value.sival_int = 0;
109    return the_info->si_signo;
110  }
111
112  /* Process pending signals? */
113
114  if ( *set & _POSIX_signals_Pending ) {
115    signo = _POSIX_signals_Get_highest( _POSIX_signals_Pending );
116    _POSIX_signals_Clear_signals( api, signo, the_info, TRUE, FALSE );
117    _ISR_Enable( level );
118
119    the_info->si_signo = signo;
120    the_info->si_code = SI_USER;
121    the_info->si_value.sival_int = 0;
122    return signo;
123  }
124
125  the_info->si_signo = -1;
126
127  _Thread_Disable_dispatch();
128    the_thread->Wait.queue           = &_POSIX_signals_Wait_queue;
129    the_thread->Wait.return_code     = EINTR;
130    the_thread->Wait.option          = *set;
131    the_thread->Wait.return_argument = the_info;
132    _Thread_queue_Enter_critical_section( &_POSIX_signals_Wait_queue );
133    _ISR_Enable( level );
134    _Thread_queue_Enqueue( &_POSIX_signals_Wait_queue, interval );
135  _Thread_Enable_dispatch();
136
137  /*
138   * When the thread is set free by a signal, it is need to eliminate
139   * the signal.
140   */
141
142  _POSIX_signals_Clear_signals( api, the_info->si_signo, the_info, FALSE, FALSE );
143  errno = _Thread_Executing->Wait.return_code;
144  return the_info->si_signo;
145}
Note: See TracBrowser for help on using the repository browser.