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
15 TEST_ACE_THREAD_MUTEX_GUARD
// -t
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 */
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_
;
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"));
40 while ((c
= getopt()) != -1)
42 //FUZZ: enable check_for_lack_ACE_OS
45 #if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
47 Guard_Test::guard_type_
= Guard_Test::TEST_ACE_THREAD_MUTEX_GUARD
;
49 #endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
51 Guard_Test::guard_type_
= Guard_Test::TEST_ACE_GUARD
;
54 ACE_ERROR_RETURN ((LM_ERROR
,
55 "Invalid option\n"), -1);
64 // Extract out the unique thread-specific value to be used as an
66 int ni
= this->thr_id ();
69 switch (Guard_Test::guard_type_
)
71 case Guard_Test::TEST_ACE_GUARD
:
72 this->test_guard (ni
);
74 #if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
75 case Guard_Test::TEST_ACE_THREAD_MUTEX_GUARD
:
76 this->test_thread_guard (ni
);
78 #endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
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
]++;
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;
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
]++;
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 */