source: rtems/cpukit/posix/src/sigtimedwait.c @ 8e36f29

4.104.114.84.95
Last change on this file since 8e36f29 was 8e36f29, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:54:26 PM

2003-09-04 Joel Sherrill <joel@…>

  • include/rtems/posix/cond.h, include/rtems/posix/condmp.h, include/rtems/posix/config.h, include/rtems/posix/intr.h, include/rtems/posix/key.h, include/rtems/posix/mqueue.h, include/rtems/posix/mqueuemp.h, include/rtems/posix/mutex.h, include/rtems/posix/mutexmp.h, include/rtems/posix/posixapi.h, include/rtems/posix/pthread.h, include/rtems/posix/pthreadmp.h, include/rtems/posix/ptimer.h, include/rtems/posix/semaphore.h, include/rtems/posix/semaphoremp.h, inline/rtems/posix/cond.inl, inline/rtems/posix/intr.inl, inline/rtems/posix/key.inl, inline/rtems/posix/mqueue.inl, inline/rtems/posix/mutex.inl, inline/rtems/posix/pthread.inl, inline/rtems/posix/semaphore.inl, inline/rtems/posix/timer.inl, macros/rtems/posix/cond.inl, macros/rtems/posix/intr.inl, macros/rtems/posix/key.inl, macros/rtems/posix/mqueue.inl, macros/rtems/posix/mutex.inl, macros/rtems/posix/pthread.inl, macros/rtems/posix/semaphore.inl, macros/rtems/posix/timer.inl, src/alarm.c, src/kill.c, src/killinfo.c, src/mqueuetranslatereturncode.c, src/pause.c, src/pthreadattrdestroy.c, src/pthreadattrgetdetachstate.c, src/pthreadattrgetinheritsched.c, src/pthreadattrgetschedparam.c, src/pthreadattrgetschedpolicy.c, src/pthreadattrgetscope.c, src/pthreadattrgetstackaddr.c, src/pthreadattrgetstacksize.c, src/pthreadattrinit.c, src/pthreadattrsetdetachstate.c, src/pthreadattrsetinheritsched.c, src/pthreadattrsetschedparam.c, src/pthreadattrsetschedpolicy.c, src/pthreadattrsetscope.c, src/pthreadattrsetstackaddr.c, src/pthreadattrsetstacksize.c, src/pthreadcreate.c, src/pthreaddetach.c, src/pthreadequal.c, src/pthreadexit.c, src/pthreadgetcpuclockid.c, src/pthreadgetcputime.c, src/pthreadgetschedparam.c, src/pthreadjoin.c, src/pthreadkill.c, src/pthreadonce.c, src/pthreadself.c, src/pthreadsetcputime.c, src/pthreadsetschedparam.c, src/pthreadsigmask.c, src/sigaction.c, src/sigaddset.c, src/sigdelset.c, src/sigemptyset.c, src/sigfillset.c, src/sigismember.c, src/signal_2.c, src/sigpending.c, src/sigprocmask.c, src/sigqueue.c, src/sigsuspend.c, src/sigtimedwait.c, src/sigwait.c, src/sigwaitinfo.c, src/ualarm.c: URL for license changed.
  • 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 = (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.