Debian Codegraph @

src/tools/davix_taskqueue.hpp

raw
1 /*
2 * This File is part of Davix, The IO library for HTTP based protocols
3 * Copyright (C) CERN 2013
4 * Author: Kwong Tat Cheung <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22 #ifndef DAVIX_TASKQUEUE_HPP
23 #define DAVIX_TASKQUEUE_HPP
24
25 #include <davix.hpp>
26 #include <tools/davix_mutex.hpp>
27 #include <tools/davix_op.hpp>
28 #include <pthread.h>
29 #include <tools/davix_tool_params.hpp>
30
31 #define DEFAULT_WAIT_TIME 30
32 #define MAX_NUM_OF_LISTING_OPS 2000000
33
34 namespace Davix{
35
36 namespace QueueType{
37 enum QueueType{
38 // first in first out
39 FIFO,
40 // last in first out
41 LIFO
42 };
43 }
44
45 class DavixTaskQueue{
46 public:
47 DavixTaskQueue();
48 DavixTaskQueue(const Tool::OptParams& opts, QueueType::QueueType queueType);
49 int pushOp(DavixOp* op);
50 DavixOp* popOp();
51 int getSize();
52 bool isEmpty();
53 void shutdown();
54 bool isStopped();
55 private:
56 std::deque<DavixOp*> taskQueue;
57 pthread_mutex_t tq_mutex;
58 pthread_cond_t popOpConvar;
59 pthread_cond_t pushOpConvar;
60 bool _shutdown;
61 bool _no_cap;
62 QueueType::QueueType _queueType;
63 };
64
65 }
66
67 #endif // DAVIX_TASKQUEUE_HPP