File indexing completed on 2025-05-11 08:24:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <stdio.h>
0034 #include <signal.h>
0035 #include <semaphore.h>
0036 #include <pthread.h>
0037
0038 #include <rtems.h>
0039 #include <tmacros.h>
0040 #include "test_support.h"
0041
0042 const char rtems_test_name[] = "PSXEINTR_JOIN";
0043
0044 #define SIG_SUSPEND SIGUSR1
0045 #define SIG_THR_RESTART SIGUSR2
0046
0047
0048 void *POSIX_Init(void *argument);
0049 static void print_sig_mask(const char * str);
0050 void GC_suspend_handler(int sig);
0051 void GC_restart_handler(int sig);
0052 void *run(void *arg);
0053
0054 sem_t GC_suspend_ack_sem;
0055
0056 static void print_sig_mask( const char * str )
0057 {
0058 sigset_t blocked;
0059 int i;
0060 int status;
0061
0062 status = pthread_sigmask( SIG_BLOCK, NULL, &blocked );
0063 rtems_test_assert( status == 0 );
0064
0065 printf( "%s blocked:\n", str );
0066 for ( i = 1; i < NSIG; i++) {
0067 if ( sigismember( &blocked, i ) )
0068 printf( "%d ", i );
0069 }
0070 printf( "\n" );
0071 }
0072
0073 void GC_suspend_handler( int sig )
0074 {
0075 puts( "run in GC_suspend_handler" );
0076 sem_post( &GC_suspend_ack_sem );
0077 }
0078
0079 void GC_restart_handler( int sig )
0080 {
0081 puts( "run in GC_restart_handler" );
0082 }
0083
0084 void *run( void *arg )
0085 {
0086 int status;
0087 pthread_t id = *(pthread_t *)arg;
0088
0089 print_sig_mask( "New Thread" );
0090
0091 status = pthread_kill( id, SIG_SUSPEND );
0092 rtems_test_assert( status == 0 );
0093
0094 puts( "New Thread: after pthread_kill" );
0095 status = sem_wait( &GC_suspend_ack_sem );
0096 rtems_test_assert( status == 0 );
0097
0098 puts( "New Thread over!" );
0099 return NULL;
0100 }
0101
0102 void *POSIX_Init( void *arg )
0103 {
0104 struct sigaction act;
0105 pthread_t newThread;
0106 pthread_t mainThread;
0107 int status;
0108
0109 TEST_BEGIN();
0110 status = sem_init( &GC_suspend_ack_sem, 0, 0);
0111 rtems_test_assert( status == 0 );
0112
0113 status = sigemptyset( &act.sa_mask );
0114 rtems_test_assert( status == 0 );
0115
0116 status = sigaddset( &act.sa_mask, SIG_SUSPEND );
0117 rtems_test_assert( status == 0 );
0118
0119 status = pthread_sigmask( SIG_UNBLOCK, &act.sa_mask, NULL );
0120 rtems_test_assert( status == 0 );
0121
0122 act.sa_handler = GC_suspend_handler;
0123
0124 status = sigaction( SIG_SUSPEND, &act, NULL );
0125 rtems_test_assert( status == 0 );
0126
0127 act.sa_handler = GC_restart_handler;
0128
0129 print_sig_mask( "Main Thread" );
0130
0131 mainThread = pthread_self();
0132 status = pthread_create( &newThread, NULL, run, &mainThread );
0133 rtems_test_assert( status == 0 );
0134
0135 pthread_join( newThread, NULL );
0136 puts( "Back from pthread_join" );
0137
0138 TEST_END();
0139 rtems_test_exit( 0 );
0140
0141 return NULL;
0142 }
0143
0144
0145 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0146 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0147
0148 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
0149 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0150
0151 #define CONFIGURE_MAXIMUM_POSIX_THREADS 2
0152
0153 #define CONFIGURE_INIT
0154 #include <rtems/confdefs.h>
0155
0156