Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:37

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2012.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
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 /* forward declarations to avoid warnings */
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 /* configuration information */
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 /* end of file */
0156