benchmarks compiles with clang
[c11concurrency-benchmarks.git] / mabain / src / mbt_base.h
1 /**
2  * Copyright (C) 2017 Cisco Inc.
3  *
4  * This program is free software: you can redistribute it and/or  modify
5  * it under the terms of the GNU General Public License, version 2,
6  * as published by the Free Software Foundation.
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, see <http://www.gnu.org/licenses/>.
15  */
16
17 // @author Changxue Deng <chadeng@cisco.com>
18
19 #ifndef __DBTraverseBase_H__
20 #define __DBTraverseBase_H__
21
22 #include "db.h"
23 #include "dict.h"
24
25 namespace mabain {
26
27 typedef struct _DBTraverseNode
28 {
29     size_t edge_offset;
30     size_t node_offset;
31     size_t node_link_offset;
32     int    node_size;
33     size_t edgestr_offset;
34     size_t edgestr_link_offset;
35     int    edgestr_size;
36     size_t data_offset;
37     size_t data_link_offset;
38     int    data_size;
39     int    buffer_type;
40 } DBTraverseNode;
41
42 // An abstract base class for writer to traverse mabain DB 
43 class DBTraverseBase
44 {
45 public:
46     DBTraverseBase(const DB &db);
47     ~DBTraverseBase();
48
49     // Traverse DB via DFS
50     void TraverseDB(int arg = 0);
51
52 protected:
53     virtual void DoTask(int arg, DBTraverseNode &dbt_node) = 0;
54     void BufferCopy(size_t offset_dst, uint8_t *ptr_dst,
55                     size_t offset_src, const uint8_t *ptr_src,
56                     int size, DRMBase *drm);
57
58     // DBTraverseBase does not own these objects or pointers.
59     const DB &db_ref;
60     Dict *dict;
61     DictMem *dmm;
62     IndexHeader *header;
63     FreeList *index_free_lists;
64     FreeList *data_free_lists;
65     LockFree *lfree;
66
67     // Used for tracking index and data sizes that have been traversed.
68     size_t   index_size;
69     size_t   data_size;
70
71 private:
72     void GetAlignmentSize(DBTraverseNode &dbt_node) const;
73     void ResizeRWBuffer(int size);
74
75     uint8_t *rw_buffer; 
76     int      rw_buffer_size;
77 };
78
79 }
80
81 #endif