diff options
21 files changed, 1019 insertions, 34 deletions
diff --git a/ChangeLog b/ChangeLog index e756dc55d4c..8c21327de8d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,59 @@ +Wed Dec 21 16:19:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl> + + * ace/CDR_Base.cpp: + * ace/CDR_Stream.cpp: + Fixed 64bit conversion warnings from int to long + + * ace/config-vxworks6.1.h: + VxWorks 6.1 defines MAP as CPU type, if it is defined, + undef it so that we can use MAP as typedef throughout ACE/TAO + + * ace/Configuration_Import_Export.cpp: + Fixed 64bit conversion warning from u_int to u_long + + * ace/Malloc_T.cpp: + Added some checks for valid pointers before calling memset. + Thanks to Oh Yoon Sik <boom at estsoft dot com> for reporting + this. + + * ace/OS_NS_sys_stat.inl (mkdir): + Replaced c-style cast with C++ cast + + * ace/Basic_Types.h: + Removed ptr_arith_t, it is not used anymore + + * ace/OS_NS_time.cpp: + Fixed the month calculation for WinCE. + Thanks to Oh Yoon Sik <boom at estsoft dot com> for reporting + this. + + * ace/WIN32_Proactor.cpp: + The code for ACE_WIN64 should also be used for ACE_WIN32 so + zapped the ACE_WIN32 specific case + + * include/makeinclude/platform_linux_icc.GNU: + When optimizations are disabled pass -O2 to the compiler. Always + disable the floating point optimizations to get correct floats + in the IDL compiler. + + * examples/Reactor/Misc/test_demuxing.cpp: + Instead of an ACE_ASSERT, use ACE_ERROR_RETURN + + * tests/Basic_Types_Test.cpp: + Use ptr_diff_t instead of ptr_arith_t + + * tests/Buffer_Stream_Test.cpp: + Initialise pointers with 0 + + * etc/tao.doxygen: + Expand all emulated exception macros, that will improve our + documentation. I will recheck doxygen later and if things look + correct I will apply the same change to the other configuration + files. + + * bin/MakeProjectCreator/modules/BorlandProjectCreator.pm: + Updated because of changes to MPC. + Tue Dec 20 08:02:03 2005 Simon McQueen <sm@prismtech.com> * ACE version 5.4.8 released. diff --git a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.h b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.h index 66031d7df6e..f75dbedbc1a 100644 --- a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.h +++ b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.h @@ -60,7 +60,7 @@ namespace TAO public: /// Constructor. - TP_Strategy(unsigned int num_threads = 1, + TP_Strategy(unsigned long num_threads = 1, bool serialize_servants = true); /// Virtual Destructor. @@ -186,7 +186,7 @@ namespace TAO TP_Task task_; /// The number of worker threads to use for the task. - unsigned int num_threads_; + unsigned long num_threads_; /// The "serialize servants" flag. bool serialize_servants_; diff --git a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.inl b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.inl index a0d9ef37fad..d0c3e95938b 100644 --- a/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.inl +++ b/TAO/tao/CSD_ThreadPool/CSD_TP_Strategy.inl @@ -5,7 +5,7 @@ TAO_BEGIN_VERSIONED_NAMESPACE_DECL ACE_INLINE -TAO::CSD::TP_Strategy::TP_Strategy(unsigned int num_threads, +TAO::CSD::TP_Strategy::TP_Strategy(unsigned long num_threads, bool serialize_servants) : num_threads_(num_threads), serialize_servants_(serialize_servants) diff --git a/TAO/tao/Leader_Follower.cpp b/TAO/tao/Leader_Follower.cpp index bb4dbf966ce..d494f48f7b3 100644 --- a/TAO/tao/Leader_Follower.cpp +++ b/TAO/tao/Leader_Follower.cpp @@ -160,7 +160,7 @@ TAO_Leader_Follower::set_client_thread (void) // re-enable it if we want to receive any replys... this->orb_core_->reactor ()->reset_reactor_event_loop (); } - this->clients_++; + ++this->clients_; } void @@ -175,7 +175,7 @@ TAO_Leader_Follower::reset_client_thread (void) ++this->leaders_; } - this->clients_--; + --this->clients_; if (this->clients_ == 0 && this->orb_core_->has_shutdown ()) { diff --git a/TAO/tao/Object.cpp b/TAO/tao/Object.cpp index adb2c4f5c28..1f38e421ed8 100644 --- a/TAO/tao/Object.cpp +++ b/TAO/tao/Object.cpp @@ -846,7 +846,7 @@ CORBA::Object::tao_object_initialize (CORBA::Object *obj) CORBA::Boolean operator>> (TAO_InputCDR& cdr, CORBA::Object*& x) { - int lazy_strategy = 0; + bool lazy_strategy = false; TAO_ORB_Core *orb_core = cdr.orb_core (); if (orb_core == 0) @@ -863,7 +863,7 @@ operator>> (TAO_InputCDR& cdr, CORBA::Object*& x) { if (orb_core->resource_factory ()->resource_usage_strategy () == TAO_Resource_Factory::TAO_LAZY) - lazy_strategy = 1; + lazy_strategy = true; } if (!lazy_strategy) diff --git a/TAO/tao/RTPortableServer/RT_Servant_Dispatcher.cpp b/TAO/tao/RTPortableServer/RT_Servant_Dispatcher.cpp index 1fc1b8bcba0..21711bf9157 100644 --- a/TAO/tao/RTPortableServer/RT_Servant_Dispatcher.cpp +++ b/TAO/tao/RTPortableServer/RT_Servant_Dispatcher.cpp @@ -1,3 +1,4 @@ + #include "RT_Servant_Dispatcher.h" #if defined (TAO_HAS_CORBA_MESSAGING) && TAO_HAS_CORBA_MESSAGING != 0 @@ -83,7 +84,7 @@ TAO_RT_Servant_Dispatcher::pre_invoke_remote_request ( TAO_Protocols_Hooks *tph = poa.orb_core ().get_protocols_hooks (); - const char *priority_model; + const char *priority_model = 0; RTCORBA::Priority target_priority = TAO_INVALID_PRIORITY; // NOT_SPECIFIED PriorityModel processing. diff --git a/TAO/tests/IDL_Test/array.idl b/TAO/tests/IDL_Test/array.idl index a9b40470990..2ec2f9c01a4 100644 --- a/TAO/tests/IDL_Test/array.idl +++ b/TAO/tests/IDL_Test/array.idl @@ -9,7 +9,7 @@ // array.idl // // = DESCRIPTION -// This file contains examples of IDL code that has +// This file contains examples of IDL code that has // caused problems in the past for the TAO IDL // compiler. This test is to make sure the problems // stay fixed. @@ -40,16 +40,16 @@ typedef wrap outside_array[10]; // Once a problem with expressions in the brackets, // as well as the typedef'd/anonymous thing. -interface tdef +interface tdef { const short byteslen = 12; typedef octet Bytes[byteslen + 1]; - struct bytes_or_longs + struct bytes_or_longs { Bytes the_bytes; // typedef'd long Longs[byteslen]; // anonymous - }; + }; }; // To test that all the octet arrays build and link as @@ -61,7 +61,7 @@ module ABCModule octet rmtNodeId[22]; octet rmtDetails[22]; }; - + struct bbbBubBubBubBaby { octet rmtNodeId[22]; @@ -91,20 +91,22 @@ module string_array // Checks code generation for arrays and typedefs of arrays // when they are not declared globally or inside a module. -interface testdata +interface testdata { typedef char Arraychar[2]; typedef Arraychar ArrayDeChar; - struct struct2 + struct struct2 { Arraychar field_1; ArrayDeChar field_2; }; typedef sequence<Arraychar> ArraycharList; + typedef sequence<Arraychar,10> BdArraycharList; typedef sequence<ArrayDeChar> ArrayDeCharList; + typedef sequence<ArrayDeChar,10> BdArrayDeCharList; }; // Tests for explicit conversion of slice pointer to the @@ -146,6 +148,19 @@ module bug_2126 case TRUE: MyStruct second_union_struct_member; case FALSE: long wibble; }; + + typedef FirstUnion BdFirstUnionArray[2]; + + struct BdMyStruct + { + BdFirstUnionArray my_struct_foo; + }; + + union BdSecondUnion switch (boolean) + { + case TRUE: BdMyStruct second_union_struct_member; + case FALSE: long wibble; + }; }; diff --git a/TAO/tests/IDL_Test/interface.idl b/TAO/tests/IDL_Test/interface.idl index 28e428251be..dbfc9d8047d 100644 --- a/TAO/tests/IDL_Test/interface.idl +++ b/TAO/tests/IDL_Test/interface.idl @@ -9,7 +9,7 @@ // interface.idl // // = DESCRIPTION -// This file contains examples of IDL code that has +// This file contains examples of IDL code that has // caused problems in the past for the TAO IDL // compiler. This test is to make sure the problems // stay fixed. @@ -21,7 +21,7 @@ -// Used to be a problem in the get() and set() +// Used to be a problem in the get() and set() // generated code. interface Base @@ -38,7 +38,7 @@ interface Derived : Base // foo's scope. module foo_mod { - struct date + struct date { short month; }; @@ -78,11 +78,11 @@ typedef boolean Bool; interface later_user { - later op (in later inarg, + later op (in later inarg, inout later inoutarg, out later outarg); - + // Not a clash with the C++ keyword because they are case sensitive, // but the Arg_Traits<> specialization parameter (ACE_InputCDR::to_boolean) // needs the unaliased type name to work. @@ -102,7 +102,7 @@ interface later {}; // somewhere other than the scope where the // lookup starts. -interface Begin +interface Begin { typedef long Value; }; @@ -111,11 +111,11 @@ interface Middle : Begin { }; -interface End : Middle +interface End : Middle { }; -interface Client +interface Client { attribute End::Value v; }; @@ -137,31 +137,33 @@ module ParamMod { ParameterTester objref; }; - + typedef sequence<ParameterTester> object_seq_type; - + typedef ParameterTester object_array_type[5]; - struct object_struct_type + struct object_struct_type { octet o1; ParameterTester p1; - long l1; + long l1; }; - + union object_union_type switch (long) { case 0: string str; case 1: ParameterTester pt; }; - + object_seq_type parameter_tester_op ( in object_struct_type inarg, inout object_array_type inoutarg, out object_union_type outarg ) - raises (object_excep_type); + raises (object_excep_type); }; }; - +local interface testlocal +{ +}; diff --git a/TAO/tests/IDL_Test/sequence.idl b/TAO/tests/IDL_Test/sequence.idl index 9cbd802c9b4..9c3b32da80e 100644 --- a/TAO/tests/IDL_Test/sequence.idl +++ b/TAO/tests/IDL_Test/sequence.idl @@ -9,7 +9,7 @@ // sequence.idl // // = DESCRIPTION -// This file contains examples of IDL code that has +// This file contains examples of IDL code that has // caused problems in the past for the TAO IDL // compiler. This test is to make sure the problems // stay fixed. @@ -28,13 +28,19 @@ typedef sequence<CORBA::OctetSeq> OctetSeqSeq; // Bounded string elements of a sequence, // require the use of CORBA_Any::to_char. -interface seqTest +interface seqTest { typedef sequence< string<12> > dozens; void send_dozen (inout dozens bouquets); }; +local interface seqLocal +{ +}; + +typedef sequence<seqLocal> seqLocalSeq; + // Anonymous sequence members must be unique types even if the // sequence itself is not, so the member name has been // incorported into the sequence class name. #if !defined guards @@ -54,7 +60,7 @@ struct nestedSeqStruct }; // Tests deeply nested recursive type. -module Deployment +module Deployment { struct ComponentPackageDescription; diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/README b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/README new file mode 100644 index 00000000000..95b07c46c2c --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/README @@ -0,0 +1,10 @@ +$Id$ + +Description: +This is a simple test for a RT thread-pool server. It creates a +server process with multiple thread pools, POAs, and servants. The +test also spawns multiple clients for each servant. The servants with +multiple threads in their thread-pool respond faster than the servants +with a single thread thread-pool. + +See run_test.pl to see how to run this test.
\ No newline at end of file diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/RTCORBA_Dynamic_Thread_Pool.mpc b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/RTCORBA_Dynamic_Thread_Pool.mpc new file mode 100644 index 00000000000..ebf79370785 --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/RTCORBA_Dynamic_Thread_Pool.mpc @@ -0,0 +1,18 @@ +// -*- MPC -*- +// $Id$ + +project(*Server): strategies, rt_server, minimum_corba { + Source_Files { + test_i.cpp + server.cpp + } +} + +project(*Client): strategies, rt_client, minimum_corba { + after += *Server + Source_Files { + testC.cpp + client.cpp + } +} + diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/client.cpp b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/client.cpp new file mode 100644 index 00000000000..e28f1a27b90 --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/client.cpp @@ -0,0 +1,221 @@ +// $Id$ + +#include "ace/Get_Opt.h" +#include "testC.h" +#include "tao/RTCORBA/RTCORBA.h" +#include "tao/ORB_Core.h" +#include "ace/Task.h" +#include "ace/OS_NS_unistd.h" + #include "../check_supported_priorities.cpp" + +ACE_RCSID(Thread_Pool, client, "$Id$") + +const char *ior = "file://ior_1"; +int iterations = 6; +int shutdown_server = 0; +bool decreased = false; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "xk:i:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'x': + shutdown_server = 1; + break; + + case 'k': + ior = get_opts.opt_arg (); + break; + + case 'i': + iterations = ACE_OS::atoi (get_opts.opt_arg ()); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-k <ior> " + "-i <iterations> " + "-x [shutdown server] " + "\n", + argv [0]), + -1); + } + + // Indicates sucessful parsing of the command line + return 0; +} + +class Task : public ACE_Task_Base +{ +public: + + Task (ACE_Thread_Manager &thread_manager, + CORBA::ORB_ptr orb); + + int svc (void); + + CORBA::ORB_var orb_; + +}; + +Task::Task (ACE_Thread_Manager &thread_manager, + CORBA::ORB_ptr orb) + : ACE_Task_Base (&thread_manager), + orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +int +Task::svc (void) +{ + ACE_TRY_NEW_ENV + { + CORBA::Object_var object = + this->orb_->string_to_object (ior ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + test_var test = + test::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + pid_t pid = + ACE_OS::getpid (); + + CORBA::Long tc = 0; + + for (int i = 0; i != iterations; ++i) + { + CORBA::Long mtc = 0; + CORBA::Long r = + test->method (pid, + i, + mtc + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Each 2 iterations sleep 5 seconds + if (i % 2 == 0) + ACE_OS::sleep (5); + + ACE_ASSERT (r == i); + // Assert disappears on with optimizations on. + ACE_UNUSED_ARG (r); + + if (mtc > tc) + { + // Number of threads increased, so store this. + ACE_DEBUG ((LM_DEBUG, "Thread count increased to %d\n", mtc)); + tc = mtc; + } + else if (mtc < tc) + { + // Number of threads decreased! + ACE_DEBUG ((LM_DEBUG, "Thread count decreased to %d\n", mtc)); + decreased = true; + tc = mtc; + } + } + + ACE_OS::sleep (10); + + CORBA::Long end = 0; + CORBA::Long re = + test->method (pid, + 0, + end + ACE_ENV_ARG_PARAMETER); + + if (end != 0) + { + ACE_ERROR ((LM_ERROR, "Dynamic thread count should be 0, not %d\n", end)); + } + + if (shutdown_server) + { + test->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Exception caught:"); + return -1; + } + ACE_ENDTRY; + + return 0; +} + +int +main (int argc, char *argv[]) +{ + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + int result = + parse_args (argc, argv); + if (result != 0) + return result; + + // Thread Manager for managing task. + ACE_Thread_Manager thread_manager; + + // Create task. + Task task (thread_manager, + orb.in ()); + + // Task activation flags. + long flags = + THR_NEW_LWP | + THR_JOINABLE | + orb->orb_core ()->orb_params ()->thread_creation_flags (); + + // Activate task. + result = + task.activate (flags); + if (result == -1) + { + if (errno == EPERM) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot create thread with scheduling policy %s\n" + "because the user does not have the appropriate privileges, terminating program....\n" + "Check svc.conf options and/or run as root\n", + sched_policy_name (orb->orb_core ()->orb_params ()->ace_sched_policy ())), + 2); + } + else + // Unexpected error. + ACE_ASSERT (0); + } + + // Wait for task to exit. + result = + thread_manager.wait (); + ACE_ASSERT (result != -1); + + if (decreased == false) + { + ACE_ERROR_RETURN ((LM_ERROR, "ERROR: Number of threads didn't decrease\n"), -1); + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught"); + return -1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/continuous.conf b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/continuous.conf new file mode 100644 index 00000000000..41c1919a08a --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/continuous.conf @@ -0,0 +1,2 @@ +# Option for platforms where direct mapping doesn't work +static RT_ORB_Loader "-ORBPriorityMapping continuous -RTORBDynamicThreadIdleTimeout 1000000" diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/continuous.conf.xml b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/continuous.conf.xml new file mode 100644 index 00000000000..bbb864e64b0 --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/continuous.conf.xml @@ -0,0 +1,6 @@ +<?xml version='1.0'?> +<!-- Converted from continuous.conf by svcconf-convert.pl --> +<ACE_Svc_Conf> + <!-- Option for platforms where direct mapping doesn't work --> + <static id="RT_ORB_Loader" params="-ORBPriorityMapping continuous -RTORBDynamicThreadIdleTimeout 1000000"/> +</ACE_Svc_Conf> diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/run_test.pl b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/run_test.pl new file mode 100644 index 00000000000..2059c01b04f --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/run_test.pl @@ -0,0 +1,117 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib '../../../../bin'; +use PerlACE::Run_Test; + +$number_of_clients = 1; +$status = 0; +$continuous = ($^O eq 'hpux'); + +@configurations = + ( + { + file => "ior_3", + description => "Invoking methods on servant in second RT thread pool (with lanes)", + }, + ); + +for $test (@configurations) +{ + unlink $test->{file}; +} + +sub run_clients +{ + my @parms = @_; + $arg = $parms[0]; + $clients = $parms[1]; + + for ($i = 0; $i < $clients; $i++) + { + $CL[$i] = new PerlACE::Process ("client", $arg); + $CL[$i]->Spawn (); + } + + for ($i = 0; $i < $clients; $i++) + { + $client = $CL[$i]->WaitKill (120); + if ($client != 0) + { + print STDERR "ERROR: client returned $client\n"; + $status = 1; + goto kill_server; + } + } +} + +if (PerlACE::is_vxworks_test()) { + $SV = new PerlACE::ProcessVX ("server"); +} +else { + $SV = new PerlACE::Process ("server"); +} + +if ($continuous) { + $SV->Arguments ("-ORBSvcConf continuous$PerlACE::svcconf_ext"); +} + $SV->Arguments ("-ORBDebugLevel 10 -ORBLogFile server.log"); + +$SV->Spawn (); + +for $test (@configurations) +{ + if (PerlACE::waitforfile_timed ($test->{file}, 10) == -1) + { + $server = $SV->TimedWait (1); + if ($server == 2) + { + # Mark as no longer running to avoid errors on exit. + $SV->{RUNNING} = 0; + exit $status; + } + else + { + print STDERR "ERROR: cannot find ior file: $test->{file}\n"; + $status = 1; + goto kill_server; + } + } + } + +for $test (@configurations) + { + print STDERR "\n*************************************************************\n"; + print STDERR "$test->{description}\n"; + print STDERR "*************************************************************\n\n"; + + run_clients ("-k file://".PerlACE::LocalFile($test->{file}), $number_of_clients); + } + +print STDERR "\n************************\n"; +print STDERR "Shutting down the server\n"; +print STDERR "************************\n\n"; + +run_clients ("-k file://".PerlACE::LocalFile($configurations[0]->{file})." -i 0 -x", 1); + +kill_server: + +$server = $SV->WaitKill (5); + +if ($server != 0) + { + print STDERR "ERROR: server returned $server\n"; + $status = 1; + } + +for $test (@configurations) + { + unlink $test->{file}; + } + +exit $status + diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/server.cpp b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/server.cpp new file mode 100644 index 00000000000..ea5dc6db558 --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/server.cpp @@ -0,0 +1,397 @@ +// $Id$ + +#include "test_i.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_unistd.h" +#include "tao/ORB_Core.h" +#include "ace/Task.h" +#include "tao/RTPortableServer/RTPortableServer.h" +#include "../check_supported_priorities.cpp" + +ACE_RCSID(Thread_Pool, server, "$Id$") + +const char *ior_output_file = "ior"; +int ior_count = 1; +CORBA::ULong static_threads = 1; +CORBA::ULong dynamic_threads = 25; +long nap_time = 1000; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "o:s:d:t:h"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.opt_arg (); + break; + + case 's': + static_threads = ACE_OS::atoi (get_opts.opt_arg ()); + break; + + case 'd': + dynamic_threads = ACE_OS::atoi (get_opts.opt_arg ()); + break; + + case 't': + nap_time = ACE_OS::atoi (get_opts.opt_arg ()); + break; + + case 'h': + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile> " + "-s <static_threads> " + "-d <dynamic_threads> " + "-t <nap_time> " + "\n", + argv [0]), + -1); + } + + // Indicates sucessful parsing of the command line + return 0; +} + +int +write_ior_to_file (CORBA::ORB_ptr orb, + test_ptr test + ACE_ENV_ARG_DECL) +{ + CORBA::String_var ior = + orb->object_to_string (test + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + char filename[BUFSIZ]; + ACE_OS::sprintf (filename, + "%s_%d", + ior_output_file, + ior_count++); + + FILE *output_file = + ACE_OS::fopen (filename, + "w"); + + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + filename), + -1); + + ACE_OS::fprintf (output_file, + "%s", + ior.in ()); + + ACE_OS::fclose (output_file); + + return 0; +} + +int +create_POA_and_register_servant (CORBA::Policy_ptr threadpool_policy, + const char *poa_name, + PortableServer::POAManager_ptr poa_manager, + PortableServer::POA_ptr root_poa, + CORBA::ORB_ptr orb, + RTCORBA::RTORB_ptr rt_orb + ACE_ENV_ARG_DECL) +{ + // Policies for the firstPOA to be created. + CORBA::PolicyList policies (3); policies.length (3); + + // Implicit_activation policy. + policies[0] = + root_poa->create_implicit_activation_policy + (PortableServer::IMPLICIT_ACTIVATION + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Thread pool policy. + policies[1] = + CORBA::Policy::_duplicate (threadpool_policy); + + // Priority Model policy. + policies[2] = + rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED, + 0 + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Create the POA under the RootPOA. + PortableServer::POA_var poa = + root_poa->create_POA (poa_name, + poa_manager, + policies + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + // Creation of POAs is over. Destroy the Policy objects. + for (CORBA::ULong i = 0; + i < policies.length (); + ++i) + { + policies[i]->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + } + + test_i *servant = + new test_i (orb, + poa.in (), + nap_time); + + PortableServer::ServantBase_var safe_servant (servant); + ACE_UNUSED_ARG (safe_servant); + + test_var test = + servant->_this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + int result = + write_ior_to_file (orb, + test.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (-1); + + return result; +} + +class Task : public ACE_Task_Base +{ +public: + + Task (ACE_Thread_Manager &thread_manager, + CORBA::ORB_ptr orb); + + int svc (void); + + CORBA::ORB_var orb_; + +}; + +Task::Task (ACE_Thread_Manager &thread_manager, + CORBA::ORB_ptr orb) + : ACE_Task_Base (&thread_manager), + orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +int +Task::svc (void) +{ + ACE_TRY_NEW_ENV + { + CORBA::Object_var object = + this->orb_->resolve_initial_references ("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + object = + this->orb_->resolve_initial_references ("RTORB" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + RTCORBA::RTORB_var rt_orb = + RTCORBA::RTORB::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + object = + this->orb_->resolve_initial_references ("RTCurrent" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + RTCORBA::Current_var current = + RTCORBA::Current::_narrow (object.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + RTCORBA::Priority default_thread_priority = + current->the_priority (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + test_i servant (this->orb_.in (), + root_poa.in (), + nap_time); + test_var test = + servant._this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + int result = + write_ior_to_file (this->orb_.in (), + test.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (result != 0) + return result; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::ULong stacksize = 0; + CORBA::Boolean allow_request_buffering = 0; + CORBA::ULong max_buffered_requests = 0; + CORBA::ULong max_request_buffer_size = 0; + + RTCORBA::ThreadpoolId threadpool_id_1 = + rt_orb->create_threadpool (stacksize, + static_threads, + dynamic_threads, + default_thread_priority, + allow_request_buffering, + max_buffered_requests, + max_request_buffer_size + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Policy_var threadpool_policy_1 = + rt_orb->create_threadpool_policy (threadpool_id_1 + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Boolean allow_borrowing = 0; + RTCORBA::ThreadpoolLanes lanes (1); + lanes.length (1); + + lanes[0].lane_priority = default_thread_priority; + lanes[0].static_threads = static_threads; + lanes[0].dynamic_threads = dynamic_threads; + + RTCORBA::ThreadpoolId threadpool_id_2 = + rt_orb->create_threadpool_with_lanes (stacksize, + lanes, + allow_borrowing, + allow_request_buffering, + max_buffered_requests, + max_request_buffer_size + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Policy_var threadpool_policy_2 = + rt_orb->create_threadpool_policy (threadpool_id_2 + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + result = + create_POA_and_register_servant (threadpool_policy_1.in (), + "first_poa", + poa_manager.in (), + root_poa.in (), + this->orb_.in (), + rt_orb.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (result != 0) + return result; + + result = + create_POA_and_register_servant (threadpool_policy_2.in (), + "second_poa", + poa_manager.in (), + root_poa.in (), + this->orb_.in (), + rt_orb.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + if (result != 0) + return result; + + this->orb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + this->orb_->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Exception caught:"); + return -1; + } + ACE_ENDTRY; + + return 0; +} + +int +main (int argc, char *argv[]) +{ + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, + argv, + "" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + int result = + parse_args (argc, argv); + if (result != 0) + return result; + + // Make sure we can support multiple priorities that are required + // for this test. + if (!check_supported_priorities (orb.in ())) + return 2; + + // Thread Manager for managing task. + ACE_Thread_Manager thread_manager; + + // Create task. + Task task (thread_manager, + orb.in ()); + + // Task activation flags. + long flags = + THR_NEW_LWP | + THR_JOINABLE | + orb->orb_core ()->orb_params ()->thread_creation_flags (); + + // Activate task. + result = + task.activate (flags); + if (result == -1) + { + if (errno == EPERM) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot create thread with scheduling policy %s\n" + "because the user does not have the appropriate privileges, terminating program....\n" + "Check svc.conf options and/or run as root\n", + sched_policy_name (orb->orb_core ()->orb_params ()->ace_sched_policy ())), + 2); + } + else + // Unexpected error. + ACE_ASSERT (0); + } + + // Wait for task to exit. + result = + thread_manager.wait (); + ACE_ASSERT (result != -1); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception caught"); + return -1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/svc.conf b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/svc.conf new file mode 100644 index 00000000000..c288d674567 --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/svc.conf @@ -0,0 +1 @@ +static RT_ORB_Loader "-RTORBDynamicThreadIdleTimeout 1000000" diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/svc.conf.xml b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/svc.conf.xml new file mode 100644 index 00000000000..0908328040b --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/svc.conf.xml @@ -0,0 +1,5 @@ +<?xml version='1.0'?> +<!-- Converted from svc.conf by svcconf-convert.pl --> +<ACE_Svc_Conf> + <static RT_ORB_Loader "-RTORBDynamicThreadIdleTimeout 1000000"> +</ACE_Svc_Conf> diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/test.idl b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/test.idl new file mode 100644 index 00000000000..3bc8f9af25c --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/test.idl @@ -0,0 +1,12 @@ +// +// $Id$ +// + +interface test +{ + long method (in long client_id, + in long iteration, + out long thread_count); + + oneway void shutdown (); +}; diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/test_i.cpp b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/test_i.cpp new file mode 100644 index 00000000000..6fbd244dd26 --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/test_i.cpp @@ -0,0 +1,71 @@ +// $Id$ + +#include "test_i.h" +#include "ace/OS_NS_unistd.h" +#include "tao/ORB_Core.h" +#include "tao/RTCORBA/Thread_Pool.h" + +ACE_RCSID(Thread_Pools, test_i, "$Id$") + +test_i::test_i (CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + long msec_sleep) + : orb_ (CORBA::ORB::_duplicate (orb)), + poa_ (PortableServer::POA::_duplicate (poa)), + nap_time_ () +{ + this->nap_time_.msec (msec_sleep); +} + +CORBA::Long +test_i::method (CORBA::Long client_id, + CORBA::Long iteration, + CORBA::Long_out thread_count + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // Get the ORB_Core's TSS resources. + TAO_ORB_Core_TSS_Resources *tss = + this->orb_->orb_core ()->get_tss_resources (); + + /// Get the lane attribute in TSS. + TAO_Thread_Lane *lane = + static_cast <TAO_Thread_Lane *> (tss->lane_); + + if (lane) + ACE_DEBUG ((LM_DEBUG, + "Request in thread %t (pool id = %d; lane id = %d) for client %d iteration %d\n", + lane->pool ().id (), + lane->id (), + client_id, + iteration)); + else + ACE_DEBUG ((LM_DEBUG, + "Request in thread %t (default thread pool) for client %d iteration %d\n", + client_id, + iteration)); + + ACE_OS::sleep (this->nap_time_); + + if (lane) + thread_count = lane->current_threads (); + else + thread_count = 0; + + return iteration; +} + +PortableServer::POA_ptr +test_i::_default_POA (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) +{ + return PortableServer::POA::_duplicate (this->poa_.in ()); +} + +void +test_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + this->orb_->shutdown (0 + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; +} diff --git a/TAO/tests/RTCORBA/Dynamic_Thread_Pool/test_i.h b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/test_i.h new file mode 100644 index 00000000000..7951ca0854c --- /dev/null +++ b/TAO/tests/RTCORBA/Dynamic_Thread_Pool/test_i.h @@ -0,0 +1,45 @@ +//============================================================================= +/** + * @file test_i.h + * + * $Id$ + * + * @author Irfan Pyarali + */ +// =================================================================== + +#include "testS.h" + +class test_i : + public POA_test +{ +public: + /// Constructor. + test_i (CORBA::ORB_ptr orb, + PortableServer::POA_ptr poa, + long msec_sleep); + + /// Test method. + CORBA::Long method (CORBA::Long client_id, + CORBA::Long iteration, + CORBA::Long_out thread_count + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Shutdown the server. + void shutdown (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Our POA. + PortableServer::POA_ptr _default_POA (ACE_ENV_SINGLE_ARG_DECL); + +private: + /// ORB. + CORBA::ORB_var orb_; + + /// Our POA. + PortableServer::POA_var poa_; + + /// Time spent in executing the upcall. + ACE_Time_Value nap_time_; +}; |