source: rtems/c/src/exec/posix/src/sigtimedwait.c @ 07d880f4

4.104.114.84.95
Last change on this file since 07d880f4 was 07d880f4, checked in by Joel Sherrill <joel.sherrill@…>, on 01/31/99 at 20:45:31

Split psignal.c into many more files. This reduced the amount of
object code that has to be loaded just for initializing the signal
manager.

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  3.3.8 Synchronously Accept a Signal, P1003.1b-1993, p. 76
3 *
4 *  COPYRIGHT (c) 1989-1998.
5 *  On-Line Applications Research Corporation (OAR).
6 *  Copyright assigned to U.S. Government, 1994.
7 *
8 *  The license and distribution terms for this file may be
9 *  found in the file LICENSE in this distribution or at
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15
16#include <pthread.h>
17#include <signal.h>
18#include <errno.h>
19
20#include <rtems/system.h>
21#include <rtems/posix/pthread.h>
22#include <rtems/posix/psignal.h>
23#include <rtems/posix/seterr.h>
24#include <rtems/posix/time.h>
25
26int _POSIX_signals_Get_highest(
27  sigset_t   set
28)
29{
30  int signo;
31
32  for ( signo = SIGRTMIN ; signo <= SIGRTMAX ; signo++ ) {
33    if ( set & signo_to_mask( signo ) )
34      return signo;
35  }
36
37/* XXX - add __SIGFIRSTNOTRT or something like that to newlib siginfo.h */
38
39  for ( signo = SIGHUP ; signo <= __SIGLASTNOTRT ; signo++ ) {
40    if ( set & signo_to_mask( signo ) )
41      return signo;
42  }
43
44  return 0;
45}
46
47int sigtimedwait(
48  const sigset_t         *set,
49  siginfo_t              *info,
50  const struct timespec  *timeout
51)
52{
53  Thread_Control    *the_thread;
54  POSIX_API_Control *api;
55  Watchdog_Interval  interval;
56  siginfo_t          signal_information;
57  siginfo_t         *the_info;
58  int                signo;
59 
60  the_info = ( info ) ? info : &signal_information;
61
62  the_thread = _Thread_Executing;
63
64  api = the_thread->API_Extensions[ THREAD_API_POSIX ];
65
66  /*
67   *  What if they are already pending?
68   */
69
70  /* API signals pending? */
71
72  if ( *set & api->signals_pending ) {
73    /* XXX real info later */
74    the_info->si_signo = _POSIX_signals_Get_highest( api->signals_pending );
75    _POSIX_signals_Clear_signals( api, the_info->si_signo, the_info,
76                                  FALSE, FALSE );
77    the_info->si_code = SI_USER;
78    the_info->si_value.sival_int = 0;
79    return the_info->si_signo;
80  }
81
82  /* Process pending signals? */
83
84  if ( *set & _POSIX_signals_Pending) {
85    signo = _POSIX_signals_Get_highest( _POSIX_signals_Pending );
86    _POSIX_signals_Clear_signals( api, signo, the_info, TRUE, FALSE );
87
88    if ( !info ) {
89      the_info->si_signo = signo;
90      the_info->si_code = SI_USER;
91      the_info->si_value.sival_int = 0;
92    }
93  }
94
95  interval = 0;
96  if ( timeout ) {
97
98    if (timeout->tv_nsec < 0 || timeout->tv_nsec >= TOD_NANOSECONDS_PER_SECOND)
99      set_errno_and_return_minus_one( EINVAL );
100
101    interval = _POSIX_Timespec_to_interval( timeout );
102  }
103
104  the_info->si_signo = -1;
105
106  _Thread_Disable_dispatch();
107    the_thread->Wait.queue           = &_POSIX_signals_Wait_queue;
108    the_thread->Wait.return_code     = EINTR;
109    the_thread->Wait.option          = *set;
110    the_thread->Wait.return_argument = (void *) the_info;
111    _Thread_queue_Enter_critical_section( &_POSIX_signals_Wait_queue );
112    _Thread_queue_Enqueue( &_POSIX_signals_Wait_queue, interval );
113  _Thread_Enable_dispatch();
114
115  errno = _Thread_Executing->Wait.return_code;
116  return the_info->si_signo;
117}
Note: See TracBrowser for help on using the repository browser.