From 6939df7520284e8c46bc1c9a9934b2c002827330 Mon Sep 17 00:00:00 2001 From: iliyan Date: Sat, 5 Apr 2008 16:43:10 +0000 Subject: ChangeLogTag: Sat Apr 5 16:21:50 UTC 2008 Iliyan Jeliazkov --- ACE/ChangeLog | 17 ++++++++ ACE/ace/Service_Config.cpp | 4 +- ACE/ace/Service_Config.inl | 2 +- ACE/ace/Service_Gestalt.cpp | 63 ++++++++++++++++++++---------- ACE/ace/Service_Gestalt.h | 22 ++++++++--- ACE/ace/svcconf.mpb | 7 ++-- ACE/tests/Object_Manager_Flipping_Test.cpp | 3 +- 7 files changed, 85 insertions(+), 33 deletions(-) diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 3dbd27d5d4a..26b97f4c899 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,20 @@ +Sat Apr 5 16:21:50 UTC 2008 Iliyan Jeliazkov + + * ace/Service_Config.inl: + * ace/Service_Config.cpp: + * ace/Service_Gestalt.cpp: + * ace/Service_Gestalt.h: + + Making SG intrusively refcountable by introducing + intrusive_{add,remove}_ref methods and a refcounter. Adding + skip_default_svc_conf_file parameter in process_directives. + + * ace/svcconf.mpb: + * tests/Object_Manager_Flipping_Test.cpp: + + Reformatting and cleanup. + + Sat Apr 5 13:42:57 UTC 2008 Johnny Willemsen * tests/Bug_2980_Regression_Test.cpp: diff --git a/ACE/ace/Service_Config.cpp b/ACE/ace/Service_Config.cpp index 02fc863790c..5a374360a01 100644 --- a/ACE/ace/Service_Config.cpp +++ b/ACE/ace/Service_Config.cpp @@ -160,8 +160,8 @@ ACE_Service_Config::parse_args_i (int argc, ACE_TCHAR *argv[]) for (int c = getopt.opt_ind (); c < argc; ++c) superargv.add (argv[c-1], true); - return ACE_Service_Gestalt::parse_args_i (superargv.argc (), - superargv.argv ()); + return this->parse_args_i (superargv.argc (), + superargv.argv ()); } /* parse_args_i () */ diff --git a/ACE/ace/Service_Config.inl b/ACE/ace/Service_Config.inl index 1cc6e35fe1d..cc57a2d4c71 100644 --- a/ACE/ace/Service_Config.inl +++ b/ACE/ace/Service_Config.inl @@ -141,7 +141,7 @@ ACE_Service_Config::process_directive (const ACE_TCHAR directive[]) ACE_INLINE int ACE_Service_Config::process_directives (void) { - return ACE_Service_Config::current ()->process_directives (); + return ACE_Service_Config::current ()->process_directives (false); } ACE_INLINE int diff --git a/ACE/ace/Service_Gestalt.cpp b/ACE/ace/Service_Gestalt.cpp index c644ec6ef72..6dec7c556fa 100644 --- a/ACE/ace/Service_Gestalt.cpp +++ b/ACE/ace/Service_Gestalt.cpp @@ -194,7 +194,29 @@ ACE_Service_Gestalt::Processed_Static_Svc::~Processed_Static_Svc (void) delete [] name_; } -// ---------------------------------------- +void +ACE_Service_Gestalt::intrusive_add_ref (ACE_Service_Gestalt* g) +{ + if (g != 0) + { + long tmp = ++g->refcnt_; + // printf ("// (%x) ++refcnt=%ld\n", (unsigned int)ACE_OS::thr_self (), tmp); + ACE_ASSERT (tmp > 0); + } +} + +void +ACE_Service_Gestalt::intrusive_remove_ref (ACE_Service_Gestalt* g) +{ + if (g != 0) + { + long tmp = --g->refcnt_; + // printf ("// (%x) refcnt--=%ld\n", (unsigned int)ACE_OS::thr_self (), tmp); + if (tmp <= 0) delete g; + ACE_ASSERT (tmp >= 0); + } +} + ACE_Service_Gestalt::~ACE_Service_Gestalt (void) { @@ -210,7 +232,7 @@ ACE_Service_Gestalt::~ACE_Service_Gestalt (void) #ifndef ACE_NLOGGING if (ACE::debug ()) ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("ACE (%P|%t) SG::dtor - this=%@, pss = %@\n"), + ACE_TEXT ("ACE (%P|%t) SG::~SG - this=%@, pss = %@\n"), this, this->processed_static_svcs_)); #endif @@ -225,8 +247,12 @@ ACE_Service_Gestalt::~ACE_Service_Gestalt (void) delete *pss; } } + delete this->processed_static_svcs_; this->processed_static_svcs_ = 0; + + delete this->svc_conf_file_queue_; + this->svc_conf_file_queue_ = 0; } ACE_Service_Gestalt::ACE_Service_Gestalt (size_t size, @@ -1011,7 +1037,7 @@ int ACE_Service_Gestalt::open_i (const ACE_TCHAR /*program_name*/[], const ACE_TCHAR* /*logger_key*/, bool /*ignore_static_svcs*/, - bool /*ignore_default_svc_conf_file*/, + bool ignore_default_svc_conf_file, bool ignore_debug_flag) { ACE_TRACE ("ACE_Service_Gestalt::open_i"); @@ -1062,7 +1088,7 @@ ACE_Service_Gestalt::open_i (const ACE_TCHAR /*program_name*/[], if (this->process_commandline_directives () == -1) result = -1; else - result = this->process_directives (); + result = this->process_directives (ignore_default_svc_conf_file); } @@ -1194,37 +1220,34 @@ ACE_Service_Gestalt::parse_args_i (int argc, ACE_TCHAR *argv[]) -// Process service configuration requests as indicated in the queue of -// svc.conf files. +// Process service configuration directives from the files queued for +// processing int -ACE_Service_Gestalt::process_directives (void) +ACE_Service_Gestalt::process_directives (bool ignore_default_svc_conf_file) { ACE_TRACE ("ACE_Service_Gestalt::process_directives"); - int result = 0; + if (this->svc_conf_file_queue_ == 0 + || this->svc_conf_file_queue_->is_empty ()) + return 0; - if (this->svc_conf_file_queue_ != 0) - { ACE_TString *sptr = 0; + ACE_TString default_svc_conf (ACE_DEFAULT_SVC_CONF); // Iterate through all the svc.conf files. for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_conf_file_queue_); iter.next (sptr) != 0; iter.advance ()) { - int r = this->process_file (sptr->fast_rep ()); + if (*sptr == default_svc_conf && ignore_default_svc_conf_file) + continue; - if (r < 0) - { - result = r; - break; + int result = this->process_file (sptr->fast_rep ()); + if (result < 0) + return result; } - result += r; - } - } - - return result; + return 0; } /* process_directives () */ diff --git a/ACE/ace/Service_Gestalt.h b/ACE/ace/Service_Gestalt.h index 96f8af3288c..6c426d9a0d7 100644 --- a/ACE/ace/Service_Gestalt.h +++ b/ACE/ace/Service_Gestalt.h @@ -29,6 +29,7 @@ #include "ace/Singleton.h" #include "ace/OS_NS_signal.h" #include "ace/Synch_Traits.h" +#include "ace/Atomic_Op.h" ACE_BEGIN_VERSIONED_NAMESPACE_DECL @@ -62,14 +63,14 @@ class ACE_Svc_Conf_Param; * may or may not be bounded by the lifetime of the gestalt, that owns * it. This feature is important for the derived classes and the * Service Config in particular. - + * */ class ACE_Export ACE_Service_Gestalt { private: - /** - * Not implemented to enforce no copying - */ + /// + /// Not implemented to enforce no copying + // ACE_UNIMPLEMENTED_FUNC (ACE_Service_Gestalt(const ACE_Service_Gestalt&)) ACE_UNIMPLEMENTED_FUNC (ACE_Service_Gestalt& operator=(const ACE_Service_Gestalt&)) @@ -236,7 +237,7 @@ public: * provided in the svc.conf file(s). Returns the number of errors * that occurred. */ - int process_directives (void); + int process_directives (bool ignore_default_svc_conf_file); /// Tidy up and perform last rites when ACE_Service_Config is shut /// down. This method calls . Returns 0. @@ -400,6 +401,7 @@ protected: friend class ACE_Dynamic_Service_Base; friend class ACE_Service_Object; + friend class ACE_Service_Config; friend class ACE_Service_Config_Guard; protected: @@ -446,6 +448,13 @@ protected: /// the static_svcs_ list. ACE_PROCESSED_STATIC_SVCS* processed_static_svcs_; + /// Support for intrusive reference counting + ACE_Atomic_Op refcnt_; + + public: + static void intrusive_add_ref (ACE_Service_Gestalt*); + static void intrusive_remove_ref (ACE_Service_Gestalt*); + }; /* class ACE_Service_Gestalt */ @@ -456,7 +465,7 @@ protected: * * Helps to resolve an issue with hybrid services, i.e. dynamic * services, accompanied by static services in the same DLL. Only - * automatic instances of SDG are supposed to exist. Those are + * automatic instances of this class are supposed to exist. Those are * created during (dynamic) service initialization and serve to: * * (a) Ensure the service we are loading is ordered last in the @@ -483,6 +492,7 @@ private: size_t repo_begin_; ACE_TCHAR const * const name_; ACE_Service_Type const * dummy_; + # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) ACE_Guard< ACE_Recursive_Thread_Mutex > repo_monitor_; #endif diff --git a/ACE/ace/svcconf.mpb b/ACE/ace/svcconf.mpb index 40f2d545367..0ab77af76cd 100644 --- a/ACE/ace/svcconf.mpb +++ b/ACE/ace/svcconf.mpb @@ -30,9 +30,10 @@ feature(ace_svcconf) { "Svc_Conf_y.cpp: Svc_Conf.y" "ifeq ($(notdir $(YACC)), bison)" " $(YACC) -l -d Svc_Conf.y" - " sed -e 's/char \\*getenv/char *ace_foo/g' \\" // Eliminates getenv prototype, use ACE's + " sed -e 's/char \\*getenv/char *ace_foo/g' \\" // Eliminates getenv prototype, use ACE's " -e 's/= getenv/= ACE_OS::getenv/g' \\" // ... like this - qualified. " -e 's/fprintf/ACE_OS::fprintf/g' \\" // Use ACE's fprintf, not library's + " -e 's/\t/ /g' \\" // Eliminate tabs (replace with 2 spaces) " -e 's/yy/ace_yy/g' \\" " -e 's/->ace_yyerrno/->yyerrno/g' \\" // These reverse the unwanted ace_ prefix " -e 's/->ace_yylineno/->yylineno/g' \\" // added by the substitution, above. @@ -49,8 +50,8 @@ feature(ace_svcconf) { " -e 's/Svc_Conf\\.tab\\.c/Svc_Conf_y.cpp/g' < Svc_Conf.tab.c > /tmp/$@" " cp /tmp/$@ $@" " echo \/\/ '$$I''d:$$' >Svc_Conf_Tokens.h" - " echo '#ifndef BISON_SVC_CONF_TAB_H' >>Svc_Conf_Tokens.h" // Inclusion protection macros - " echo '# define BISON_SVC_CONF_TAB_H' >>Svc_Conf_Tokens.h" // ... same ... + " echo '#ifndef BISON_SVC_CONF_TAB_H' >>Svc_Conf_Tokens.h" // Inclusion protection macros + " echo '# define BISON_SVC_CONF_TAB_H' >>Svc_Conf_Tokens.h" // ... same ... " echo '# define ACE_YYSTYPE_IS_DECLARED 1' >>Svc_Conf_Tokens.h" // Don't use Svc_Conf_y.cpp's " sed -e 's/yy/ace_yy/g' \\" " -e 's/YY/ACE_YY/g' >Svc_Conf_Tokens.h" diff --git a/ACE/tests/Object_Manager_Flipping_Test.cpp b/ACE/tests/Object_Manager_Flipping_Test.cpp index 36f61a19383..876fafe790c 100644 --- a/ACE/tests/Object_Manager_Flipping_Test.cpp +++ b/ACE/tests/Object_Manager_Flipping_Test.cpp @@ -27,6 +27,7 @@ #include "ace/OS_Memory.h" #include "ace/ACE.h" #include "ace/Service_Config.h" +#include "ace/Intrusive_Auto_Ptr.h" ACE_RCSID(tests, Object_Manager_Flipping_Test, "$Id$") @@ -111,7 +112,7 @@ int run_main (int, ACE_TCHAR *[]) ACE::init(); ACE_START_TEST (ACE_TEXT ("Object_Manager_Flipping_Test")); - ACE_Service_Gestalt_Auto_Ptr p2 (ACE_Service_Config::instance ()); + ACE_Intrusive_Auto_Ptr p2 (ACE_Service_Config::instance ()); // ACE_ASSERT uses Log_Msg::instance() and needs to be done only // after ACE_START_TEST -- cgit v1.2.1