00001 /* 00002 * 00003 * 00004 * Distributed under the OpenDDS License. 00005 * See: http://www.opendds.org/license.html 00006 */ 00007 00008 #ifndef OPENDDS_DCPS_THREADSYNCH_H 00009 #define OPENDDS_DCPS_THREADSYNCH_H 00010 00011 #include "dds/DCPS/dcps_export.h" 00012 #include "ThreadSynchWorker.h" 00013 #include "dds/DCPS/PoolAllocationBase.h" 00014 #include "dds/DCPS/unique_ptr.h" 00015 00016 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 00017 00018 namespace OpenDDS { 00019 namespace DCPS { 00020 00021 class ThreadSynchResource; 00022 00023 /** 00024 * This class is the base class for different ThreadSynch stratege, currently 00025 * only the thread per connection strategy is implemented and used. 00026 * 00027 * Notes for object ownership: 00028 * 1) Pointer to TransportSendStrategy object (as ThreadSynchWorker) directly but not 00029 * reference counted. It won't have access problem during it lifetime because the 00030 * TransportSendStrategy object owns this ThreadSynch object. 00031 * 2) The ThreadSynch object is created by the ThreadSynchResource object and it owns 00032 * the ThreadSynchResource object. 00033 */ 00034 class OpenDDS_Dcps_Export ThreadSynch : public PoolAllocationBase { 00035 public: 00036 00037 virtual ~ThreadSynch(); 00038 00039 /// The worker must introduce himself to this ThreadSynch object. 00040 /// It is the worker object that "owns" this ThreadSynch object. 00041 /// Returns 0 for success, -1 for failure. 00042 int register_worker(ThreadSynchWorker& worker); 00043 00044 /// Our owner, the worker_, is breaking our relationship. 00045 void unregister_worker(); 00046 00047 /// The ThreadSynchWorker would like to have its perform_work() called 00048 /// from the appropriate thread once the ThreadSynchResource claims 00049 /// that it is_ready_for_work(). 00050 virtual void work_available() = 0; 00051 00052 protected: 00053 00054 // This ThreadSynch object takes ownership of the resource. 00055 ThreadSynch(ThreadSynchResource* resource); 00056 00057 int wait_on_clogged_resource(); 00058 00059 /// The default implementation is to do nothing here. The 00060 /// subclass may override the implementation in order to do 00061 /// something when the worker registers. 00062 /// Returns 0 for success, -1 for failure. 00063 virtual int register_worker_i(); 00064 00065 /// The default implementation is to do nothing here. The 00066 /// subclass may override the implementation in order to do 00067 /// something when the worker unregisters. 00068 virtual void unregister_worker_i(); 00069 00070 /// Access the worker implementation directly. 00071 WeakRcHandle<ThreadSynchWorker> worker(); 00072 00073 private: 00074 WeakRcHandle<ThreadSynchWorker> worker_; 00075 unique_ptr<ThreadSynchResource> resource_; 00076 }; 00077 00078 } // namespace DCPS 00079 } // namespace OpenDDS 00080 00081 OPENDDS_END_VERSIONED_NAMESPACE_DECL 00082 00083 #if defined (__ACE_INLINE__) 00084 #include "ThreadSynch.inl" 00085 #endif /* __ACE_INLINE__ */ 00086 00087 #endif /* OPENDDS_DCPS_THREADSYNCH_H */