forked from heavyai/heavydb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractBuffer.h
124 lines (96 loc) · 3.86 KB
/
AbstractBuffer.h
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
* @file AbstractBuffer.h
* @author Steven Stewart <steve@map-d.com>
* @author Todd Mostak <todd@map-d.com>
*/
#ifndef DATAMGR_MEMORY_ABSTRACTBUFFER_H
#define DATAMGR_MEMORY_ABSTRACTBUFFER_H
#include "../Shared/types.h"
#include "../Shared/sqltypes.h"
#include "MemoryLevel.h"
#include "Encoder.h"
#ifdef BUFFER_MUTEX
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>
#endif
namespace Data_Namespace {
/**
* @class AbstractBuffer
* @brief An AbstractBuffer is a unit of data management for a data manager.
*/
//enum BufferType {FILE_BUFFER, CPU_BUFFER, GPU_BUFFER};
class AbstractBuffer {
public:
AbstractBuffer (const int deviceId): encoder(0), hasEncoder(0), size_(0), isDirty_(false), isAppended_(false),isUpdated_(false), deviceId_(deviceId) {}
AbstractBuffer (const int deviceId, const SQLTypeInfo sqlType): size_(0),isDirty_(false), isAppended_(false),isUpdated_(false), deviceId_(deviceId){
initEncoder(sqlType);
}
virtual ~AbstractBuffer() { if (hasEncoder) delete encoder; }
virtual void read(int8_t * const dst, const size_t numBytes, const size_t offset = 0, const MemoryLevel dstBufferType = CPU_LEVEL, const int dstDeviceId = -1) = 0;
virtual void write(int8_t * src, const size_t numBytes, const size_t offset = 0, const MemoryLevel srcBufferType = CPU_LEVEL, const int srcDeviceId = -1) = 0;
virtual void reserve(size_t numBytes) = 0;
virtual void append(int8_t * src, const size_t numBytes, const MemoryLevel srcBufferType = CPU_LEVEL, const int deviceId = -1) = 0;
virtual int8_t* getMemoryPtr() = 0;
virtual size_t pageCount() const = 0;
virtual size_t pageSize() const = 0;
virtual size_t size() const = 0;
virtual size_t reservedSize() const = 0;
//virtual size_t used() const = 0;
virtual int getDeviceId() const {return deviceId_;}
virtual MemoryLevel getType() const = 0;
// Next three methods are dummy methods so FileBuffer does not implement these
virtual inline int pin() {return 0;}
virtual inline int unPin() {return 0;}
virtual inline int getPinCount() {return 0;}
virtual inline bool isDirty() const {return isDirty_;}
virtual inline bool isAppended() const {return isAppended_;}
virtual inline bool isUpdated() const {return isUpdated_;}
virtual inline void setDirty() {
isDirty_ = true;
}
virtual inline void setUpdated() {
isUpdated_ = true;
isDirty_ = true;
}
virtual inline void setAppended() {
isAppended_ = true;
isDirty_ = true;
}
void setSize(const size_t size) {
size_ = size;
}
void clearDirtyBits() {
isAppended_ = false;
isUpdated_ = false;
isDirty_ = false;
}
void initEncoder(const SQLTypeInfo tmpSqlType) {
hasEncoder = true;
sqlType = tmpSqlType;
encoder = Encoder::Create(this,sqlType);
}
void syncEncoder(const AbstractBuffer *srcBuffer) {
hasEncoder = srcBuffer->hasEncoder;
if (hasEncoder) {
if (encoder == 0) { // Encoder not initialized
initEncoder(srcBuffer->sqlType);
}
encoder->copyMetadata(srcBuffer->encoder);
}
}
Encoder * encoder;
bool hasEncoder;
SQLTypeInfo sqlType;
protected:
size_t size_;
bool isDirty_;
bool isAppended_;
bool isUpdated_;
int deviceId_;
#ifdef BUFFER_MUTEX
boost::shared_mutex readWriteMutex_;
boost::shared_mutex appendMutex_;
#endif
};
} // Data_Namespace
#endif // DATAMGR_MEMORY_ABSTRACTBUFFER_H