source: rtems/testsuites/psxtests/psxeintr_join/init.c @ bd1505b2

4.115
Last change on this file since bd1505b2 was bd1505b2, checked in by Joel Sherrill <joel.sherrill@…>, on 07/31/11 at 22:40:31

2011-07-31 Joel Sherrill <joel.sherrilL@…>

PR 1855/cpukit

  • Makefile.am, configure.ac: Correct signal processing during pthread_join. We are supposed to unblock the thread waiting on a pthread_join(), dispatch the signal handler, account for it potentially overwriting errno, and then have the thread return to blocking within pthread_join().
  • psxeintr_join/.cvsignore, psxeintr_join/Makefile.am, psxeintr_join/init.c, psxeintr_join/psxeintr_join.doc, psxeintr_join/psxeintr_join.scn: New files.
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#include <stdio.h>
13#include <signal.h>
14#include <semaphore.h>
15#include <pthread.h>
16
17#include <rtems.h>
18#include <tmacros.h>
19#include "test_support.h"
20
21#define SIG_SUSPEND SIGUSR1
22#define SIG_THR_RESTART SIGUSR2
23
24sem_t GC_suspend_ack_sem;
25
26static void print_sig_mask( const char * str )
27{
28  sigset_t blocked;
29  int      i;
30  int      status;
31
32  status = pthread_sigmask( SIG_BLOCK, NULL, &blocked );
33  rtems_test_assert( status == 0 );
34
35  printf( "%s blocked:\n", str );
36  for ( i = 1; i < NSIG; i++) {
37    if ( sigismember( &blocked, i ) )
38      printf( "%d ", i );
39  }
40  printf( "\n" );
41}
42
43void GC_suspend_handler( int sig )
44{
45  puts( "run in GC_suspend_handler" );
46  sem_post( &GC_suspend_ack_sem );
47}
48
49void GC_restart_handler( int sig )
50{
51  puts( "run in GC_restart_handler" );
52}
53
54void* run( void *arg )
55{
56  int       status;
57  pthread_t id = *(pthread_t *)arg;
58
59  print_sig_mask( "New Thread" );
60
61  status = pthread_kill( id, SIG_SUSPEND );
62  rtems_test_assert( status == 0 );
63
64  puts( "New Thread: after pthread_kill" );
65  status = sem_wait( &GC_suspend_ack_sem );
66  rtems_test_assert( status == 0 );
67
68  puts( "New Thread over!" );
69  return NULL;
70}
71
72void *POSIX_Init( void *arg )
73{
74  struct sigaction act;
75  pthread_t        newThread;
76  pthread_t        mainThread;
77  int              status;
78
79  puts( "*** POSIX TEST PSXEINTR_JOIN ***" );
80  status = sem_init( &GC_suspend_ack_sem, 0, 0);
81  rtems_test_assert( status == 0 );
82
83  status = sigemptyset( &act.sa_mask );
84  rtems_test_assert( status == 0 );
85
86  status = sigaddset( &act.sa_mask, SIG_SUSPEND );
87  rtems_test_assert( status == 0 );
88
89  status = pthread_sigmask( SIG_UNBLOCK, &act.sa_mask, NULL );
90  rtems_test_assert( status == 0 );
91
92  act.sa_handler = GC_suspend_handler;
93
94  status = sigaction( SIG_SUSPEND, &act, NULL );
95  rtems_test_assert( status == 0 );
96
97  act.sa_handler = GC_restart_handler;
98
99  print_sig_mask( "Main Thread" );
100
101  mainThread = pthread_self();
102  status = pthread_create( &newThread, NULL, run, &mainThread );
103  rtems_test_assert( status == 0 );
104
105  pthread_join( newThread, NULL );
106  puts( "Back from pthread_join" );
107
108  puts( "*** END OF POSIX TEST PSXEINTR_JOIN ***" );
109  rtems_test_exit( 0 );
110
111  return NULL;
112}
113
114/* configuration information */
115#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
116#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
117
118#define CONFIGURE_POSIX_INIT_THREAD_TABLE
119#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
120#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 1
121
122#define CONFIGURE_INIT
123#include <rtems/confdefs.h>
124/* end of file */
125
Note: See TracBrowser for help on using the repository browser.