ACE+TAO-7_0_8
[ACE_TAO.git] / ACE / tests / Upgradable_RW_Test.h
blob24ae64d5e30b31240859585d0cb336f3c233bb81
2 //=============================================================================
3 /**
4 * @file Upgradable_RW_Test.h
6 * This class gets its own header file to work around AIX C++
7 * compiler "features" related to template instantiation... It is
8 * only used by Upgradable_RW_Test.cpp.
10 * @author Michael Kircher <mk1@cs.wustl.edu>
12 //=============================================================================
15 #ifndef ACE_TESTS_UPGRADABLE_RW_TEST_H
16 #define ACE_TESTS_UPGRADABLE_RW_TEST_H
18 #include "test_config.h"
19 #include "ace/Barrier.h"
21 #if !defined (ACE_LACKS_PRAGMA_ONCE)
22 # pragma once
23 #endif /* ACE_LACKS_PRAGMA_ONCE */
25 #include "ace/Task.h"
26 #include "ace/Thread.h"
27 #include "ace/Thread_Manager.h"
28 #include "ace/Get_Opt.h"
29 #include "ace/SString.h"
30 #include "ace/Profile_Timer.h"
32 class Element;
34 /**
35 * @class Element
37 * @brief The members for the double linked list.
39 class Element
41 friend class ACE_Double_Linked_List<Element>;
42 friend class ACE_Double_Linked_List_Iterator_Base<Element>;
43 friend class ACE_Double_Linked_List_Iterator<Element>;
44 friend class ACE_Double_Linked_List_Reverse_Iterator<Element>;
46 public:
47 Element (ACE_CString *item = 0,
48 Element *p = 0,
49 Element *n = 0)
50 : prev_ (p),
51 next_(n),
52 item_(item)
56 ACE_CString *value (void)
58 return this->item_;
61 private:
62 Element *prev_;
63 Element *next_;
64 ACE_CString *item_;
67 typedef ACE_Double_Linked_List<Element> Linked_List;
69 /**
70 * @class Time_Calculation
72 * @brief class to do time calculations thread safe
74 class Time_Calculation
76 public:
77 Time_Calculation (void)
78 : reported_times_ (0)
80 times_.real_time = 0;
81 times_.user_time = 0;
82 times_.system_time = 0;
85 /// take the time of the thread and add it to
86 void report_time (ACE_Profile_Timer::ACE_Elapsed_Time &elapsed_time);
88 void print_stats (void);
90 private:
91 /// add the times incrementally
92 ACE_Profile_Timer::ACE_Elapsed_Time times_;
94 /// protect the time
95 ACE_SYNCH_MUTEX mutex_;
97 /// count how many threads gave me the elapsed_time
98 unsigned int reported_times_;
102 * @class Reader_Task
104 * @brief A Task for readers
106 class Reader_Task : public ACE_Task_Base
108 public:
109 Reader_Task (Time_Calculation &time_Calculation,
110 ACE_Barrier &barrier)
111 : time_Calculation_ (time_Calculation),
112 barrier_(barrier)
116 virtual int svc ();
118 private:
119 /// keep a reference to the time calculation class
120 Time_Calculation &time_Calculation_;
122 /// keep this reference for the barrier, in order
123 /// to allow a "nice" start
124 ACE_Barrier &barrier_;
128 * @class Writer_Task
130 * @brief A Task for wirters.
132 class Writer_Task : public ACE_Task_Base
134 public:
135 Writer_Task (Time_Calculation &time_Calculation,
136 ACE_Barrier &barrier)
137 : time_Calculation_ (time_Calculation),
138 barrier_(barrier)
142 virtual int svc ();
144 private:
145 /// keep a reference to the time calculation class
146 Time_Calculation &time_Calculation_;
148 /// keep this reference for the barrier, in order
149 /// to allow a "nice" start
150 ACE_Barrier &barrier_;
153 #endif /* ACE_TESTS_UPGRADABLE_RW_TEST_H */