summaryrefslogtreecommitdiff
path: root/ace/TP_Reactor.h
diff options
context:
space:
mode:
authornanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-07-29 12:13:10 +0000
committernanbor <nanbor@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-07-29 12:13:10 +0000
commitc58830a8ae5bb549b8ea15b31cf16403eb03c363 (patch)
treec25c98634a7145d2dd10e7379ce05c407d5f9860 /ace/TP_Reactor.h
parent59de0d81f1793f5d033d73af6d3c402b6185388c (diff)
downloadATCD-c58830a8ae5bb549b8ea15b31cf16403eb03c363.tar.gz
Integrated TP_Reactor
Diffstat (limited to 'ace/TP_Reactor.h')
-rw-r--r--ace/TP_Reactor.h156
1 files changed, 156 insertions, 0 deletions
diff --git a/ace/TP_Reactor.h b/ace/TP_Reactor.h
new file mode 100644
index 00000000000..11d02955290
--- /dev/null
+++ b/ace/TP_Reactor.h
@@ -0,0 +1,156 @@
+/* -*- C++ -*- */
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// ace
+//
+// = FILENAME
+// TP_Reactor.h
+//
+// = AUTHOR
+// Irfan Pyarali
+//
+// ============================================================================
+
+#if !defined (ACE_TP_REACTOR_H)
+#define ACE_TP_REACTOR_H
+
+#include "ace/Select_Reactor.h"
+
+class ACE_Export ACE_EH_Dispatch_Info
+{
+ // = TITLE
+ //
+ // This structure contains information of the activated event
+ // handler.
+public:
+
+ ACE_EH_Dispatch_Info (void);
+
+ void set (ACE_HANDLE handle,
+ ACE_Event_Handler *event_handler,
+ ACE_Reactor_Mask mask,
+ ACE_EH_PTMF callback);
+
+ void reset (void);
+
+ int dispatch (void) const;
+
+ ACE_HANDLE handle_;
+ ACE_Event_Handler *event_handler_;
+ ACE_Reactor_Mask mask_;
+ ACE_EH_PTMF callback_;
+
+ int dispatch_;
+};
+
+class ACE_Export ACE_TP_Reactor : public ACE_Select_Reactor
+{
+ // = TITLE
+ //
+ // Specialization of Select Reactor to support thread-pool based
+ // event dispatching.
+ //
+ // = DESCRIPTION
+ //
+ // One of the short comings of the Select_Reactor in ACE is that
+ // it did not support a thread pool based event dispatching
+ // model, similar to the one in WFMO_Reactor. In
+ // Select_Reactor, only thread can be blocked in handle_events()
+ // at any given time.
+ //
+ // A new Reactor has been added to ACE that removes this
+ // short-coming. TP_Reactor is a specialization of Select
+ // Reactor to support thread-pool based event dispatching. This
+ // Reactor takes advantage of the fact that events reported by
+ // select() are persistent if not acted upon immediately. It
+ // works by remembering the event handler that just got
+ // activated, releasing the internal lock (so that some other
+ // thread can start waiting in the event loop) and then
+ // dispatching the event handler outside the context of the
+ // Reactor lock.
+ //
+ // This Reactor is best suited for situations when the callbacks
+ // to event handlers can take arbitrarily long and/or a number
+ // of threads are available to run the event loops.
+ //
+ // Note that callback code in Event Handlers
+ // (e.g. Event_Handler::handle_input) does not have to be
+ // modified or made thread-safe for this Reactor. This is
+ // because an activated Event Handler is suspended in the
+ // Reactor before the upcall is made and resumed after the
+ // upcall completes. Therefore, one Event Handler cannot be
+ // called by multiple threads simultaneously.
+public:
+
+ // = Initialization and termination methods.
+
+ ACE_TP_Reactor (ACE_Sig_Handler * = 0,
+ ACE_Timer_Queue * = 0);
+ // Initialize <ACE_TP_Reactor> with the default size.
+
+ ACE_TP_Reactor (size_t size,
+ int restart = 0,
+ ACE_Sig_Handler * = 0,
+ ACE_Timer_Queue * = 0);
+ // Initialize <ACE_TP_Reactor> with size <size>.
+
+ // = Event loop drivers.
+
+ virtual int handle_events (ACE_Time_Value *max_wait_time = 0);
+ // This event loop driver that blocks for <max_wait_time> before
+ // returning. It will return earlier if timer events, I/O events,
+ // or signal events occur. Note that <max_wait_time> can be 0, in
+ // which case this method blocks indefinitely until events occur.
+ //
+ // <max_wait_time> is decremented to reflect how much time this call
+ // took. For instance, if a time value of 3 seconds is passed to
+ // handle_events and an event occurs after 2 seconds,
+ // <max_wait_time> will equal 1 second. This can be used if an
+ // application wishes to handle events for some fixed amount of
+ // time.
+ //
+ // Returns the total number of <ACE_Event_Handler>s that were
+ // dispatched, 0 if the <max_wait_time> elapsed without dispatching
+ // any handlers, or -1 if something goes wrong.
+
+ static void no_op_sleep_hook (void *);
+ // Called from handle events
+
+ ACE_ALLOC_HOOK_DECLARE;
+ // Declare the dynamic allocation hooks.
+
+protected:
+ // = Internal methods that do the actual work.
+
+ virtual int dispatch_io_set (int number_of_active_handles,
+ int& number_dispatched,
+ int mask,
+ ACE_Handle_Set& dispatch_mask,
+ ACE_Handle_Set& ready_mask,
+ ACE_EH_PTMF callback);
+ // Overwrites ACE_Select_Reactor::dispatch_io_set() to *not*
+ // dispatch any event handlers. The information of one activated
+ // event handler is stored away, so that the event handler can be
+ // dispatch later.
+
+ virtual int notify_handle (ACE_EH_Dispatch_Info &dispatch_info);
+ // Notify the appropriate <callback> in the context of the <eh>
+ // associated with <handle> that a particular event has occurred.
+
+ ACE_EH_Dispatch_Info dispatch_info_;
+ // Dispatch information of the activated event handler
+
+private:
+ ACE_TP_Reactor (const ACE_TP_Reactor &);
+ ACE_TP_Reactor &operator = (const ACE_TP_Reactor &);
+ // Deny access since member-wise won't work...
+};
+
+#if defined (__ACE_INLINE__)
+#include "ace/TP_Reactor.i"
+#endif /* __ACE_INLINE__ */
+
+#endif /* ACE_TP_REACTOR_H */