OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
OpenDDS::DCPS::ThreadSynch Class Referenceabstract

#include <ThreadSynch.h>

Inheritance diagram for OpenDDS::DCPS::ThreadSynch:
Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::ThreadSynch:
Collaboration graph
[legend]

Public Member Functions

virtual ~ThreadSynch ()
 
int register_worker (ThreadSynchWorker &worker)
 
void unregister_worker ()
 Our owner, the worker_, is breaking our relationship. More...
 
virtual void work_available ()=0
 

Protected Member Functions

 ThreadSynch (ThreadSynchResource *resource)
 
int wait_on_clogged_resource ()
 
virtual int register_worker_i ()
 
virtual void unregister_worker_i ()
 
WeakRcHandle< ThreadSynchWorkerworker ()
 Access the worker implementation directly. More...
 

Private Attributes

WeakRcHandle< ThreadSynchWorkerworker_
 
unique_ptr< ThreadSynchResourceresource_
 

Detailed Description

This class is the base class for different ThreadSynch stratege, currently only the thread per connection strategy is implemented and used.

Notes for object ownership: 1) Pointer to TransportSendStrategy object (as ThreadSynchWorker) directly but not reference counted. It won't have access problem during it lifetime because the TransportSendStrategy object owns this ThreadSynch object. 2) The ThreadSynch object is created by the ThreadSynchResource object and it owns the ThreadSynchResource object.

Definition at line 34 of file ThreadSynch.h.

Constructor & Destructor Documentation

◆ ~ThreadSynch()

OpenDDS::DCPS::ThreadSynch::~ThreadSynch ( )
virtual

Definition at line 15 of file ThreadSynch.cpp.

References DBG_ENTRY_LVL.

16 {
17  DBG_ENTRY_LVL("ThreadSynch","~ThreadSynch",6);
18 }
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ ThreadSynch()

ACE_INLINE OpenDDS::DCPS::ThreadSynch::ThreadSynch ( ThreadSynchResource resource)
protected

Note that we allow the ThreadSynchResource pointer to be NULL to support the NullSynch case.

Definition at line 14 of file ThreadSynch.inl.

References ACE_INLINE, and DBG_ENTRY_LVL.

15  : resource_(resource)
16 {
17  DBG_ENTRY_LVL("ThreadSynch","ThreadSynch",6);
18 }
unique_ptr< ThreadSynchResource > resource_
Definition: ThreadSynch.h:75
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

Member Function Documentation

◆ register_worker()

ACE_INLINE int OpenDDS::DCPS::ThreadSynch::register_worker ( ThreadSynchWorker worker)

The worker must introduce himself to this ThreadSynch object. It is the worker object that "owns" this ThreadSynch object. Returns 0 for success, -1 for failure.

Definition at line 28 of file ThreadSynch.inl.

References ACE_INLINE, DBG_ENTRY_LVL, OpenDDS::DCPS::ThreadSynchWorker::get_handle(), register_worker_i(), resource_, worker(), and worker_.

29 {
30  DBG_ENTRY_LVL("ThreadSynch","register_worker",6);
31  this->worker_ = worker;
32  if (resource_)
33  resource_->set_handle(worker.get_handle());
34  return this->register_worker_i();
35 }
WeakRcHandle< ThreadSynchWorker > worker()
Access the worker implementation directly.
Definition: ThreadSynch.inl:22
virtual int register_worker_i()
Definition: ThreadSynch.cpp:21
unique_ptr< ThreadSynchResource > resource_
Definition: ThreadSynch.h:75
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68
WeakRcHandle< ThreadSynchWorker > worker_
Definition: ThreadSynch.h:74

◆ register_worker_i()

int OpenDDS::DCPS::ThreadSynch::register_worker_i ( )
protectedvirtual

The default implementation is to do nothing here. The subclass may override the implementation in order to do something when the worker registers. Returns 0 for success, -1 for failure.

Reimplemented in OpenDDS::DCPS::PerConnectionSynch.

Definition at line 21 of file ThreadSynch.cpp.

References DBG_ENTRY_LVL.

Referenced by register_worker().

22 {
23  DBG_ENTRY_LVL("ThreadSynch","register_worker_i",6);
24  // Default implementation is to do nothing here. Subclass may override.
25  return 0;
26 }
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ unregister_worker()

ACE_INLINE void OpenDDS::DCPS::ThreadSynch::unregister_worker ( )

Our owner, the worker_, is breaking our relationship.

Definition at line 38 of file ThreadSynch.inl.

References ACE_INLINE, DBG_ENTRY_LVL, and unregister_worker_i().

39 {
40  DBG_ENTRY_LVL("ThreadSynch","unregister_worker",6);
41  this->unregister_worker_i();
42 }
virtual void unregister_worker_i()
Definition: ThreadSynch.cpp:29
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ unregister_worker_i()

void OpenDDS::DCPS::ThreadSynch::unregister_worker_i ( )
protectedvirtual

The default implementation is to do nothing here. The subclass may override the implementation in order to do something when the worker unregisters.

Reimplemented in OpenDDS::DCPS::PerConnectionSynch, and OpenDDS::DCPS::PoolSynch.

Definition at line 29 of file ThreadSynch.cpp.

References DBG_ENTRY_LVL.

Referenced by unregister_worker().

30 {
31  DBG_ENTRY_LVL("ThreadSynch","unregister_worker_i",6);
32  // Default implementation is to do nothing here. Subclass may override.
33 }
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ wait_on_clogged_resource()

ACE_INLINE int OpenDDS::DCPS::ThreadSynch::wait_on_clogged_resource ( )
protected

Definition at line 46 of file ThreadSynch.inl.

References ACE_ERROR, DBG_ENTRY_LVL, LM_ERROR, and resource_.

Referenced by OpenDDS::DCPS::PerConnectionSynch::svc().

47 {
48  DBG_ENTRY_LVL("ThreadSynch","wait_on_clogged_resource",6);
49 
50  int result = -1;
51 
52  if (this->resource_) {
53  result = this->resource_->wait_to_unclog();
54 
55  } else {
56  ACE_ERROR((LM_ERROR,
57  "(%P|%t) ERROR: ThreadSynch cannot wait on a NULL clogged resource.\n"));
58  }
59 
60  return result;
61 }
#define ACE_ERROR(X)
unique_ptr< ThreadSynchResource > resource_
Definition: ThreadSynch.h:75
#define DBG_ENTRY_LVL(CNAME, MNAME, DBG_LVL)
Definition: EntryExit.h:68

◆ work_available()

virtual void OpenDDS::DCPS::ThreadSynch::work_available ( )
pure virtual

The ThreadSynchWorker would like to have its perform_work() called from the appropriate thread once the ThreadSynchResource claims that it is_ready_for_work().

Implemented in OpenDDS::DCPS::ReactorSynch, OpenDDS::DCPS::PerConnectionSynch, OpenDDS::DCPS::PoolSynch, and OpenDDS::DCPS::NullSynch.

Referenced by OpenDDS::DCPS::TcpSendStrategy::schedule_output().

◆ worker()

ACE_INLINE OpenDDS::DCPS::WeakRcHandle< OpenDDS::DCPS::ThreadSynchWorker > OpenDDS::DCPS::ThreadSynch::worker ( )
protected

Access the worker implementation directly.

Definition at line 22 of file ThreadSynch.inl.

References ACE_INLINE, and worker_.

Referenced by OpenDDS::DCPS::ReactorSynch::ReactorSynch(), register_worker(), OpenDDS::DCPS::PerConnectionSynch::svc(), and OpenDDS::DCPS::ReactorSynch::~ReactorSynch().

23 {
24  return worker_;
25 }
WeakRcHandle< ThreadSynchWorker > worker_
Definition: ThreadSynch.h:74

Member Data Documentation

◆ resource_

unique_ptr<ThreadSynchResource> OpenDDS::DCPS::ThreadSynch::resource_
private

Definition at line 75 of file ThreadSynch.h.

Referenced by register_worker(), and wait_on_clogged_resource().

◆ worker_

WeakRcHandle<ThreadSynchWorker> OpenDDS::DCPS::ThreadSynch::worker_
private

Definition at line 74 of file ThreadSynch.h.

Referenced by register_worker(), and worker().


The documentation for this class was generated from the following files: