Merge branch 'master' into jwi-bcc64xsingletonwarning
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Concurrency.h
blob18c4571d2eaf986d8c82873cf8fdc9629a26cef5
1 /* -*- c++ -*- */
2 #ifndef JAWS_CONCURRENCY_H
3 #define JAWS_CONCURRENCY_H
5 #include "ace/Singleton.h"
7 #if !defined (ACE_LACKS_PRAGMA_ONCE)
8 # pragma once
9 #endif /* ACE_LACKS_PRAGMA_ONCE */
11 #include "ace/Task.h"
12 #include "ace/Synch_Traits.h"
14 #include "JAWS/Export.h"
15 #include "JAWS/Jaws_IO.h"
17 class JAWS_Data_Block;
18 class JAWS_Dispatch_Policy;
19 class JAWS_Reaper;
21 class JAWS_Export JAWS_Concurrency_Base : public ACE_Task<ACE_SYNCH>
22 // = TITLE
23 // Base class for different concurrency models
25 // = DESCRIPTION
26 // Provides a default implementaion of the virtual put() method
27 // which calls putq(), but can be overloaded to do something
28 // synchronously, such as call put_next().
31 public:
32 JAWS_Concurrency_Base ();
33 ~JAWS_Concurrency_Base ();
35 virtual int put (ACE_Message_Block *mb, ACE_Time_Value *tv = 0);
36 virtual int svc ();
38 virtual int svc_loop (JAWS_Data_Block *db);
39 // in thread pool, this is an infinite loop
40 // in thread per request, it is a single iteration
42 virtual int svc_hook (JAWS_Data_Block *db);
43 // does the work of following the pipeline tasks
45 virtual int activate_hook ();
46 // callback for IO_Handler when accept completes
48 virtual ACE_Message_Block *singleton_mb ();
50 protected:
51 int mb_acquired_;
52 ACE_Message_Block *mb_;
53 JAWS_Reaper *reaper_;
54 ACE_SYNCH_MUTEX lock_;
57 class JAWS_Export JAWS_Dispatcher
58 // = TITLE
59 // The class that is responsible to delivering events to the
60 // appropriate concurrency mechanism.
62 // = DESCRIPTION
63 // JAWS_IO_Handler calls into the dispatcher so that the completed
64 // IO can find a thread to take care of it.
66 public:
67 JAWS_Dispatcher ();
69 int dispatch (ACE_Message_Block *mb);
70 JAWS_Dispatch_Policy *policy ();
71 JAWS_Dispatch_Policy *policy (JAWS_Dispatch_Policy *p);
73 private:
74 JAWS_Dispatch_Policy *policy_;
77 class JAWS_Export JAWS_Thread_Pool_Task : public JAWS_Concurrency_Base
78 // = TITLE
79 // Used to implement Thread Pool Concurrency Strategy
81 // = DESCRIPTION
82 // This task is created to hold a pool of threads that receive
83 // requests through the message queue.
85 public:
86 virtual int make (long flags, int nthreads, int maxthreads);
87 // Initiate the thread_pool task
89 private:
90 long flags_;
91 int nthreads_;
92 int maxthreads_;
95 class JAWS_Export JAWS_Thread_Per_Task : public JAWS_Concurrency_Base
96 // = TITLE
97 // Used to implement Thread Per Request Concurrency Strategy
99 // = DESCRIPTION
100 // As each new message arrives from the queue, a new thread is
101 // spawned to handle it. This is done by overloading put to call
102 // activate.
104 public:
105 virtual int make (long flags, int maxthreads);
106 // Initiate the thread_per task
108 virtual int put (ACE_Message_Block *mb, ACE_Time_Value *tv = 0);
110 virtual int svc_loop (JAWS_Data_Block *db);
111 // a single iteration
113 virtual int activate_hook ();
114 // callback for IO_Handler when accept completes
116 private:
117 long flags_;
118 int maxthreads_;
121 typedef ACE_Singleton<JAWS_Dispatcher, ACE_SYNCH_MUTEX>
122 JAWS_Dispatcher_Singleton;
124 typedef ACE_Singleton<JAWS_Thread_Pool_Task, ACE_SYNCH_MUTEX>
125 JAWS_Thread_Pool_Singleton;
127 typedef ACE_Singleton<JAWS_Thread_Per_Task, ACE_SYNCH_MUTEX>
128 JAWS_Thread_Per_Singleton;
130 #endif /* !defined (JAWS_CONCURRENCY_H) */