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

4.104.114.84.95
Last change on this file since e7bd66a7 was e7bd66a7, checked in by Ralf Corsepius <ralf.corsepius@…>, on Oct 21, 2003 at 9:39:11 AM

2003-10-21 Ralf Corsepius <corsepiu@…>

  • src/cancelrun.c, src/pthreadexit.c, src/pthreadjoin.c, src/sigtimedwait.c: Remove unnecessary typecasts in assignments to thread->Wait.return_argument.
  • 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.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 ( 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 = 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.