blob: d9b12e9f478dc98d8e136e592b012ae2188c77c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/* tnt/poller.h
* Copyright (C) 2005 Tommi Maekitalo
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* is provided AS IS, WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and
* NON-INFRINGEMENT. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef TNT_POLLER_H
#define TNT_POLLER_H
#include "tnt/job.h"
#include <cxxtools/dynbuffer.h>
#include <cxxtools/thread.h>
#include <sys/poll.h>
namespace tnt
{
class Poller : public cxxtools::AttachedThread
{
Jobqueue& queue;
int notify_pipe[2];
typedef std::deque<Jobqueue::JobPtr> jobs_type;
jobs_type current_jobs;
cxxtools::Dynbuffer<pollfd> pollfds;
jobs_type new_jobs;
cxxtools::Mutex mutex;
int poll_timeout;
void append_new_jobs();
void append(Jobqueue::JobPtr& job);
void dispatch();
void remove(jobs_type::size_type n);
public:
Poller(Jobqueue& q);
virtual void run();
void doStop();
void addIdleJob(Jobqueue::JobPtr job);
};
}
#endif // TNT_POLLER_H
|