//========================================================================== // // signal4.cxx // // POSIX signal test 4 // //========================================================================== // TODO: Need GPL header //========================================================================== //#####DESCRIPTIONBEGIN#### // // Author(s): Created by Dan Jakubiec from a template by nickg. // Contributors: Dan Jakubiec // Date: 2003-11-05 // Description: Tests POSIX signal SIGEV_THREAD functionality. // //####DESCRIPTIONEND#### //========================================================================== #include #include #if !defined(CYGPKG_POSIX_SIGNALS_SIGEV_THREAD) #define NA_MSG "POSIX SIGEV_THREAD support not enabled" #elif !defined(CYGPKG_POSIX_PTHREAD) #define NA_MSG "POSIX threads not enabled" #endif #ifdef NA_MSG void cyg_start(void) { CYG_TEST_INIT(); CYG_TEST_NA(NA_MSG); } #else #include #include #include #include #include volatile int sigthread_called = 0; #define SIGTHREAD_TESTVAL 0xA1B2C3D4 //-------------------------------------------------------------------------- // Signal handler function static void sigev_thread(union sigval context) { CYG_TEST_INFO( "sigev_thread() handler called" ); CYG_TEST_CHECK( context.sival_int == SIGTHREAD_TESTVAL, "sigev_thread() got bad context"); sigthread_called++; } //-------------------------------------------------------------------------- int main (int argc, char **argv) { int ret_val; sigset_t set; struct itimerspec timerValue; // Timeout value on eCos timer_t timer1; // Timer struct sigevent sev; CYG_TEST_INIT(); // Unblock all the signals. We shouldn't get any, though. sigfillset (&set); pthread_sigmask (SIG_UNBLOCK, &set, (sigset_t*)NULL); //-------------------------------------------------------------------- // //-------------------------------------------------------------------- // Notification type --- Launch a thread sev.sigev_notify = SIGEV_THREAD; sev.sigev_signo = SIGNULL; sev.sigev_value.sival_int = SIGTHREAD_TESTVAL; sev.sigev_notify_function = sigev_thread; sev.sigev_notify_attributes = NULL; // Timer values --- Timeout in 0.5 seconds, then every 1 second after that timerValue.it_value.tv_sec = 0; timerValue.it_value.tv_nsec = 5e8; /* 0.5 seconds */ timerValue.it_interval.tv_sec = 1; timerValue.it_interval.tv_nsec = 0; ret_val = timer_create (CLOCK_REALTIME, &sev, &timer1); CYG_TEST_CHECK( ret_val==0, "Error in creating the timer"); ret_val = timer_settime (timer1, 0, &timerValue, NULL ); CYG_TEST_CHECK( ret_val==0,"Error in setting the time"); //-------------------------------------------------------------------- // //-------------------------------------------------------------------- CYG_TEST_INFO ("Timer initialisation is completed.."); // Sleep for 5 seconds --- The thread handler should be called 5 times, // and the sleep should not be interrupted. CYG_TEST_INFO ("Calling sleep()"); ret_val = sleep(5); CYG_TEST_CHECK( ret_val==0, "sleep() did not return 0"); CYG_TEST_CHECK( sigthread_called==5, "Thread handler not properly called"); CYG_TEST_INFO ("Program terminating"); CYG_TEST_PASS_FINISH( "signal4" ); return 0; } #endif //-------------------------------------------------------------------------- // end of signal4.c