1 // This test program illustrates the performance of ACE_GUARD
3 #include "ace/Log_Msg.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/Profile_Timer.h"
6 #include "ace/Thread_Mutex.h"
7 #include "ace/Guard_T.h"
9 #if defined (ACE_HAS_THREADS)
11 static const int DEFAULT_ITERATIONS
= 100000000;
20 ACE_Thread_Mutex lock_
;
21 typedef void (*guard_func
)(void);
22 int test_type
= TEST_GUARD
;
27 ACE_GUARD (ACE_Thread_Mutex
, _ace_mon
, lock_
);
31 // FUZZ: disable check_for_ACE_Guard
32 const char *test_name
[TEST_END
] = { "ACE_Guard" };
33 // FUZZ: enable check_for_ACE_Guard
35 guard_func test_function
=guard
;
38 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
40 ACE_Profile_Timer timer
;
42 ACE_Get_Opt
get_opt (argc
, argv
, ACE_TEXT("gn:"));
44 int iterations
= DEFAULT_ITERATIONS
;
47 while ((c
= get_opt()) != -1)
51 test_type
= TEST_GUARD
;
52 test_function
= guard
;
55 iterations
= ACE_OS::atoi (get_opt
.opt_arg ());
58 ACE_ERROR_RETURN ((LM_ERROR
,
59 "Invalid option\n"), -1);
62 ACE_DEBUG ((LM_DEBUG
, "%s for iterations = %d\n", test_name
[test_type
], iterations
));
66 // Test the thread mutex (which doesn't use inheritance or dynamic
69 for (i
= 0; i
< iterations
; i
++)
74 ACE_Profile_Timer::ACE_Elapsed_Time et
;
76 timer
.elapsed_time (et
);
78 ACE_DEBUG ((LM_DEBUG
, "Thread_Mutex\n"));
79 ACE_DEBUG ((LM_DEBUG
, "real time = %f secs, user time = %f secs, system time = %f secs\n",
80 et
.real_time
, et
.user_time
, et
.system_time
));
82 ACE_DEBUG ((LM_DEBUG
, "time per call = %f usecs\n",
83 (et
.real_time
/ double (iterations
)) * 1000000));
89 ACE_TMAIN(int, ACE_TCHAR
*[])
91 ACE_ERROR ((LM_ERROR
, "threads not supported on this platform\n"));
94 #endif /* ACE_HAS_THREADS */