forked from Imagelibrary/rtems
modified to test pthread_kill() to self and pthread_kill() to a blocked
thread. nanosleep() can be interrupted and return the time remaining.
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
#define CONFIGURE_INIT
|
||||
#include "system.h"
|
||||
#include <signal.h>
|
||||
|
||||
volatile int Signal_occurred;
|
||||
|
||||
@@ -19,7 +20,7 @@ void Signal_handler(
|
||||
int signo
|
||||
)
|
||||
{
|
||||
printf( "Signal: %d caught\n", signo );
|
||||
printf( "Signal: %d caught by 0x%x\n", signo, pthread_self() );
|
||||
Signal_occurred = 1;
|
||||
}
|
||||
|
||||
@@ -27,9 +28,10 @@ void *POSIX_Init(
|
||||
void *argument
|
||||
)
|
||||
{
|
||||
int status;
|
||||
struct timespec tv;
|
||||
struct timespec tr;
|
||||
int status;
|
||||
struct timespec tv;
|
||||
struct timespec tr;
|
||||
struct sigaction act;
|
||||
|
||||
puts( "\n\n*** POSIX TEST 2 ***" );
|
||||
|
||||
@@ -42,6 +44,21 @@ void *POSIX_Init(
|
||||
Init_id = pthread_self();
|
||||
printf( "Init's ID is 0x%08x\n", Init_id );
|
||||
|
||||
/* install a signal handler */
|
||||
|
||||
status = sigemptyset( &act.sa_mask );
|
||||
assert( !status );
|
||||
|
||||
act.sa_handler = Signal_handler;
|
||||
act.sa_flags = 0;
|
||||
|
||||
sigaction( SIGUSR1, &act, NULL );
|
||||
|
||||
/* simple signal to self */
|
||||
|
||||
status = pthread_kill( Init_id, SIGUSR1 );
|
||||
assert( !status );
|
||||
|
||||
/* create a thread */
|
||||
|
||||
status = pthread_create( &Task_id, NULL, Task_1_through_3, NULL );
|
||||
@@ -62,7 +79,6 @@ void *POSIX_Init(
|
||||
status = nanosleep ( &tv, &tr );
|
||||
assert( !status );
|
||||
|
||||
print_current_time( "Init: ", "" );
|
||||
printf(
|
||||
"Init: signal was %sprocessed with %d:%d time remaining\n",
|
||||
(Signal_occurred) ? "" : "not ",
|
||||
|
||||
@@ -31,12 +31,12 @@ void *Task_1_through_3(
|
||||
int status;
|
||||
|
||||
for ( i=0 ; i<5 ; i++ ) {
|
||||
seconds = sleep( 1 );
|
||||
assert( !seconds );
|
||||
|
||||
print_current_time( "Task1: ", "" );
|
||||
status = pthread_kill( Init_id, SIGUSR1 );
|
||||
assert( !status );
|
||||
|
||||
seconds = sleep( 1 );
|
||||
assert( !seconds );
|
||||
}
|
||||
puts( "*** END OF POSIX TEST 2 ***" );
|
||||
exit( 0 );
|
||||
|
||||
Reference in New Issue
Block a user