Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / performance-tests / Synch-Benchmarks / Perf_Test / guard_test.cpp
blob29427e1abba837e13a9805ed2ccae26e393c14d3
1 #define ACE_BUILD_SVC_DLL
2 #include "ace/Guard_T.h"
3 #include "ace/Log_Msg.h"
4 #include "Performance_Test_Options.h"
5 #include "Benchmark_Performance.h"
7 #if defined (ACE_HAS_THREADS)
9 class ACE_Svc_Export Guard_Test : public Benchmark_Performance
11 public:
12 enum
13 { // svc.conf options
14 TEST_ACE_GUARD, // -g
15 TEST_ACE_THREAD_MUTEX_GUARD // -t
18 virtual int svc ();
19 virtual int init (int, ACE_TCHAR *[]);
21 void test_guard (int);
22 #if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
23 void test_thread_guard (int);
24 #endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
25 private:
26 static int guard_type_;
27 static ACE_Thread_Mutex mutex_;
30 int Guard_Test::guard_type_ = Guard_Test::TEST_ACE_GUARD;
31 ACE_Thread_Mutex Guard_Test::mutex_;
33 int
34 Guard_Test::init (int argc, ACE_TCHAR *argv[])
36 //FUZZ: disable check_for_lack_ACE_OS
37 ACE_Get_Opt getopt (argc, argv, ACE_TEXT("gt"));
38 int c;
40 while ((c = getopt()) != -1)
42 //FUZZ: enable check_for_lack_ACE_OS
43 switch (c)
45 #if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
46 case 't':
47 Guard_Test::guard_type_ = Guard_Test::TEST_ACE_THREAD_MUTEX_GUARD;
48 break;
49 #endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
50 case 'g':
51 Guard_Test::guard_type_ = Guard_Test::TEST_ACE_GUARD;
52 break;
53 default:
54 ACE_ERROR_RETURN ((LM_ERROR,
55 "Invalid option\n"), -1);
58 return 0;
61 int
62 Guard_Test::svc ()
64 // Extract out the unique thread-specific value to be used as an
65 // index...
66 int ni = this->thr_id ();
67 synch_count = 2;
69 switch (Guard_Test::guard_type_)
71 case Guard_Test::TEST_ACE_GUARD:
72 this->test_guard (ni);
73 break;
74 #if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
75 case Guard_Test::TEST_ACE_THREAD_MUTEX_GUARD:
76 this->test_thread_guard (ni);
77 break;
78 #endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
79 default:
80 return -1;
82 return 0;
85 void
86 Guard_Test::test_guard (int ni)
88 while (!this->done ())
91 ACE_GUARD (ACE_Thread_Mutex, _ace_mon, Guard_Test::mutex_);
93 performance_test_options.thr_work_count[ni]++;
94 buffer++;
99 #if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
100 # define ACE_THREAD_GUARD(OBJ,LOCK) \
101 ACE_Thread_Mutex_Guard OBJ (LOCK); \
102 if (OBJ.locked () == 0) return;
104 void
105 Guard_Test::test_thread_guard (int ni)
107 while (!this->done ())
110 ACE_THREAD_GUARD (_ace_mon, Guard_Test::mutex_);
112 performance_test_options.thr_work_count[ni]++;
113 buffer++;
117 #endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
118 ACE_SVC_FACTORY_DECLARE (Guard_Test)
119 ACE_SVC_FACTORY_DEFINE (Guard_Test)
121 // ACE_Service_Object_Type mut (&mutex_test, "Guard_Test");
122 #endif /* ACE_HAS_THREADS */