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
PageCircularBuffer.h
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 PAGECIRCULARBUFFER_H
20 #define PAGECIRCULARBUFFER_H
21 
22 #include "PDBPage.h"
23 #include "PDBLogger.h"
24 #include <pthread.h>
25 #include <memory>
26 using namespace std;
28 typedef shared_ptr<PageCircularBuffer> PageCircularBufferPtr;
29 
38 public:
39  PageCircularBuffer(unsigned int bufferSize, pdb::PDBLoggerPtr logger);
41 
46  int addPageToTail(PDBPagePtr page);
47 
54  PDBPagePtr popPageFromHead();
55 
59  bool isFull();
60 
64  bool isEmpty();
65 
69  unsigned int getSize();
70 
75  void close();
76 
80  void open();
81 
82 
86  bool isClosed() {
87  return closed;
88  }
89 
90 protected:
95  return pageArray;
96  }
97 
101  unsigned int getPageArrayHead() {
102  return pageArrayHead;
103  }
104 
108  unsigned int getPageArrayTail() {
109  return pageArrayTail;
110  }
111 
115  unsigned int getMaxArraySize() {
116  return maxArraySize;
117  }
118 
122  int initArray();
123 
124 private:
127  unsigned int maxArraySize;
128  unsigned int pageArrayHead;
129  unsigned int pageArrayTail;
130  pthread_mutex_t mutex;
131  pthread_mutex_t addPageMutex;
132  pthread_cond_t cond;
133  bool closed;
134 };
135 
136 
137 #endif /* PAGECIRCULARBUFFER_H */
shared_ptr< PDBPage > PDBPagePtr
Definition: PDBPage.h:32
pthread_mutex_t addPageMutex
unsigned int pageArrayTail
unsigned int pageArrayHead
pthread_mutex_t mutex
PDBPagePtr * getPageArray()
unsigned int getMaxArraySize()
unsigned int getPageArrayHead()
std::shared_ptr< PDBLogger > PDBLoggerPtr
Definition: PDBLogger.h:40
unsigned int getPageArrayTail()
pdb::PDBLoggerPtr logger
shared_ptr< PageCircularBuffer > PageCircularBufferPtr