Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / examples / Kokyu_dsrt_schedulers / mif_example / test_i.cpp
blobebe9a514d1b8693e126b456fc17ce23d9112ad1a
1 #include "test_i.h"
2 #include "ace/High_Res_Timer.h"
3 #include "ace/Task.h"
4 #include "ace/ACE.h"
5 #include "tao/debug.h"
6 #include "ace/Countdown_Time.h"
8 #if !defined(__ACE_INLINE__)
9 #include "test_i.inl"
10 #endif /* __ACE_INLINE__ */
12 CORBA::Long
13 Simple_Server_i::test_method (CORBA::Long exec_duration)
15 ACE_hthread_t thr_handle;
16 ACE_Thread::self (thr_handle);
17 int prio;
18 int guid;
19 RTScheduling::Current::IdType_var id = this->current_->id ();
21 ACE_OS::memcpy (&guid,
22 id->get_buffer (),
23 sizeof (id->length ()));
25 ACE_High_Res_Timer timer;
26 ACE_Time_Value elapsed_time;
28 ACE_DEBUG ((LM_DEBUG, "Request in thread %t\n"));
30 if (ACE_Thread::getprio (thr_handle, prio) == -1)
32 if (errno == ENOTSUP)
34 ACE_DEBUG((LM_DEBUG,
35 ACE_TEXT ("getprio not supported on this platform\n")));
36 return 0;
39 ACE_ERROR_RETURN ((LM_ERROR,
40 ACE_TEXT ("%p\n"),
41 ACE_TEXT ("getprio failed")),
42 -1);
45 ACE_DEBUG ((LM_DEBUG,
46 "Request in thread %t, prio = %d,"
47 "exec duration = %u\n", prio, exec_duration));
49 static CORBA::ULong prime_number = 9619899;
51 ACE_Time_Value compute_count_down_time (exec_duration, 0);
52 ACE_Countdown_Time compute_count_down (&compute_count_down_time);
54 //Applicable only for CV based implementations
55 //yield every 1 sec
56 ACE_Time_Value yield_interval (1,0);
58 ACE_Time_Value yield_count_down_time (yield_interval);
59 ACE_Countdown_Time yield_count_down (&yield_count_down_time);
61 timer.start ();
62 int j=0;
63 while (compute_count_down_time > ACE_Time_Value::zero)
65 ACE::is_prime (prime_number,
67 prime_number / 2);
69 ++j;
71 #ifdef KOKYU_DSRT_LOGGING
72 if (j%1000 == 0)
74 ACE_DEBUG ((LM_DEBUG,
75 "(%t|%T) loop # = %d, load = %usec\n", j, exec_duration));
77 #endif
78 if (j%1000 == 0)
80 ACE_Time_Value run_time = ACE_OS::gettimeofday ();
81 task_stats_.sample (run_time.msec (), guid);
84 compute_count_down.update ();
86 if (enable_yield_)
88 yield_count_down.update ();
89 if (yield_count_down_time <= ACE_Time_Value::zero)
91 CORBA::Policy_var sched_param_policy =
92 current_->scheduling_parameter();
94 const char * name = 0;
96 CORBA::Policy_ptr implicit_sched_param = 0;
97 current_->update_scheduling_segment (name,
98 sched_param_policy.in (),
99 implicit_sched_param);
100 yield_count_down_time = yield_interval;
101 yield_count_down.start ();
106 timer.stop ();
107 timer.elapsed_time (elapsed_time);
109 ACE_DEBUG ((LM_DEBUG,
110 "Request processing in thread %t done, "
111 "prio = %d, load = %d, elapsed time = %umsec\n",
112 prio, exec_duration, elapsed_time.msec () ));
114 return exec_duration;
117 void
118 Simple_Server_i::shutdown (void)
120 ACE_DEBUG ((LM_DEBUG, "shutdown request from client\n"));
121 this->orb_->shutdown (0);