OpenDDS::DCPS::ThreadSynch Class Reference

#include <ThreadSynch.h>

Inheritance diagram for OpenDDS::DCPS::ThreadSynch:

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

Collaboration graph
[legend]
List of all members.

Public Member Functions

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

Protected Member Functions

 ThreadSynch (ThreadSynchResource *resource)
ThreadSynchWorker::WorkOutcome perform_work ()
int wait_on_clogged_resource ()
virtual int register_worker_i ()
virtual void unregister_worker_i ()
ThreadSynchWorkerworker ()
 Access the worker implementation directly.

Private Attributes

ThreadSynchWorkerworker_
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 31 of file ThreadSynch.h.


Constructor & Destructor Documentation

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

Definition at line 15 of file ThreadSynch.cpp.

References DBG_ENTRY_LVL, and resource_.

00016 {
00017   DBG_ENTRY_LVL("ThreadSynch","~ThreadSynch",6);
00018   delete this->resource_;
00019 }

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 DBG_ENTRY_LVL.

00015   : worker_(0),
00016     resource_(resource)
00017 {
00018   DBG_ENTRY_LVL("ThreadSynch","ThreadSynch",6);
00019 }


Member Function Documentation

ACE_INLINE OpenDDS::DCPS::ThreadSynchWorker::WorkOutcome OpenDDS::DCPS::ThreadSynch::perform_work (  )  [protected]

This will tell the worker_ to perform_work(). A return value of 0 means that the perform_work() did all the work necessary, and we shouldn't ask it to perform_work() again, unless we receive another work_available() call. It won't hurt if we call perform_work() and it has nothing to do - it will immediately return 0 to indicate it has nothing more to do (at the moment). A return value of 1 means that the perform_work() completed, and there is still more work it could do. The perform_work() should be called again in this case.

Definition at line 47 of file ThreadSynch.inl.

References DBG_ENTRY_LVL, OpenDDS::DCPS::ThreadSynchWorker::perform_work(), OpenDDS::DCPS::ThreadSynchWorker::WORK_OUTCOME_NO_MORE_TO_DO, and worker_.

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

00048 {
00049   DBG_ENTRY_LVL("ThreadSynch","perform_work",6);
00050 
00051   if (this->worker_ == 0) {
00052     return ThreadSynchWorker::WORK_OUTCOME_NO_MORE_TO_DO;
00053   }
00054 
00055   return this->worker_->perform_work();
00056 }

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 29 of file ThreadSynch.inl.

References DBG_ENTRY_LVL, register_worker_i(), worker(), and worker_.

00030 {
00031   DBG_ENTRY_LVL("ThreadSynch","register_worker",6);
00032   this->worker_ = worker;
00033   return this->register_worker_i();
00034 }

int OpenDDS::DCPS::ThreadSynch::register_worker_i (  )  [protected, virtual]

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 22 of file ThreadSynch.cpp.

References DBG_ENTRY_LVL.

Referenced by register_worker().

00023 {
00024   DBG_ENTRY_LVL("ThreadSynch","register_worker_i",6);
00025   // Default implementation is to do nothing here.  Subclass may override.
00026   return 0;
00027 }

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

Our owner, the worker_, is breaking our relationship.

Definition at line 37 of file ThreadSynch.inl.

References DBG_ENTRY_LVL, resource_, unregister_worker_i(), and worker_.

Referenced by OpenDDS::DCPS::TransportSendStrategy::stop().

00038 {
00039   DBG_ENTRY_LVL("ThreadSynch","unregister_worker",6);
00040   this->unregister_worker_i();
00041   this->worker_ = 0;
00042   delete this->resource_;
00043   this->resource_ = 0;
00044 }

void OpenDDS::DCPS::ThreadSynch::unregister_worker_i (  )  [protected, virtual]

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 30 of file ThreadSynch.cpp.

References DBG_ENTRY_LVL.

Referenced by unregister_worker().

00031 {
00032   DBG_ENTRY_LVL("ThreadSynch","unregister_worker_i",6);
00033   // Default implementation is to do nothing here.  Subclass may override.
00034 }

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

Definition at line 59 of file ThreadSynch.inl.

References DBG_ENTRY_LVL, resource_, and OpenDDS::DCPS::ThreadSynchResource::wait_to_unclog().

00060 {
00061   DBG_ENTRY_LVL("ThreadSynch","wait_on_clogged_resource",6);
00062 
00063   int result = -1;
00064 
00065   if (this->resource_) {
00066     result = this->resource_->wait_to_unclog();
00067 
00068   } else {
00069     ACE_ERROR((LM_ERROR,
00070                "(%P|%t) ERROR: ThreadSynch cannot wait on a NULL clogged resource.\n"));
00071   }
00072 
00073   return result;
00074 }

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::NullSynch, OpenDDS::DCPS::PerConnectionSynch, OpenDDS::DCPS::PoolSynch, and OpenDDS::DCPS::ReactorSynch.

Referenced by OpenDDS::DCPS::TransportSendStrategy::perform_work(), OpenDDS::DCPS::TcpSendStrategy::schedule_output(), OpenDDS::DCPS::TransportSendStrategy::send(), and OpenDDS::DCPS::TransportSendStrategy::send_stop().

ACE_INLINE OpenDDS::DCPS::ThreadSynchWorker * OpenDDS::DCPS::ThreadSynch::worker (  )  [protected]

Access the worker implementation directly.

Definition at line 23 of file ThreadSynch.inl.

References worker_.

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

00024 {
00025   return worker_;
00026 }


Member Data Documentation

ThreadSynchResource* OpenDDS::DCPS::ThreadSynch::resource_ [private]

Definition at line 85 of file ThreadSynch.h.

Referenced by unregister_worker(), wait_on_clogged_resource(), and ~ThreadSynch().

ThreadSynchWorker* OpenDDS::DCPS::ThreadSynch::worker_ [private]

Definition at line 84 of file ThreadSynch.h.

Referenced by perform_work(), register_worker(), unregister_worker(), and worker().


The documentation for this class was generated from the following files:
Generated on Fri Feb 12 20:06:29 2016 for OpenDDS by  doxygen 1.4.7