b483f7c5ee56d25eb33fed46b15e3601131f682b
[com/gs-lite.git] / include / hfta / host_tuple.h
1 /* ------------------------------------------------\r
2 Copyright 2014 AT&T Intellectual Property\r
3    Licensed under the Apache License, Version 2.0 (the "License");\r
4    you may not use this file except in compliance with the License.\r
5    You may obtain a copy of the License at\r
6 \r
7      http://www.apache.org/licenses/LICENSE-2.0\r
8 \r
9    Unless required by applicable law or agreed to in writing, software\r
10    distributed under the License is distributed on an "AS IS" BASIS,\r
11    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12    See the License for the specific language governing permissions and\r
13    limitations under the License.\r
14  ------------------------------------------- */\r
15 \r
16 #ifndef HOST_TUPLE_H\r
17 #define HOST_TUPLE_H\r
18 \r
19 #include <stdlib.h>\r
20 #include "fta.h"\r
21 \r
22 \r
23 /* vstring_type specifis the format in which vstirng data is stored\r
24 we will use the reserved field of vstirng to store the vstring_type\r
25 vstring_type desclaration should probably be in host.h\r
26 */\r
27 enum vstring_type {\r
28         // data immediately follows the tuple fields\r
29         PACKED,\r
30         // data allocated on a heap in one block\r
31         // offset is interpreted as pointer to data\r
32         INTERNAL,\r
33         // vstring is a shallow copy of another vstring (or its part)\r
34         // offset is interpreted as pointer to data\r
35         SHALLOW_COPY,\r
36         // data allocated on a heap as single linked list of data blocks\r
37         // offset is interpreted as pointer to the head of the list\r
38         // list node has the following format\r
39         // {int length, node* next) followed by the data block\r
40         SLIST,\r
41         // data allocated on a heap as double linked list of data blocks\r
42         // offset is interpreted as pointer to the head of the list\r
43         // list node has the following format\r
44         // {int length, node* next, node* prev) followed by the data block\r
45         DLIST\r
46 };\r
47 \r
48 struct host_tuple {\r
49 \r
50         size_t tuple_size;              // tuple size in bytes\r
51         void* data;                             // tuple data\r
52         unsigned int channel;   // input or output channel the tuple should go to\r
53         bool heap_resident;     // indicates whether tuple is heap or stack resident\r
54 \r
55         // we need to use reference counting for query plans that are DAGs\r
56 #ifdef PLAN_DAG\r
57         int* ref_cnt;\r
58         host_tuple() {ref_cnt = NULL;}\r
59 #endif\r
60 \r
61 \r
62         inline void free_tuple() {\r
63                 if (heap_resident) {\r
64                         #ifdef PLAN_DAG\r
65                                 if (!ref_cnt)\r
66                                         free(data);\r
67                                 else if (*ref_cnt == 0) {\r
68                                         free(data);\r
69                                         free(ref_cnt);\r
70                                 } else {\r
71                                         (*ref_cnt)--;\r
72                                 }\r
73                         #else\r
74                                 free(data);\r
75                         #endif\r
76                 }\r
77         }\r
78 \r
79 };\r
80 \r
81 #endif  // HOST_TUPLE_H\r