From 98ed15e30fffa76a0dc298e1d68cf21a70f90bae Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 11 Jun 1996 16:01:37 +0000 Subject: Basic signal functionality appears to work. pthread_kill() can successfully send signals to the current thread or to another blocked thread. nanosleep() can be interrupted by a signal and return the time remaining. Post switch extension added to dispatch posix signal handlers. --- cpukit/posix/src/psignal.c | 32 +++++++++++++++++++++++++------- cpukit/posix/src/pthread.c | 3 ++- cpukit/posix/src/time.c | 5 ++++- 3 files changed, 31 insertions(+), 9 deletions(-) (limited to 'cpukit/posix') diff --git a/cpukit/posix/src/psignal.c b/cpukit/posix/src/psignal.c index 36f0583ddf..b0496cf225 100644 --- a/cpukit/posix/src/psignal.c +++ b/cpukit/posix/src/psignal.c @@ -127,6 +127,14 @@ boolean _POSIX_signals_Check_signal( if ( !do_callout ) return FALSE; + + /* + * Since we made a union of these, only one test is necessary but this is + * safer. + */ + + assert( _POSIX_signals_Vectors[ signo ].sa_handler || + _POSIX_signals_Vectors[ signo ].sa_sigaction ); switch ( _POSIX_signals_Vectors[ signo ].sa_flags ) { case SA_SIGINFO: @@ -150,7 +158,7 @@ boolean _POSIX_signals_Check_signal( return TRUE; } -void _POSIX_signals_Run_Them( +void _POSIX_signals_Post_switch_extension( Thread_Control *the_thread ) { @@ -376,7 +384,7 @@ int sigaction( _POSIX_signals_Vectors[ sig ] = *act; - return POSIX_NOT_IMPLEMENTED(); + return 0; } /* @@ -604,7 +612,7 @@ int pthread_kill( * If sig == 0 then just validate arguments */ - api = _Thread_Executing->API_Extensions[ THREAD_API_POSIX ]; + api = the_thread->API_Extensions[ THREAD_API_POSIX ]; if ( sig ) { @@ -615,12 +623,22 @@ int pthread_kill( if ( api->signals_pending & ~api->signals_blocked ) { the_thread->do_post_task_switch_extension = TRUE; - /* XXX may have to unblock the task */ - + + /* XXX may have to unblock the task -- this is a kludge -- fix it */ + if ( the_thread->current_state & STATES_INTERRUPTIBLE_BY_SIGNAL ) { + the_thread->Wait.return_code = EINTR; + if ( _States_Is_waiting_on_thread_queue(the_thread->current_state) ) + _Thread_queue_Extract_with_proxy( the_thread ); + else if ( _States_Is_delaying(the_thread->current_state)){ + if ( _Watchdog_Is_active( &the_thread->Timer ) ) + (void) _Watchdog_Remove( &the_thread->Timer ); + _Thread_Unblock( the_thread ); + } } } - _Thread_Enable_dispatch(); - return 0; + } + _Thread_Enable_dispatch(); + return 0; } return POSIX_BOTTOM_REACHED(); diff --git a/cpukit/posix/src/pthread.c b/cpukit/posix/src/pthread.c index aaf005312f..877af7a8ff 100644 --- a/cpukit/posix/src/pthread.c +++ b/cpukit/posix/src/pthread.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -222,7 +223,7 @@ API_extensions_Control _POSIX_Threads_API_extensions = { { NULL, NULL }, NULL, /* predriver */ _POSIX_Threads_Initialize_user_threads, /* postdriver */ - NULL, /* post switch */ + _POSIX_signals_Post_switch_extension, /* post switch */ }; User_extensions_Control _POSIX_Threads_User_extensions = { diff --git a/cpukit/posix/src/time.c b/cpukit/posix/src/time.c index 3860ae993d..10808dd6b5 100644 --- a/cpukit/posix/src/time.c +++ b/cpukit/posix/src/time.c @@ -247,7 +247,10 @@ int nanosleep( ticks = _POSIX_Timespec_to_interval( rqtp ); _Thread_Disable_dispatch(); - _Thread_Set_state( _Thread_Executing, STATES_WAITING_FOR_TIME ); + _Thread_Set_state( + _Thread_Executing, + STATES_DELAYING | STATES_INTERRUPTIBLE_BY_SIGNAL + ); _Watchdog_Initialize( &_Thread_Executing->Timer, _Thread_Delay_ended, /* XXX may need to be POSIX specific */ -- cgit v1.2.3