summaryrefslogtreecommitdiff
path: root/ACE/performance-tests/Synch-Benchmarks/Synch_Lib/Benchmark_Base.h
blob: 7023dfccffd9844bd081bb83706dbfd3bf55ebe3 (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
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
/* -*- C++ -*- */
/* Defines the base class used to dynamically link in the benchmark tests */

#ifndef ACE_BENCHMARK_BASE_H
# define ACE_BENCHMARK_BASE_H

# include "ace/Service_Config.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

# include "ace/Service_Repository.h"
# include "ace/Service_Types.h"
# include "ace/Atomic_Op.h"
# include "export_mac.h"
# include "ace/TSS_T.h"

# if defined (ACE_HAS_THREADS)

#   if defined (ACE_HAS_PTHREADS) || defined (VXWORKS)

typedef ACE_Atomic_Op<ACE_Thread_Mutex, int> MT_INT;

class Thr_ID
  // TITLE
  //   A simple class that provides a thread-specific value in order
  //   to compensate for POSIX Pthreads.
  //
  // DESCRIPTION
  //   Pthreads are too lame to have a sensible scalar values for the
  //   thread id.   Therefore, we have to
  //   emulate this ourselves with this class (gag).
{
public:
  Thr_ID ();
  int thr_id ();
  void thr_id (int);

private:
  int thr_id_;
  static MT_INT thread_id_;
};
#   endif /* ACE_HAS_PTHREADS || VXWORKS */

class SYNCHLIB_Export Benchmark_Base : public ACE_Service_Object
{
  // = TITLE
  //     Base class for all benchmarking objects.
  //
  // = DESCRIPTION
  //     This class is the base class for all benchmarking
  //     classes.  Its major functionalities are to privide RTTI
  //     information and to define other common methods all
  //     benchmarking classes should support.
public:
  enum {
    BENCHMARK_BASE,
    METHOD,
    BASELINE,
    PERFORMANCE
  };

  int benchmark_type ();
  // RTTI information of this module.

  int thr_id ();
  // Returns our thread id;

protected:
  Benchmark_Base (int type = BENCHMARK_BASE);
  // Default ctor.

  int benchmark_type_;
  // Store the RTTI info of this module.

#   if defined (ACE_HAS_PTHREADS) || defined (VXWORKS)
  ACE_TSS <Thr_ID> id_;
  // Keeps track of our "virtual" thread id...
#   endif /* ACE_HAS_PTHREADS || VXWORKS */
};

class SYNCHLIB_Export Benchmark_Method_Base : public Benchmark_Base
{
  // = TITLE
  //     This class identifies itself as Benmarking Method class.
  //     It defines a method as of how the test is setup and measured.
public:
  int exec (ACE_Service_Repository_Iterator *sri);
  // Run the test and advanced the service repository iterator

  virtual int pre_run_test (Benchmark_Base *bp) = 0;
  // Before running the real test.  Subclasses implement this method
  // to dictate how the test is performed.

  virtual int run_test () = 0;
  // Run the real test.  Subclasses implement this method to
  // dictate how the test is performed.

  virtual int post_run_test () = 0;
  // After running the real test.  Subclasses implement this method to
  // dictate how the test is performed.

  virtual int valid_test_object (Benchmark_Base *) = 0;
  // Check if we got a valid test to perform.

protected:
  Benchmark_Method_Base ();
};

# endif /* ACE_HAS_THREADS */
#endif /* ACE_BENCHMARK_BASE_H */