Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / performance-tests / Latency / Collocation / Collocated_Test.cpp
blobab5360f499de292a5961a74230355560b9a02762
1 #include "Server_Task.h"
2 #include "Client_Task.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Sched_Params.h"
5 #include "ace/OS_NS_errno.h"
6 #include "ace/Manual_Event.h"
8 #include "tao/Strategies/advanced_resource.h"
10 int niterations = 250000;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:n:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'n':
22 niterations = ACE_OS::atoi (get_opts.opt_arg ());
23 break;
25 default:
26 // This is a hack but that is okay!
27 return 0;
29 // Indicates successful parsing of the command line
30 return 0;
33 void
34 set_priority()
36 int priority =
37 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
38 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
39 priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
40 priority);
41 // Enable FIFO scheduling
42 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
43 priority,
44 ACE_SCOPE_PROCESS)) != 0)
46 if (ACE_OS::last_error () == EPERM)
48 ACE_DEBUG ((LM_DEBUG,
49 "server (%P|%t): user is not superuser, "
50 "test runs in time-shared class\n"));
52 else
53 ACE_ERROR ((LM_ERROR,
54 "server (%P|%t): sched_params failed\n"));
58 int
59 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
61 //Use Real-time Scheduling class if possible
62 set_priority();
64 try
66 CORBA::ORB_var sorb =
67 CORBA::ORB_init (argc, argv);
69 if (parse_args (argc,argv) == -1)
70 return -1;
72 ACE_Manual_Event wait_for_event;
74 Server_Task server_task (sorb.in (),
75 wait_for_event,
76 ACE_Thread_Manager::instance ());
78 if (server_task.activate (THR_NEW_LWP | THR_JOINABLE,
80 1) == -1)
82 ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
85 // Wait for the server thread to do some processing
86 wait_for_event.wait ();
88 // Obtain the object reference
89 Test::Roundtrip_var reference = server_task.get_reference ();
91 Client_Task client_task (reference.in (),
92 niterations,
93 ACE_Thread_Manager::instance ());
95 if (client_task.activate (THR_NEW_LWP | THR_JOINABLE,
97 1) == -1)
99 ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
102 ACE_Thread_Manager::instance ()->wait ();
104 catch (const CORBA::Exception&)
106 // Ignore exceptions..
108 return 0;