00001 // -*- C++ -*- 00002 00003 /** 00004 * @file ESF_RefCount_Guard.h 00005 * 00006 * $Id: ESF_RefCount_Guard.h 73791 2006-07-27 20:54:56Z wotte $ 00007 * 00008 * @author Carlos O'Ryan (coryan@cs.wustl.edu) 00009 * 00010 * http://doc.ece.uci.edu/~coryan/EC/index.html 00011 */ 00012 00013 #ifndef TAO_ESF_REFCOUNT_GUARD_H 00014 #define TAO_ESF_REFCOUNT_GUARD_H 00015 00016 #include "ace/config-all.h" 00017 00018 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00019 # pragma once 00020 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00021 00022 #include "tao/Versioned_Namespace.h" 00023 00024 TAO_BEGIN_VERSIONED_NAMESPACE_DECL 00025 00026 /** 00027 * @class TAO_ESF_RefCount_Guard 00028 * 00029 * @brief Reference count based guard. 00030 * 00031 * A common idiom used on event services is to increment a 00032 * reference count before starting a long running operation. 00033 * The system can then execute the operation without any risk of 00034 * having the underlying object destroyed. The advantage of using 00035 * a reference count is that no mutex or lock needs to be held 00036 * while the operation is beign executed. 00037 */ 00038 template<class T> 00039 class TAO_ESF_RefCount_Guard 00040 { 00041 public: 00042 /// Constructor 00043 TAO_ESF_RefCount_Guard (T &refcount); 00044 00045 /// Destructor 00046 ~TAO_ESF_RefCount_Guard (void); 00047 00048 protected: 00049 /// The reference count 00050 T &refcount_; 00051 }; 00052 00053 TAO_END_VERSIONED_NAMESPACE_DECL 00054 00055 #if defined (__ACE_INLINE__) 00056 #include "orbsvcs/ESF/ESF_RefCount_Guard.inl" 00057 #endif /* __ACE_INLINE__ */ 00058 00059 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE) 00060 #include "orbsvcs/ESF/ESF_RefCount_Guard.cpp" 00061 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */ 00062 00063 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA) 00064 #pragma implementation ("ESF_RefCount_Guard.cpp") 00065 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */ 00066 00067 #endif /* TAO_ESF_REFCOUNT_GUARD_H */