source: rtems/cpukit/posix/src/sigtimedwait.c @ f22ebf0

4.104.114.84.95
Last change on this file since f22ebf0 was e180a77e, checked in by Joel Sherrill <joel.sherrill@…>, on 01/04/02 at 18:28:24

2002-01-04 Ralf Corsepius <corsepiu@…>

  • src/clockgetres.c: Apply rtems_set_errno_and_return_minus_one.
  • src/clockgettime.c: Apply rtems_set_errno_and_return_minus_one.
  • src/clocksettime.c: Apply rtems_set_errno_and_return_minus_one.
  • src/killinfo.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueueclose.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuecreatesupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuegetattr.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuenotify.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueueopen.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuerecvsupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuesendsupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueuesetattr.c: Apply rtems_set_errno_and_return_minus_one.
  • src/mqueueunlink.c: Apply rtems_set_errno_and_return_minus_one.
  • src/nanosleep.c: Apply rtems_set_errno_and_return_minus_one.
  • src/pthreadkill.c: Apply rtems_set_errno_and_return_minus_one.
  • src/pthreadsigmask.c: Apply rtems_set_errno_and_return_minus_one.
  • src/ptimer1.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sched.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semaphorecreatesupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semaphorewaitsupp.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semclose.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semdestroy.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semgetvalue.c: Apply rtems_set_errno_and_return_minus_one.
  • src/seminit.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semopen.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sempost.c: Apply rtems_set_errno_and_return_minus_one.
  • src/semunlink.c: Apply rtems_set_errno_and_return_minus_one.
  • src/setpgid.c: Apply rtems_set_errno_and_return_minus_one.
  • src/setsid.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigaction.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigaddset.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigdelset.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigemptyset.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigfillset.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigismember.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigpending.c: Apply rtems_set_errno_and_return_minus_one.
  • src/sigtimedwait.c: Apply rtems_set_errno_and_return_minus_one.
  • src/utsname.c: Apply rtems_set_errno_and_return_minus_one.
  • Property mode set to 100644
File size: 3.4 KB
Line 
1/*
2 *  3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
3 *
4 *  COPYRIGHT (c) 1989-1999.
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.OARcorp.com/rtems/license.html.
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 ( timeout->tv_nsec < 0 ||
72         timeout->tv_nsec >= TOD_NANOSECONDS_PER_SECOND) {
73      rtems_set_errno_and_return_minus_one( EINVAL );
74    }
75
76    interval = _POSIX_Timespec_to_interval( timeout );
77  }
78
79  /*
80   *  Initialize local variables.
81   */
82
83  the_info = ( info ) ? info : &signal_information;
84
85  the_thread = _Thread_Executing;
86
87  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
88
89  /*
90   *  What if they are already pending?
91   */
92
93  /* API signals pending? */
94
95  _ISR_Disable( level );
96  if ( *set & api->signals_pending ) {
97    /* XXX real info later */
98    the_info->si_signo = _POSIX_signals_Get_highest( api->signals_pending );
99    _POSIX_signals_Clear_signals( api, the_info->si_signo, the_info, FALSE, FALSE );
100    _ISR_Enable( level );
101
102    the_info->si_code = SI_USER;
103    the_info->si_value.sival_int = 0;
104    return the_info->si_signo;
105  }
106
107  /* Process pending signals? */
108
109  if ( *set & _POSIX_signals_Pending ) {
110    signo = _POSIX_signals_Get_highest( _POSIX_signals_Pending );
111    _POSIX_signals_Clear_signals( api, signo, the_info, TRUE, FALSE );
112    _ISR_Enable( level );
113
114    the_info->si_signo = signo;
115    the_info->si_code = SI_USER;
116    the_info->si_value.sival_int = 0;
117    return signo;
118  }
119
120  the_info->si_signo = -1;
121
122  _Thread_Disable_dispatch();
123    the_thread->Wait.queue           = &_POSIX_signals_Wait_queue;
124    the_thread->Wait.return_code     = EINTR;
125    the_thread->Wait.option          = *set;
126    the_thread->Wait.return_argument = (void *) the_info;
127    _Thread_queue_Enter_critical_section( &_POSIX_signals_Wait_queue );
128    _ISR_Enable( level );
129    _Thread_queue_Enqueue( &_POSIX_signals_Wait_queue, interval );
130  _Thread_Enable_dispatch();
131
132  /*
133   * When the thread is set free by a signal, it is need to eliminate
134   * the signal.
135   */
136
137  _POSIX_signals_Clear_signals( api, the_info->si_signo, the_info, FALSE, FALSE );
138  errno = _Thread_Executing->Wait.return_code;
139  return the_info->si_signo;
140}
Note: See TracBrowser for help on using the repository browser.