ddc
ServerThread.h
Go to the documentation of this file.
1 //-*- Mode: C++ -*-
2 // DDC originally by Alexey Sokirko
3 // Changes and modifications 2011-2016 by Bryan Jurish
4 //
5 // This file is part of DDC.
6 //
7 // DDC is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // DDC is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Lesser General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with DDC. If not, see <http://www.gnu.org/licenses/>.
19 //
20 #ifndef DDC_SERVER_THREAD_H
21 #define DDC_SERVER_THREAD_H
22 
23 #include "Server.h"
24 #include "../CommonLib/ddcThread.h"
25 #include "../CommonLib/ddcThreadQueue.h"
26 
27 //======================================================================
28 // globals
29 
31 #define DDC_DEFAULT_THREAD_POOL_SIZE 4
32 
33 //======================================================================
36 {
37 public:
38  //--------------------------------------------------------------
39  // data
40 
42  size_t m_ThreadId;
43 
45  string m_Label;
46 
49 
52 
55 
56 public:
57  //--------------------------------------------------------------
58  // methods
59 
61  CDDCServerThread(CDDCServer* Parent=NULL, size_t ThreadId=1);
62 
64  virtual ~CDDCServerThread();
65 
69  virtual void* run();
70 };
71 
72 
73 //======================================================================
76 {
77 public:
80 
82  vector<CDDCServerThread*> m_Workers;
83 
85  pthread_mutex_t m_mutex;
86 
87 public:
88  //--------------------------------------------------------------
89  // Constructors etc.
90 
93 
96 
98  virtual ~CDDCServerThreadPool();
99 
100 public:
101  //--------------------------------------------------------------
102  // API
103 
107  virtual void start(CDDCServer *Server, size_t nWorkers=DDC_DEFAULT_THREAD_POOL_SIZE, size_t maxQueueSize=DDC_DEFAULT_THREAD_QUEUE_SIZE);
108 
110  virtual void stop(void);
111 
113  inline size_t size(void) const
114  { return m_Workers.size(); };
115 
117  inline bool started(void) const
118  { return (size() != 0); };
119 };
120 
121 
122 
123 #endif /* DDC_SERVER_THREAD_H */
124 
125 /*--- emacs style variables ---
126  * Local Variables:
127  * mode: C++
128  * c-file-style: "ellemtel"
129  * c-basic-offset: 4
130  * tab-width: 8
131  * indent-tabs-mode: nil
132  * End:
133  */
generic thread-safe queue template class should use POD or pointer types for message-type T ...
Definition: ddcThreadQueue.h:36
#define SOCKET
Definition: string_socket.h:66
size_t nWorkers
Definition: ddc_daemon.cpp:58
generic pthread wrapper class
Definition: ddcThread.h:59
CDDCServer * m_Server
Definition: ServerThread.h:51
virtual int start()
Definition: ddcThread.cpp:75
ddcThreadQueue< int > m_Queue
Definition: ServerThread.h:79
string m_Label
Definition: ServerThread.h:45
pthread_mutex_t m_mutex
Definition: ServerThread.h:85
size_t m_ThreadId
Definition: ServerThread.h:42
int m_Client
Definition: ServerThread.h:54
Definition: Server.h:46
size_t size(void) const
Definition: ServerThread.h:113
#define DDC_DEFAULT_THREAD_QUEUE_SIZE
Definition: ddcThreadQueue.h:29
high-level class used by CDDCServer for a per-client thread pool
Definition: ServerThread.h:75
low-level class implementing a single CDDCServer per-client worker thread
Definition: ServerThread.h:35
CDDCServer * m_Parent
Definition: ServerThread.h:48
#define DDC_DEFAULT_THREAD_POOL_SIZE
Definition: ServerThread.h:31
bool started(void) const
Definition: ServerThread.h:117
virtual void * run()
Definition: ServerThread.cpp:47
virtual ~CDDCServerThread()
Definition: ServerThread.cpp:38
CDDCServerThread(CDDCServer *Parent=NULL, size_t ThreadId=1)
Definition: ServerThread.cpp:28
vector< CDDCServerThread * > m_Workers
Definition: ServerThread.h:82