Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / performance-tests / RTEvent / lib / Send_Task.cpp
blob5461015c222328ac54beb7f17d50cd18354eef9f
1 /**
2 * @file Send_Task.cpp
4 * @author Carlos O'Ryan <coryan@uci.edu>
5 */
7 #include "Send_Task.h"
9 #include "orbsvcs/Time_Utilities.h"
11 #include "ace/Barrier.h"
12 #include "ace/OS_NS_unistd.h"
14 Send_Task::Send_Task ()
15 : iterations_ (0)
16 , period_in_usecs_ (0)
17 , startup_sleep_ (0)
18 , event_type_ (0)
19 , event_source_ (0)
20 , barrier_ (0)
21 , stop_ (0)
25 void
26 Send_Task::init (int iterations,
27 int period_in_usecs,
28 int startup_sleep,
29 int event_type,
30 int event_source,
31 Supplier *supplier,
32 ACE_Barrier *barrier)
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;
39 this->supplier_ =
40 PortableServer::Servant_var<Supplier>::_duplicate (supplier);
41 this->barrier_ = barrier;
44 void
45 Send_Task::stop ()
47 ACE_GUARD (TAO_SYNCH_MUTEX, ace_mon, this->mutex_);
48 this->stop_ = 1;
51 int
52 Send_Task::svc ()
54 if (this->barrier_ == 0)
55 return -1;
57 this->barrier_->wait ();
59 ACE_Time_Value startup (0, this->startup_sleep_);
60 ACE_OS::sleep (startup);
62 ACE_DEBUG ((LM_DEBUG,
63 "(%P|%t) - Thread started, "
64 "iterations = %d, period = %d, event_type = %d\n",
65 this->iterations_, this->period_in_usecs_,
66 this->event_type_));
69 int start_i = 0;
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.
75 start_i = 1;
78 RtecEventComm::EventSet event (1);
79 event.length (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)
88 ACE_DEBUG ((LM_DEBUG,
89 "(%P|%t) - Thread has sent %d messages @ %T\n",
90 i + 1));
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);
97 if (this->stop_ != 0)
99 ACE_DEBUG ((LM_DEBUG,
100 "(%P|%t) - Thread has been stopped\n"));
101 return 0;
104 ACE_hrtime_t creation = ACE_OS::gethrtime ();
105 ORBSVCS_Time::hrtime_to_TimeT (event[0].header.creation_time,
106 creation);
109 // push one event...
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"));
119 return 0;