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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
// $Id: guard_test.cpp 91670 2010-09-08 18:02:26Z johnnyw $
#define ACE_BUILD_SVC_DLL
#include "ace/Guard_T.h"
#include "ace/Log_Msg.h"
#include "Performance_Test_Options.h"
#include "Benchmark_Performance.h"
#if defined (ACE_HAS_THREADS)
class ACE_Svc_Export Guard_Test : public Benchmark_Performance
{
public:
enum
{ // svc.conf options
TEST_ACE_GUARD, // -g
TEST_ACE_THREAD_MUTEX_GUARD // -t
};
virtual int svc (void);
virtual int init (int, ACE_TCHAR *[]);
void test_guard (int);
#if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
void test_thread_guard (int);
#endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
private:
static int guard_type_;
static ACE_Thread_Mutex mutex_;
};
int Guard_Test::guard_type_ = Guard_Test::TEST_ACE_GUARD;
ACE_Thread_Mutex Guard_Test::mutex_;
int
Guard_Test::init (int argc, ACE_TCHAR *argv[])
{
//FUZZ: disable check_for_lack_ACE_OS
ACE_Get_Opt getopt (argc, argv, ACE_TEXT("gt"));
int c;
while ((c = getopt()) != -1)
{
//FUZZ: enable check_for_lack_ACE_OS
switch (c)
{
#if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
case 't':
Guard_Test::guard_type_ = Guard_Test::TEST_ACE_THREAD_MUTEX_GUARD;
break;
#endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
case 'g':
Guard_Test::guard_type_ = Guard_Test::TEST_ACE_GUARD;
break;
default:
ACE_ERROR_RETURN ((LM_ERROR,
"Invalid option\n"), -1);
}
}
return 0;
}
int
Guard_Test::svc (void)
{
// Extract out the unique thread-specific value to be used as an
// index...
int ni = this->thr_id ();
synch_count = 2;
switch (Guard_Test::guard_type_)
{
case Guard_Test::TEST_ACE_GUARD:
this->test_guard (ni);
break;
#if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
case Guard_Test::TEST_ACE_THREAD_MUTEX_GUARD:
this->test_thread_guard (ni);
break;
#endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
default:
return -1;
}
return 0;
}
void
Guard_Test::test_guard (int ni)
{
while (!this->done ())
{
{
ACE_GUARD (ACE_Thread_Mutex, _ace_mon, Guard_Test::mutex_);
performance_test_options.thr_work_count[ni]++;
buffer++;
}
}
}
#if defined (ACE_USES_OBSOLETE_GUARD_CLASSES)
# define ACE_THREAD_GUARD(OBJ,LOCK) \
ACE_Thread_Mutex_Guard OBJ (LOCK); \
if (OBJ.locked () == 0) return;
void
Guard_Test::test_thread_guard (int ni)
{
while (!this->done ())
{
{
ACE_THREAD_GUARD (_ace_mon, Guard_Test::mutex_);
performance_test_options.thr_work_count[ni]++;
buffer++;
}
}
}
#endif /* ACE_USES_OBSOLETE_GUARD_CLASSES */
ACE_SVC_FACTORY_DECLARE (Guard_Test)
ACE_SVC_FACTORY_DEFINE (Guard_Test)
// ACE_Service_Object_Type mut (&mutex_test, "Guard_Test");
#endif /* ACE_HAS_THREADS */
|