source: rtems/cpukit/posix/src/sigtimedwait.c @ 92f4671

4.104.115
Last change on this file since 92f4671 was f8437c8, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/04/08 at 15:23:12

Convert to "bool".

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 *  3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
3 *
4 *  COPYRIGHT (c) 1989-2008.
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   *  NOTE: This is very specifically a RELATIVE not ABSOLUTE time
68   *        in the Open Group specification.
69   */
70
71  interval = 0;
72  if ( timeout ) {
73
74    if ( !_Timespec_Is_valid( timeout ) )
75      rtems_set_errno_and_return_minus_one( EINVAL );
76
77    interval = _Timespec_To_ticks( timeout );
78
79    if ( !interval )
80      rtems_set_errno_and_return_minus_one( EINVAL );
81  }
82
83  /*
84   *  Initialize local variables.
85   */
86
87  the_info = ( info ) ? info : &signal_information;
88
89  the_thread = _Thread_Executing;
90
91  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
92
93  /*
94   *  What if they are already pending?
95   */
96
97  /* API signals pending? */
98
99  _ISR_Disable( level );
100  if ( *set & api->signals_pending ) {
101    /* XXX real info later */
102    the_info->si_signo = _POSIX_signals_Get_highest( api->signals_pending );
103    _POSIX_signals_Clear_signals(
104      api,
105      the_info->si_signo,
106      the_info,
107      false,
108      false
109    );
110    _ISR_Enable( level );
111
112    the_info->si_code = SI_USER;
113    the_info->si_value.sival_int = 0;
114    return the_info->si_signo;
115  }
116
117  /* Process pending signals? */
118
119  if ( *set & _POSIX_signals_Pending ) {
120    signo = _POSIX_signals_Get_highest( _POSIX_signals_Pending );
121    _POSIX_signals_Clear_signals( api, signo, the_info, true, false );
122    _ISR_Enable( level );
123
124    the_info->si_signo = signo;
125    the_info->si_code = SI_USER;
126    the_info->si_value.sival_int = 0;
127    return signo;
128  }
129
130  the_info->si_signo = -1;
131
132  _Thread_Disable_dispatch();
133    the_thread->Wait.queue           = &_POSIX_signals_Wait_queue;
134    the_thread->Wait.return_code     = EINTR;
135    the_thread->Wait.option          = *set;
136    the_thread->Wait.return_argument = the_info;
137    _Thread_queue_Enter_critical_section( &_POSIX_signals_Wait_queue );
138    _ISR_Enable( level );
139    _Thread_queue_Enqueue( &_POSIX_signals_Wait_queue, interval );
140  _Thread_Enable_dispatch();
141
142  /*
143   * When the thread is set free by a signal, it is need to eliminate
144   * the signal.
145   */
146
147  _POSIX_signals_Clear_signals( api, the_info->si_signo, the_info, false, false );
148  errno = _Thread_Executing->Wait.return_code;
149  return the_info->si_signo;
150}
Note: See TracBrowser for help on using the repository browser.