OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [posix/] [src/] [sigtimedwait.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  sigtimedwait.c,v 1.9 2002/01/04 18:28:24 joel Exp
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
 
29
int _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
 
50
int 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
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.