OpenDDS  Snapshot(2023/04/28-20:55)
ThreadSynch.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
8 #ifndef OPENDDS_DCPS_TRANSPORT_FRAMEWORK_THREADSYNCH_H
9 #define OPENDDS_DCPS_TRANSPORT_FRAMEWORK_THREADSYNCH_H
10 
11 #include "dds/DCPS/dcps_export.h"
12 #include "ThreadSynchWorker.h"
14 #include "dds/DCPS/unique_ptr.h"
15 
17 
18 namespace OpenDDS {
19 namespace DCPS {
20 
21 class ThreadSynchResource;
22 
23 /**
24  * This class is the base class for different ThreadSynch stratege, currently
25  * only the thread per connection strategy is implemented and used.
26  *
27  * Notes for object ownership:
28  * 1) Pointer to TransportSendStrategy object (as ThreadSynchWorker) directly but not
29  * reference counted. It won't have access problem during it lifetime because the
30  * TransportSendStrategy object owns this ThreadSynch object.
31  * 2) The ThreadSynch object is created by the ThreadSynchResource object and it owns
32  * the ThreadSynchResource object.
33  */
35 public:
36 
37  virtual ~ThreadSynch();
38 
39  /// The worker must introduce himself to this ThreadSynch object.
40  /// It is the worker object that "owns" this ThreadSynch object.
41  /// Returns 0 for success, -1 for failure.
42  int register_worker(ThreadSynchWorker& worker);
43 
44  /// Our owner, the worker_, is breaking our relationship.
45  void unregister_worker();
46 
47  /// The ThreadSynchWorker would like to have its perform_work() called
48  /// from the appropriate thread once the ThreadSynchResource claims
49  /// that it is_ready_for_work().
50  virtual void work_available() = 0;
51 
52 protected:
53 
54  // This ThreadSynch object takes ownership of the resource.
56 
57  int wait_on_clogged_resource();
58 
59  /// The default implementation is to do nothing here. The
60  /// subclass may override the implementation in order to do
61  /// something when the worker registers.
62  /// Returns 0 for success, -1 for failure.
63  virtual int register_worker_i();
64 
65  /// The default implementation is to do nothing here. The
66  /// subclass may override the implementation in order to do
67  /// something when the worker unregisters.
68  virtual void unregister_worker_i();
69 
70  /// Access the worker implementation directly.
72 
73 private:
76 };
77 
78 } // namespace DCPS
79 } // namespace OpenDDS
80 
82 
83 #if defined (__ACE_INLINE__)
84 #include "ThreadSynch.inl"
85 #endif /* __ACE_INLINE__ */
86 
87 #endif /* OPENDDS_DCPS_THREADSYNCH_H */
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
unique_ptr< ThreadSynchResource > resource_
Definition: ThreadSynch.h:75
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
WeakRcHandle< ThreadSynchWorker > worker_
Definition: ThreadSynch.h:74
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28