1 /* Copyright (C) 2014 InfiniDB, Inc.
2 
3    This program is free software; you can redistribute it and/or
4    modify it under the terms of the GNU General Public License
5    as published by the Free Software Foundation; version 2 of
6    the License.
7 
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12 
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
16    MA 02110-1301, USA. */
17 
18 #ifndef FILEBLOCKREQUESTQUEUE_H
19 #define FILEBLOCKREQUESTQUEUE_H
20 
21 /***************************************************************************
22  *
23  *   $Id: fileblockrequestqueue.h 2035 2013-01-21 14:12:19Z rdempsey $
24  *
25  *   jrodriguez@calpont.com   *
26  *                                                                         *
27 ***************************************************************************/
28 
29 
30 #include <deque>
31 #include <boost/thread.hpp>
32 #include <boost/thread/condition.hpp>
33 #include <iostream>
34 #include "filerequest.h"
35 
36 
37 /**
38 	@author Jason Rodriguez <jrodriguez@calpont.com>
39 */
40 
41 /**
42  * @brief definition of the block request queue as stl std::priority_queue
43  **/
44 namespace dbbc
45 {
46 
47 typedef std::deque<fileRequest*> fileBlockRequestQueue_t;
48 
49 /**
50  * @brief class to hold requests for disk blocks in a queue. sorted by the size of a request
51  **/
52 
53 
54 class fileBlockRequestQueue
55 {
56 
57 public:
58 
59     /**
60      * @brief default ctor
61      **/
62     fileBlockRequestQueue();
63 
64     /**
65      * @brief dtor
66      **/
67     virtual ~fileBlockRequestQueue();
68 
69     /**
70      * @brief add a request to the queue
71      **/
72     int push(fileRequest& blk);
73 
74     /**
75      * @brief get the next request from the queue and delete it from the queue
76      **/
77     fileRequest* pop(void);
78 
79     /**
80      * @brief true if no reuquests are in the queue. false if there are requests in the queue
81      **/
82     bool empty() const;
83 
84     /**
85      * @brief number of requests in the queue
86      **/
size()87     uint32_t size() const
88     {
89         return queueSize;
90     }
91 
92     /**
93      * @brief queue will stop accecpting requests in preparation for the dtor
94      **/
95     void stop();
96 
97 protected:
98     boost::mutex mutex;
99     boost::condition notEmpty;
100     fileBlockRequestQueue_t fbQueue;
101     uint32_t queueSize;
102     uint32_t readersWaiting;
103 
104 private:
105     // do not implement
fileBlockRequestQueue(const fileBlockRequestQueue & Q)106     fileBlockRequestQueue(const fileBlockRequestQueue& Q) {}
107     const fileBlockRequestQueue& operator=(const fileBlockRequestQueue& Q);
108 
109     /**
110      * @brief pointer to the next request to be popped from the queue
111      **/
112     fileRequest* top() const;
113 
114 
115 };
116 }
117 #endif
118