A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
PageCircularBufferIterator.cc
Go to the documentation of this file.
1 /*****************************************************************************
2  * *
3  * Copyright 2018 Rice University *
4  * *
5  * Licensed under the Apache License, Version 2.0 (the "License"); *
6  * you may not use this file except in compliance with the License. *
7  * You may obtain a copy of the License at *
8  * *
9  * http://www.apache.org/licenses/LICENSE-2.0 *
10  * *
11  * Unless required by applicable law or agreed to in writing, software *
12  * distributed under the License is distributed on an "AS IS" BASIS, *
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14  * See the License for the specific language governing permissions and *
15  * limitations under the License. *
16  * *
17  *****************************************************************************/
18 
19 #ifndef PAGECIRCULARBUFFERITERATOR_CC
20 #define PAGECIRCULARBUFFERITERATOR_CC
21 
22 #include "PDBDebug.h"
24 #include "PageCircularBuffer.h"
25 #include <iostream>
26 using namespace std;
28  PageCircularBufferPtr buffer,
29  pdb::PDBLoggerPtr logger) {
30  this->id = id;
31  this->buffer = buffer;
32  this->logger = logger;
33 }
34 
36 
37 // will block when queue is empty and will remove the page from queue before return;
39  return this->buffer->popPageFromHead();
40 }
41 
42 /* Potential Bug: in certain cases, two iterators may simultaneously find that the buffer is closed,
43  * but there are still data in the buffer. In this case, one iterator will not be able
44  * to get a page, although it says hasNext() == true.
45  *
46  * Solution 1: wait for all elements in the queue to be fetched, then close the queue;
47  * Solution 2: allow that you may get a nullptr by calling next(), and it is your responsibility to
48  * check that!
49  *
50  * Now, we go solution 2, please let me know if this is a problem!
51  */
53  bool ret = ((!this->buffer->isClosed()) || (!this->buffer->isEmpty()));
54  PDB_COUT << "iter Id=" << this->id << ",ret=" << ret << "\n";
55  return ret;
56 }
57 
59  return this->id;
60 }
61 
62 
63 #endif
shared_ptr< PDBPage > PDBPagePtr
Definition: PDBPage.h:32
PageCircularBufferIterator(unsigned int id, PageCircularBufferPtr buffer, pdb::PDBLoggerPtr logger)
#define PDB_COUT
Definition: PDBDebug.h:31
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
shared_ptr< PageCircularBuffer > PageCircularBufferPtr