summaryrefslogtreecommitdiff
path: root/examples/Misc/test_trace.cpp
blob: 41b407cbdcacb528460f3e0e5bd91bbc443cc2e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Enable tracing
// $Id$

#define ACE_NTRACE 0

#include "ace/Thread.h"
#include "ace/Signal.h"

static void
foo (int max_depth)
{
  ACE_Trace _ ("void foo (void)", __LINE__, __FILE__);

  if (max_depth > 0)
    foo (max_depth - 1);
  // Destructor automatically called.
}

int 
main (int argc, char *argv[])
{
  const int MAX_DEPTH = argc == 1 ? 10 : atoi (argv[1]);

  if (argc > 2)
    ACE_Trace::set_nesting_indent (ACE_OS::atoi (argv[2]));

  ACE_Trace _ ("int main (int argc, char *argv[])", __LINE__, __FILE__);

  // The following won't work on MVS OpenEdition...
  ACE_Sig_Action sig1 ((ACE_SignalHandler) ACE_Trace::start_tracing, SIGUSR1);
  ACE_Sig_Action sig2 ((ACE_SignalHandler) ACE_Trace::stop_tracing, SIGUSR2);

#if defined (ACE_MT_SAFE)
  int n_threads = argc > 3 ? ACE_OS::atoi (argv[3]) : 4;

  if (ACE_Thread::spawn_n (n_threads, ACE_THR_FUNC (foo), 
			   (void *) MAX_DEPTH, 
			   THR_BOUND | THR_DETACHED) != n_threads)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn_n"), -1);
  ACE_OS::thr_exit (0);
#else
  for (;;)
    foo (MAX_DEPTH);
#endif /* ACE_MT_SAFE */

  // Destructor automatically called.
  return 0;
}