Changeset ee979cd in rtems


Ignore:
Timestamp:
Nov 2, 1999, 5:36:20 PM (20 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, master
Children:
799c767
Parents:
96c041c
Message:

Split some more stuff out of psignal.c.

Files:
10 added
3 edited

Legend:

Unmodified
Added
Removed
  • c/src/exec/posix/src/Makefile.in

    r96c041c ree979cd  
    4646    pthreadattrgetscope pthreadattrsetscope
    4747
    48 PSIGNAL_C_PIECES = psignal alarm kill killinfo pause pthreadkill \
     48PSIGNAL_C_PIECES = psignal alarm kill killinfo pause \
     49    psignalclearprocesssignals psignalsetprocesssignals \
     50    psignalchecksignal psignalclearsignals \
     51    psignalunblockthread pthreadkill \
    4952    pthreadsigmask sigaction sigaddset sigdelset sigemptyset sigfillset \
    5053    sigismember sigpending sigprocmask sigqueue sigsuspend sigtimedwait \
  • c/src/exec/posix/src/psignal.c

    r96c041c ree979cd  
    9999      (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL))
    100100
    101 /*PAGE
    102  *
    103  *  _POSIX_signals_Unblock_thread
    104  */
    105 
    106 /* XXX this routine could probably be cleaned up */
    107 boolean _POSIX_signals_Unblock_thread(
    108   Thread_Control  *the_thread,
    109   int              signo,
    110   siginfo_t       *info
    111 )
    112 {
    113   POSIX_API_Control  *api;
    114   sigset_t            mask;
    115   siginfo_t          *the_info = NULL;
    116 
    117   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    118 
    119   mask = signo_to_mask( signo );
    120 
    121   /*
    122    *  Is the thread is specifically waiting for a signal?
    123    */
    124 
    125   if ( _States_Is_interruptible_signal( the_thread->current_state ) ) {
    126 
    127     if ( (the_thread->Wait.option & mask) || (~api->signals_blocked & mask) ) {
    128       the_thread->Wait.return_code = EINTR;
    129 
    130       the_info = (siginfo_t *) the_thread->Wait.return_argument;
    131 
    132       if ( !info ) {
    133         the_info->si_signo = signo;
    134         the_info->si_code = SI_USER;
    135         the_info->si_value.sival_int = 0;
    136       } else {
    137         *the_info = *info;
    138       }
    139      
    140       _Thread_queue_Extract_with_proxy( the_thread );
    141       return TRUE;
    142     }
    143 
    144     /*
    145      *  This should only be reached via pthread_kill().
    146      */
    147 
    148     return FALSE;
    149   }
    150 
    151   if ( ~api->signals_blocked & mask ) {
    152     the_thread->do_post_task_switch_extension = TRUE;
    153 
    154     if ( the_thread->current_state & STATES_INTERRUPTIBLE_BY_SIGNAL ) {
    155       the_thread->Wait.return_code = EINTR;
    156       if ( _States_Is_waiting_on_thread_queue(the_thread->current_state) )
    157         _Thread_queue_Extract_with_proxy( the_thread );
    158       else if ( _States_Is_delaying(the_thread->current_state)){
    159         if ( _Watchdog_Is_active( &the_thread->Timer ) )
    160           (void) _Watchdog_Remove( &the_thread->Timer );
    161         _Thread_Unblock( the_thread );
    162       }
    163     }
    164   }
    165   return FALSE;
    166 
    167 }
    168 
    169 /*PAGE
    170  *
    171  *  _POSIX_signals_Set_process_signals
    172  */
    173  
    174 void _POSIX_signals_Set_process_signals(
    175   sigset_t   mask
    176 )
    177 {
    178   ISR_Level  level;
    179  
    180   _ISR_Disable( level );
    181     if ( !_POSIX_signals_Pending )
    182       _Thread_Do_post_task_switch_extension++;
    183     _POSIX_signals_Pending |= mask;
    184   _ISR_Enable( level );
    185 }
    186 
    187 /*PAGE
    188  *
    189  *  _POSIX_signals_Clear_process_signals
    190  */
    191 
    192 void _POSIX_signals_Clear_process_signals(
    193   sigset_t   mask
    194 )
    195 {
    196   ISR_Level  level;
    197 
    198   _ISR_Disable( level );
    199     _POSIX_signals_Pending &= ~mask;
    200     if ( !_POSIX_signals_Pending )
    201       _Thread_Do_post_task_switch_extension--;
    202   _ISR_Enable( level );
    203 }
    204 
    205 /*PAGE
    206  *
    207  *  _POSIX_signals_Clear_signals
    208  */
    209  
    210 boolean _POSIX_signals_Clear_signals(
    211   POSIX_API_Control  *api,
    212   int                 signo,
    213   siginfo_t          *info,
    214   boolean             is_global,
    215   boolean             check_blocked
    216 )
    217 {
    218   sigset_t                    mask;
    219   sigset_t                    signals_blocked;
    220   ISR_Level                   level;
    221   boolean                     do_callout;
    222   POSIX_signals_Siginfo_node *psiginfo;
    223  
    224   mask = signo_to_mask( signo );
    225  
    226   do_callout = FALSE;
    227  
    228   /* set blocked signals based on if checking for them, SIGNAL_ALL_MASK
    229    * insures that no signals are blocked and all are checked.
    230    */
    231 
    232   if ( check_blocked )
    233     signals_blocked = ~api->signals_blocked;
    234   else
    235     signals_blocked = SIGNAL_ALL_MASK;
    236 
    237   /* XXX this is not right for siginfo type signals yet */
    238   /* XXX since they can't be cleared the same way */
    239  
    240   _ISR_Disable( level );
    241     if ( is_global ) {
    242        if ( mask & (_POSIX_signals_Pending & signals_blocked) ) {
    243          if ( _POSIX_signals_Vectors[ signo ].sa_flags == SA_SIGINFO ) {
    244            psiginfo = (POSIX_signals_Siginfo_node *)
    245              _Chain_Get_unprotected( &_POSIX_signals_Siginfo[ signo ] );
    246            if ( _Chain_Is_empty( &_POSIX_signals_Siginfo[ signo ] ) )
    247              _POSIX_signals_Clear_process_signals( mask );
    248            if ( psiginfo ) {
    249              *info = psiginfo->Info;
    250              _Chain_Append_unprotected(
    251                &_POSIX_signals_Inactive_siginfo,
    252                &psiginfo->Node
    253              );
    254            } else
    255              do_callout = FALSE;
    256          } else
    257            _POSIX_signals_Clear_process_signals( mask );
    258          do_callout = TRUE;
    259        }
    260     } else {
    261       if ( mask & (api->signals_pending & signals_blocked) ) {
    262         api->signals_pending &= ~mask;
    263         do_callout = TRUE;
    264       }
    265     }
    266   _ISR_Enable( level );
    267   return do_callout;
    268 }
    269 
    270 
    271 /*PAGE
    272  *
    273  *  _POSIX_signals_Check_signal
    274  */
    275 
    276 boolean _POSIX_signals_Check_signal(
    277   POSIX_API_Control  *api,
    278   int                 signo,
    279   boolean             is_global
    280 )
    281 {
    282   siginfo_t                   siginfo_struct;
    283   sigset_t                    saved_signals_blocked;
    284 
    285   if ( ! _POSIX_signals_Clear_signals( api, signo, &siginfo_struct,
    286                                        is_global, TRUE ) )
    287     return FALSE;
    288 
    289   /*
    290    *  Since we made a union of these, only one test is necessary but this is
    291    *  safer.
    292    */
    293 
    294   assert( _POSIX_signals_Vectors[ signo ].sa_handler ||
    295           _POSIX_signals_Vectors[ signo ].sa_sigaction );
    296  
    297   /*
    298    *  Just to prevent sending a signal which is currently being ignored.
    299    */
    300 
    301   if ( _POSIX_signals_Vectors[ signo ].sa_handler == SIG_IGN )
    302     return FALSE;
    303 
    304   /*
    305    *  Block the signals requested in sa_mask
    306    */
    307 
    308   saved_signals_blocked = api->signals_blocked;
    309   api->signals_blocked |= _POSIX_signals_Vectors[ signo ].sa_mask;
    310 
    311   /* Here, the signal handler function executes */
    312 
    313   switch ( _POSIX_signals_Vectors[ signo ].sa_flags ) {
    314     case SA_SIGINFO:
    315101/*
    316  *
    317  *     assert( is_global );
    318  */
    319       (*_POSIX_signals_Vectors[ signo ].sa_sigaction)(
    320         signo,
    321         &siginfo_struct,
    322         NULL        /* context is undefined per 1003.1b-1993, p. 66 */
    323       );
    324       break;
    325     default:
    326       (*_POSIX_signals_Vectors[ signo ].sa_handler)( signo );
    327       break;
    328   }
    329 
    330   /*
    331    *  Restore the previous set of blocked signals
    332    */
    333  
    334   api->signals_blocked = saved_signals_blocked;
    335 
    336   return TRUE;
    337 }
     102 *  _POSIX_signals_Post_switch_extension
     103 */
    338104
    339105void _POSIX_signals_Post_switch_extension(
  • cpukit/posix/src/psignal.c

    r96c041c ree979cd  
    9999      (STATES_WAITING_FOR_SIGNAL|STATES_INTERRUPTIBLE_BY_SIGNAL))
    100100
    101 /*PAGE
    102  *
    103  *  _POSIX_signals_Unblock_thread
    104  */
    105 
    106 /* XXX this routine could probably be cleaned up */
    107 boolean _POSIX_signals_Unblock_thread(
    108   Thread_Control  *the_thread,
    109   int              signo,
    110   siginfo_t       *info
    111 )
    112 {
    113   POSIX_API_Control  *api;
    114   sigset_t            mask;
    115   siginfo_t          *the_info = NULL;
    116 
    117   api = the_thread->API_Extensions[ THREAD_API_POSIX ];
    118 
    119   mask = signo_to_mask( signo );
    120 
    121   /*
    122    *  Is the thread is specifically waiting for a signal?
    123    */
    124 
    125   if ( _States_Is_interruptible_signal( the_thread->current_state ) ) {
    126 
    127     if ( (the_thread->Wait.option & mask) || (~api->signals_blocked & mask) ) {
    128       the_thread->Wait.return_code = EINTR;
    129 
    130       the_info = (siginfo_t *) the_thread->Wait.return_argument;
    131 
    132       if ( !info ) {
    133         the_info->si_signo = signo;
    134         the_info->si_code = SI_USER;
    135         the_info->si_value.sival_int = 0;
    136       } else {
    137         *the_info = *info;
    138       }
    139      
    140       _Thread_queue_Extract_with_proxy( the_thread );
    141       return TRUE;
    142     }
    143 
    144     /*
    145      *  This should only be reached via pthread_kill().
    146      */
    147 
    148     return FALSE;
    149   }
    150 
    151   if ( ~api->signals_blocked & mask ) {
    152     the_thread->do_post_task_switch_extension = TRUE;
    153 
    154     if ( the_thread->current_state & STATES_INTERRUPTIBLE_BY_SIGNAL ) {
    155       the_thread->Wait.return_code = EINTR;
    156       if ( _States_Is_waiting_on_thread_queue(the_thread->current_state) )
    157         _Thread_queue_Extract_with_proxy( the_thread );
    158       else if ( _States_Is_delaying(the_thread->current_state)){
    159         if ( _Watchdog_Is_active( &the_thread->Timer ) )
    160           (void) _Watchdog_Remove( &the_thread->Timer );
    161         _Thread_Unblock( the_thread );
    162       }
    163     }
    164   }
    165   return FALSE;
    166 
    167 }
    168 
    169 /*PAGE
    170  *
    171  *  _POSIX_signals_Set_process_signals
    172  */
    173  
    174 void _POSIX_signals_Set_process_signals(
    175   sigset_t   mask
    176 )
    177 {
    178   ISR_Level  level;
    179  
    180   _ISR_Disable( level );
    181     if ( !_POSIX_signals_Pending )
    182       _Thread_Do_post_task_switch_extension++;
    183     _POSIX_signals_Pending |= mask;
    184   _ISR_Enable( level );
    185 }
    186 
    187 /*PAGE
    188  *
    189  *  _POSIX_signals_Clear_process_signals
    190  */
    191 
    192 void _POSIX_signals_Clear_process_signals(
    193   sigset_t   mask
    194 )
    195 {
    196   ISR_Level  level;
    197 
    198   _ISR_Disable( level );
    199     _POSIX_signals_Pending &= ~mask;
    200     if ( !_POSIX_signals_Pending )
    201       _Thread_Do_post_task_switch_extension--;
    202   _ISR_Enable( level );
    203 }
    204 
    205 /*PAGE
    206  *
    207  *  _POSIX_signals_Clear_signals
    208  */
    209  
    210 boolean _POSIX_signals_Clear_signals(
    211   POSIX_API_Control  *api,
    212   int                 signo,
    213   siginfo_t          *info,
    214   boolean             is_global,
    215   boolean             check_blocked
    216 )
    217 {
    218   sigset_t                    mask;
    219   sigset_t                    signals_blocked;
    220   ISR_Level                   level;
    221   boolean                     do_callout;
    222   POSIX_signals_Siginfo_node *psiginfo;
    223  
    224   mask = signo_to_mask( signo );
    225  
    226   do_callout = FALSE;
    227  
    228   /* set blocked signals based on if checking for them, SIGNAL_ALL_MASK
    229    * insures that no signals are blocked and all are checked.
    230    */
    231 
    232   if ( check_blocked )
    233     signals_blocked = ~api->signals_blocked;
    234   else
    235     signals_blocked = SIGNAL_ALL_MASK;
    236 
    237   /* XXX this is not right for siginfo type signals yet */
    238   /* XXX since they can't be cleared the same way */
    239  
    240   _ISR_Disable( level );
    241     if ( is_global ) {
    242        if ( mask & (_POSIX_signals_Pending & signals_blocked) ) {
    243          if ( _POSIX_signals_Vectors[ signo ].sa_flags == SA_SIGINFO ) {
    244            psiginfo = (POSIX_signals_Siginfo_node *)
    245              _Chain_Get_unprotected( &_POSIX_signals_Siginfo[ signo ] );
    246            if ( _Chain_Is_empty( &_POSIX_signals_Siginfo[ signo ] ) )
    247              _POSIX_signals_Clear_process_signals( mask );
    248            if ( psiginfo ) {
    249              *info = psiginfo->Info;
    250              _Chain_Append_unprotected(
    251                &_POSIX_signals_Inactive_siginfo,
    252                &psiginfo->Node
    253              );
    254            } else
    255              do_callout = FALSE;
    256          } else
    257            _POSIX_signals_Clear_process_signals( mask );
    258          do_callout = TRUE;
    259        }
    260     } else {
    261       if ( mask & (api->signals_pending & signals_blocked) ) {
    262         api->signals_pending &= ~mask;
    263         do_callout = TRUE;
    264       }
    265     }
    266   _ISR_Enable( level );
    267   return do_callout;
    268 }
    269 
    270 
    271 /*PAGE
    272  *
    273  *  _POSIX_signals_Check_signal
    274  */
    275 
    276 boolean _POSIX_signals_Check_signal(
    277   POSIX_API_Control  *api,
    278   int                 signo,
    279   boolean             is_global
    280 )
    281 {
    282   siginfo_t                   siginfo_struct;
    283   sigset_t                    saved_signals_blocked;
    284 
    285   if ( ! _POSIX_signals_Clear_signals( api, signo, &siginfo_struct,
    286                                        is_global, TRUE ) )
    287     return FALSE;
    288 
    289   /*
    290    *  Since we made a union of these, only one test is necessary but this is
    291    *  safer.
    292    */
    293 
    294   assert( _POSIX_signals_Vectors[ signo ].sa_handler ||
    295           _POSIX_signals_Vectors[ signo ].sa_sigaction );
    296  
    297   /*
    298    *  Just to prevent sending a signal which is currently being ignored.
    299    */
    300 
    301   if ( _POSIX_signals_Vectors[ signo ].sa_handler == SIG_IGN )
    302     return FALSE;
    303 
    304   /*
    305    *  Block the signals requested in sa_mask
    306    */
    307 
    308   saved_signals_blocked = api->signals_blocked;
    309   api->signals_blocked |= _POSIX_signals_Vectors[ signo ].sa_mask;
    310 
    311   /* Here, the signal handler function executes */
    312 
    313   switch ( _POSIX_signals_Vectors[ signo ].sa_flags ) {
    314     case SA_SIGINFO:
    315101/*
    316  *
    317  *     assert( is_global );
    318  */
    319       (*_POSIX_signals_Vectors[ signo ].sa_sigaction)(
    320         signo,
    321         &siginfo_struct,
    322         NULL        /* context is undefined per 1003.1b-1993, p. 66 */
    323       );
    324       break;
    325     default:
    326       (*_POSIX_signals_Vectors[ signo ].sa_handler)( signo );
    327       break;
    328   }
    329 
    330   /*
    331    *  Restore the previous set of blocked signals
    332    */
    333  
    334   api->signals_blocked = saved_signals_blocked;
    335 
    336   return TRUE;
    337 }
     102 *  _POSIX_signals_Post_switch_extension
     103 */
    338104
    339105void _POSIX_signals_Post_switch_extension(
Note: See TracChangeset for help on using the changeset viewer.