diff options
author | mcorino <mcorino@users.noreply.github.com> | 2010-06-16 09:04:21 +0000 |
---|---|---|
committer | mcorino <mcorino@users.noreply.github.com> | 2010-06-16 09:04:21 +0000 |
commit | 4f18d712f2c6691632fdaac2b75b51e1affe6e62 (patch) | |
tree | b1db4a787d5641c4f13b4bddd00ed5e1983cecc7 | |
parent | 46defb7d42917e64bda0875cd85ea4a3438a05a7 (diff) | |
download | ATCD-4f18d712f2c6691632fdaac2b75b51e1affe6e62.tar.gz |
Wed Jun 16 09:01:10 UTC 2010 Martin Corino <mcorino@remedy.nl>
* DAnCE/MPC/config/dance_installation_handlers.mpb:
Added missing base project.
* DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.inl:
* DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.cpp:
* DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.h:
Improved thread safety.
5 files changed, 149 insertions, 83 deletions
diff --git a/CIAO/ChangeLog b/CIAO/ChangeLog index 6dd26a27b53..9fbec9ef2d9 100644 --- a/CIAO/ChangeLog +++ b/CIAO/ChangeLog @@ -1,3 +1,13 @@ +Wed Jun 16 09:01:10 UTC 2010 Martin Corino <mcorino@remedy.nl> + + * DAnCE/MPC/config/dance_installation_handlers.mpb: + Added missing base project. + + * DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.inl: + * DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.cpp: + * DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.h: + Improved thread safety. + Wed Jun 16 06:43:17 UTC 2010 Marcel Smit <msmit@remedy.nl> * connectors/dds4ccm/tutorials/Shapes/Shapes_asm/ShapesReceiver_comp/ShapesReceiver_exec.h: diff --git a/CIAO/DAnCE/MPC/config/dance_installation_handlers.mpb b/CIAO/DAnCE/MPC/config/dance_installation_handlers.mpb new file mode 100644 index 00000000000..30d4afa48db --- /dev/null +++ b/CIAO/DAnCE/MPC/config/dance_installation_handlers.mpb @@ -0,0 +1,6 @@ +// $Id$ + +project : dance_artifact_installation { + libs += DAnCE_File_Installation DAnCE_Http_Installation + after += DAnCE_File_Installation DAnCE_Http_Installation +} diff --git a/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.cpp b/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.cpp index 9f9d52e71ce..b74ea5e6281 100644 --- a/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.cpp +++ b/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.cpp @@ -15,16 +15,13 @@ namespace DAnCE * ArtifactRegistry */ - ArtifactRegistry::ArtifactRegistry () - : install_count_ (0) + ArtifactRegistry::ArtifactRegistry (TCONDITION& condition, bool locked) + : condition_ (condition), + locked_ (locked), + install_count_ (0) { } - ArtifactRegistry::ArtifactRegistry (const ArtifactRegistry& ar) - { - *this = ar; - } - ArtifactRegistry::~ArtifactRegistry () { } @@ -37,7 +34,8 @@ namespace DAnCE ArtifactInstallation_Impl::TLOCK ArtifactInstallation_Impl::handler_lock_; ArtifactInstallation_Impl::ArtifactInstallation_Impl () - : POA_DAnCE::ArtifactInstallation () + : POA_DAnCE::ArtifactInstallation (), + artifacts_condition_ (artifacts_lock_) { } @@ -301,40 +299,55 @@ namespace DAnCE const std::string& name) { ACE_GUARD_REACTION (TLOCK, - handler_guard_, - handler_lock_, + artifacts_guard_, + artifacts_lock_, throw Deployment::PlanError ( plan_uuid.c_str (), - "ArtifactInstallation handler lock failed")); + "artifacts lock failed")); - // get existing or create new - ArtifactRegistry* ar = 0; - TArtifactsMap& plan_map = this->artifacts_[plan_uuid]; - TArtifactsMap::iterator it_art = plan_map.find (name); - if (it_art == plan_map.end ()) + while (true) { - ACE_NEW_NORETURN (ar, ArtifactRegistry ()); - if (ar == 0) + // get existing or create new + ArtifactRegistry* ar = 0; + TArtifactsMap& plan_map = this->artifacts_[plan_uuid]; + TArtifactsMap::iterator it_art = plan_map.find (name); + if (it_art == plan_map.end ()) { - throw Deployment::PlanError ( - plan_uuid.c_str (), - "out of memory"); + ACE_NEW_NORETURN (ar, ArtifactRegistry (this->artifacts_condition_, + true)); + if (ar == 0) + { + throw Deployment::PlanError ( + plan_uuid.c_str (), + "out of memory"); + } + plan_map[name] = ar; + return ar; // we created it locked so we're ready + } + else + { + ar = it_art->second; } - plan_map[name] = ar; - } - else - { - ar = it_art->second; - } - // lock - if (ar->lock ().acquire () != 0) - { - throw Deployment::PlanError ( - plan_uuid.c_str (), - "ArtifactRegistry lock failed"); + // lock + if (ar->is_locked ()) + { + // registry is locked by another thread so wait + if (this->artifacts_condition_.wait () != 0) + { + throw Deployment::PlanError ( + plan_uuid.c_str (), + "artifact registry lock failed"); + } + } + else + { + // we're free to set the lock + ar->set_locked (); + return ar; + } } - return ar; + return 0; } ArtifactRegistry* @@ -342,33 +355,46 @@ namespace DAnCE const std::string& name) { ACE_GUARD_REACTION (TLOCK, - handler_guard_, - handler_lock_, + artifacts_guard_, + artifacts_lock_, throw Deployment::PlanError ( plan_uuid.c_str (), - "ArtifactInstallation handler lock failed")); + "artifacts lock failed")); - // get existing - TArtifactsMap& plan_map = this->artifacts_[plan_uuid]; - TArtifactsMap::iterator it_art = plan_map.find (name); - if (it_art == plan_map.end ()) + while (true) { - std::string err ("unknown artifact "); - err += name; - throw Deployment::PlanError ( - plan_uuid.c_str (), - err.c_str ()); - } - ArtifactRegistry* ar = it_art->second; + // get existing + TArtifactsMap& plan_map = this->artifacts_[plan_uuid]; + TArtifactsMap::iterator it_art = plan_map.find (name); + if (it_art == plan_map.end ()) + { + std::string err ("unknown artifact "); + err += name; + throw Deployment::PlanError ( + plan_uuid.c_str (), + err.c_str ()); + } + ArtifactRegistry* ar = it_art->second; - // lock - if (ar->lock ().acquire () != 0) - { - throw Deployment::PlanError ( - plan_uuid.c_str (), - "ArtifactRegistry lock failed"); + // lock + if (ar->is_locked ()) + { + // registry is locked by another thread so wait + if (this->artifacts_condition_.wait () != 0) + { + throw Deployment::PlanError ( + plan_uuid.c_str (), + "artifact registry lock failed"); + } + } + else + { + // we're free to set the lock + ar->set_locked (); + return ar; + } } - return ar; + return 0; } void ArtifactInstallation_Impl::remove ( @@ -499,6 +525,8 @@ namespace DAnCE const std::string& plan_uuid, const std::string& name) { + ArtifactRegistry* ar = 0; + // lock the artifact registry for the given plan ArtifactRegistry::Guard ar_guard (this->lock_artifact_registry (plan_uuid, name)); @@ -510,6 +538,13 @@ namespace DAnCE // only if we reach 0, we really remove artifacts if (ar_guard->install_count () == 0) { + ACE_GUARD_REACTION (TLOCK, + artifacts_guard_, + artifacts_lock_, + throw Deployment::PlanError ( + plan_uuid.c_str (), + "artifacts lock failed")); + DANCE_DEBUG (6, (LM_TRACE, DLINFO ACE_TEXT("ArtifactInstallation_Impl::remove - ") ACE_TEXT ("removing versions for artifact %C from plan %C\n"), name.c_str (), plan_uuid.c_str ())); @@ -517,11 +552,10 @@ namespace DAnCE // erase the artifact registry this->artifacts_[plan_uuid].erase (name); - ArtifactRegistry* ar = &ar_guard; - return ar; + ar = &ar_guard; } } - return 0; + return ar; } void ArtifactInstallation_Impl::remove_artifacts_map ( @@ -529,11 +563,11 @@ namespace DAnCE TArtifactsMap& artifacts_map) { ACE_GUARD_REACTION (TLOCK, - handler_guard_, - handler_lock_, + artifacts_guard_, + artifacts_lock_, throw Deployment::PlanError ( plan_uuid.c_str (), - "ArtifactInstallation handler lock failed")); + "artifacts lock failed")); TArtifactsRegistry::iterator it_reg = this->artifacts_.find (plan_uuid); if (it_reg != this->artifacts_.end ()) @@ -544,12 +578,17 @@ namespace DAnCE } char * ArtifactInstallation_Impl::get_artifact_location ( - const char * uuid, + const char * plan_uuid, const char * artifact_name) { - ACE_GUARD_RETURN (TLOCK, guard_, handler_lock_, 0); + ACE_GUARD_REACTION (TLOCK, + artifacts_guard_, + artifacts_lock_, + throw Deployment::PlanError ( + plan_uuid, + "artifacts lock failed")); - TArtifactsRegistry::iterator it_reg = this->artifacts_.find (uuid); + TArtifactsRegistry::iterator it_reg = this->artifacts_.find (plan_uuid); if (it_reg != this->artifacts_.end ()) { TArtifactsMap::iterator it_art = it_reg->second.find (artifact_name); diff --git a/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.h b/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.h index 1e77e80a23a..246db133af7 100644 --- a/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.h +++ b/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.h @@ -28,7 +28,7 @@ namespace DAnCE class ArtifactRegistry { public: - typedef ACE_MT_SYNCH::MUTEX TLOCK; + typedef ACE_MT_SYNCH::CONDITION TCONDITION; struct Version { std::string protocol_; @@ -41,12 +41,9 @@ namespace DAnCE }; typedef std::vector<Version> TVersions; - ArtifactRegistry (); - ArtifactRegistry (const ArtifactRegistry& ar); + ArtifactRegistry (TCONDITION& condition, bool locked=false); ~ArtifactRegistry (); - ArtifactRegistry& operator =(const ArtifactRegistry& ar); - const std::string& location () const; TVersions& versions (); @@ -56,7 +53,9 @@ namespace DAnCE void increment_install_count (); void decrement_install_count (); - TLOCK& lock (); + void set_locked (); + void set_unlocked (); + bool is_locked () const; class Guard { @@ -75,7 +74,8 @@ namespace DAnCE }; private: - TLOCK lock_; + TCONDITION& condition_; + bool locked_; u_long install_count_; TVersions versions_; }; @@ -85,6 +85,7 @@ namespace DAnCE { public: typedef ACE_MT_SYNCH::MUTEX TLOCK; + typedef ACE_MT_SYNCH::CONDITION TCONDITION; typedef ArtifactInstallationHandler::TPropertyMap TPropertyMap; ArtifactInstallation_Impl (); @@ -102,7 +103,7 @@ namespace DAnCE virtual void remove_all (const char * plan_uuid); - virtual char * get_artifact_location (const char * uuid, + virtual char * get_artifact_location (const char * plan_uuid, const char * artifact_name); private: @@ -146,6 +147,8 @@ namespace DAnCE TArtifactsMap& artifacts_map); TArtifactsRegistry artifacts_; + TLOCK artifacts_lock_; + TCONDITION artifacts_condition_; public: diff --git a/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.inl b/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.inl index 756e9fdde98..e5cebbf877c 100644 --- a/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.inl +++ b/CIAO/DAnCE/tools/Artifact_Installation/Artifact_Installation_Impl.inl @@ -31,14 +31,6 @@ namespace DAnCE } ACE_INLINE - ArtifactRegistry& ArtifactRegistry::operator =(const ArtifactRegistry& ar) - { - this->versions_ = ar.versions (); - this->install_count_ = ar.install_count (); - return *this; - } - - ACE_INLINE const std::string& ArtifactRegistry::location () const { return this->versions_.back ().location_; @@ -75,9 +67,25 @@ namespace DAnCE } ACE_INLINE - ArtifactRegistry::TLOCK& ArtifactRegistry::lock () + void ArtifactRegistry::set_locked () + { + this->locked_ = true; + } + + ACE_INLINE + void ArtifactRegistry::set_unlocked () + { + if (this->locked_) + { + this->locked_ = false; + this->condition_.broadcast (); + } + } + + ACE_INLINE + bool ArtifactRegistry::is_locked () const { - return this->lock_; + return this->locked_; } ACE_INLINE @@ -91,7 +99,7 @@ namespace DAnCE { if (this->arp_) { - this->arp_->lock ().release (); + this->arp_->set_unlocked (); } this->arp_ = 0; } |