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