4 * @author Carlos O'Ryan <coryan@uci.edu>
9 #include "orbsvcs/Time_Utilities.h"
11 #include "ace/Barrier.h"
12 #include "ace/OS_NS_unistd.h"
14 Send_Task::Send_Task ()
16 , period_in_usecs_ (0)
26 Send_Task::init (int iterations
,
34 this->iterations_
= iterations
;
35 this->period_in_usecs_
= period_in_usecs
;
36 this->startup_sleep_
= startup_sleep
;
37 this->event_type_
= event_type
;
38 this->event_source_
= event_source
;
40 PortableServer::Servant_var
<Supplier
>::_duplicate (supplier
);
41 this->barrier_
= barrier
;
47 ACE_GUARD (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
);
54 if (this->barrier_
== 0)
57 this->barrier_
->wait ();
59 ACE_Time_Value
startup (0, this->startup_sleep_
);
60 ACE_OS::sleep (startup
);
63 "(%P|%t) - Thread started, "
64 "iterations = %d, period = %d, event_type = %d\n",
65 this->iterations_
, this->period_in_usecs_
,
70 if (this->iterations_
== 0)
72 // Starting from 1 results in an infinite loop (well, so long
73 // that I call it infinite), which is exactly what we want, kind
74 // of hackish, oh well.
78 RtecEventComm::EventSet
event (1);
80 event
[0].header
.type
= this->event_type_
;
81 event
[0].header
.source
= this->event_source_
;
82 event
[0].header
.ttl
= 1;
84 for (int i
= start_i
; i
!= this->iterations_
; ++i
)
86 if ((i
+ 1) % 1000 == 0)
89 "(%P|%t) - Thread has sent %d messages @ %T\n",
93 ACE_Time_Value
period (0, this->period_in_usecs_
);
94 ACE_OS::sleep (period
);
96 ACE_GUARD_RETURN (TAO_SYNCH_MUTEX
, ace_mon
, this->mutex_
, -1);
100 "(%P|%t) - Thread has been stopped\n"));
104 ACE_hrtime_t creation
= ACE_OS::gethrtime ();
105 ORBSVCS_Time::hrtime_to_TimeT (event
[0].header
.creation_time
,
110 this->supplier_
->push (event
);
112 catch (const CORBA::Exception
& ex
)
114 ex
._tao_print_exception ("Caught exception:");
117 ACE_DEBUG ((LM_DEBUG
,
118 "(%P|%t) - Thread finished\n"));