summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/util/CcSynch.h
blob: aa346c5b37a5e8d272b537429eeb1c6d15fee973 (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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/util/CcSynch.h $                     */
/*                                                                        */
/* IBM CONFIDENTIAL                                                       */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 1995,2013              */
/*                                                                        */
/* p1                                                                     */
/*                                                                        */
/* Object Code Only (OCO) source materials                                */
/* Licensed Internal Code Source Materials                                */
/* IBM HostBoot Licensed Internal Code                                    */
/*                                                                        */
/* The source code for this program is not published or otherwise         */
/* divested of its trade secrets, irrespective of what has been           */
/* deposited with the U.S. Copyright Office.                              */
/*                                                                        */
/* Origin: 30                                                             */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

#ifndef CcSynch_h
#define CcSynch_h

// Class Specification *************************************************
//
// Class name:   CcSynch
// Parent class: None.
//
// Summary: This class is used as a synchronization mechanism.  A
//          static step counter is maintained and incremented via the
//          static member function Advance().  An internal step counter
//          is also maintained.  The member function IsCurrent()
//          compares the two values to indicate if this instance is
//          "in synch".  Calling the IsCurrent() functiona also updates
//          the internal counter to the static counter.
//
//          The primary use is to ensure that an operation is performed
//          only once over a given time interval.  The time interval
//          is controlled by successive calls to Advance().  If an
//          instance is not current, then the operation is performed
//          and the instance will then be current.
//
//          The parameterized type STEP_TYPE is used for the type of
//          the counters.  This type should be selected according to
//          the necessary granularity.  For example, an 8 bit integer
//          value allows for 256 unique counter values.
//
//          The parameterized type ID is used to diferentiate an
//          instantiation of this tmeplate from other instantiations.
//          This class relies on a unique static data member which is
//          generated for each unique instantiation.
//
// Cardinality: N
//
// Performance/Implementation:
//   Space Complexity: Constant
//   Time Complexity:  Constant
//
// Usage Examples:
//
// struct mytype {};
//
// void foo(CcSynch<int, mytpe> & synch)
//   {
//   synch.Advance();
//
//   if(synch.IsCurrent())
//     {
//     // Operation is performed
//     }
//
//   if(synch.IsCurrent())
//     {
//     // Operation is not performed
//     }
//   }
//
//
// End Class Specification *********************************************

// Includes

namespace PRDF
{

template <class STEP_TYPE, class ID>
class CcSynch
  {
  public:    // public member functions

     typedef STEP_TYPE StepType;

     enum
       {
       STATIC_INITIAL_VALUE = 1,
       INSTANCE_INITIAL_VALUE = 0
       };

     static void Advance(void);
  // Function Specification ********************************************
  //
  // Purpose:      Advances the static data member step.
  // Parameters:   None.
  // Returns:      No value returned.
  // Requirements: None.
  // Promises:     Static data member step will be incremented.
  // Exceptions:   None.
  // Concurrency:  Reentrant.
  //
  // End Function Specification ****************************************

   CcSynch(void);
  // Function Specification ********************************************
  //
  // Purpose:      Initialization
  // Parameters:   No parameters
  // Returns:      No value returned
  // Requirements: None.
  // Promises:     All data members are initialized.
  // Exceptions:   None.
  // Concurrency:  N/A
  //
  // End Function Specification ****************************************

  //  CcSynch(const CcSynch & e);
  // Function Specification ********************************************
  //
  // Purpose:      Copy
  // Parameters:   e: Reference to instance to copy
  // Returns:      No value returned.
  // Requirements: None.
  // Promises:     All data members are initialized.
  // Exceptions:   None.
  // Concurrency:  N/A.
  // Notes:  The compiler generated copy constructor is sufficient.
  //
  // End Function Specification ****************************************

  //  ~CcSynch(void);
  // Function Specification ********************************************
  //
  // Purpose:      Destruction
  // Parameters:   None.
  // Returns:      No value returned
  // Requirements: None.
  // Promises:     None.
  // Exceptions:   None.
  // Concurrency:  N/A
  // Notes:  The compiler generated default destructor is sufficient.
  //
  // End Function Specification ****************************************

  //  CcSynch & operator=(const CcSynch & e);
  // Function Specification ********************************************
  //
  // Purpose:      Assigment
  // Parameters:   e: Reference to instance to assign from
  // Returns:      Reference to this instance
  // Requirements: None.
  // Promises:     All data members will be assigned.
  // Exceptions:   N/A.
  // Concurrency:  N/A.
  // Notes:  The compiler generated default assignment operator is
  //         sufficient.
  //
  // End Function Specification ****************************************

    bool IsCurrent(void);
  // Function Specification ********************************************
  //
  // Purpose:      Determines if myStep is current with step.
  // Parameters:   None.
  // Returns:      TRUE if myStep is current with step. Otherewise,
  //               FALSE.
  // Requirements: None.
  // Promises:     myStep will be current with step.
  // Exceptions:   None..
  // Concurrency:  Reenetrant.
  //
  // End Function Specification ****************************************

  private:

    static StepType                step;

    StepType                       myStep;
  };

} // end namespace PRDF

#include "CcSynch.inl"

#endif

OpenPOWER on IntegriCloud