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

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <stdio.h>
15#include <signal.h>
16#include <semaphore.h>
17#include <pthread.h>
18
19#include <rtems.h>
20#include <tmacros.h>
21#include "test_support.h"
22
23#define SIG_SUSPEND SIGUSR1
24#define SIG_THR_RESTART SIGUSR2
25
26/* forward declarations to avoid warnings */
27void *POSIX_Init(void *argument);
28static void print_sig_mask(const char * str);
29void GC_suspend_handler(int sig);
30void GC_restart_handler(int sig);
31void *run(void *arg);
32
33sem_t GC_suspend_ack_sem;
34
35static void print_sig_mask( const char * str )
36{
37  sigset_t blocked;
38  int      i;
39  int      status;
40
41  status = pthread_sigmask( SIG_BLOCK, NULL, &blocked );
42  rtems_test_assert( status == 0 );
43
44  printf( "%s blocked:\n", str );
45  for ( i = 1; i < NSIG; i++) {
46    if ( sigismember( &blocked, i ) )
47      printf( "%d ", i );
48  }
49  printf( "\n" );
50}
51
52void GC_suspend_handler( int sig )
53{
54  puts( "run in GC_suspend_handler" );
55  sem_post( &GC_suspend_ack_sem );
56}
57
58void GC_restart_handler( int sig )
59{
60  puts( "run in GC_restart_handler" );
61}
62
63void *run( void *arg )
64{
65  int       status;
66  pthread_t id = *(pthread_t *)arg;
67
68  print_sig_mask( "New Thread" );
69
70  status = pthread_kill( id, SIG_SUSPEND );
71  rtems_test_assert( status == 0 );
72
73  puts( "New Thread: after pthread_kill" );
74  status = sem_wait( &GC_suspend_ack_sem );
75  rtems_test_assert( status == 0 );
76
77  puts( "New Thread over!" );
78  return NULL;
79}
80
81void *POSIX_Init( void *arg )
82{
83  struct sigaction act;
84  pthread_t        newThread;
85  pthread_t        mainThread;
86  int              status;
87
88  puts( "*** POSIX TEST PSXEINTR_JOIN ***" );
89  status = sem_init( &GC_suspend_ack_sem, 0, 0);
90  rtems_test_assert( status == 0 );
91
92  status = sigemptyset( &act.sa_mask );
93  rtems_test_assert( status == 0 );
94
95  status = sigaddset( &act.sa_mask, SIG_SUSPEND );
96  rtems_test_assert( status == 0 );
97
98  status = pthread_sigmask( SIG_UNBLOCK, &act.sa_mask, NULL );
99  rtems_test_assert( status == 0 );
100
101  act.sa_handler = GC_suspend_handler;
102
103  status = sigaction( SIG_SUSPEND, &act, NULL );
104  rtems_test_assert( status == 0 );
105
106  act.sa_handler = GC_restart_handler;
107
108  print_sig_mask( "Main Thread" );
109
110  mainThread = pthread_self();
111  status = pthread_create( &newThread, NULL, run, &mainThread );
112  rtems_test_assert( status == 0 );
113
114  pthread_join( newThread, NULL );
115  puts( "Back from pthread_join" );
116
117  puts( "*** END OF POSIX TEST PSXEINTR_JOIN ***" );
118  rtems_test_exit( 0 );
119
120  return NULL;
121}
122
123/* configuration information */
124#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
125#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
126
127#define CONFIGURE_POSIX_INIT_THREAD_TABLE
128#define CONFIGURE_MAXIMUM_POSIX_THREADS 2
129#define CONFIGURE_MAXIMUM_POSIX_SEMAPHORES 1
130
131#define CONFIGURE_INIT
132#include <rtems/confdefs.h>
133/* end of file */
134
Note: See TracBrowser for help on using the repository browser.