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