Fixed newline characters throughout the code
[com/gs-lite.git] / src / lib / gscphost / include / gscpipc.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  * gscpipc.h:: defines the interface of the IPC channels used in
17  * the GS-lite framework to communicate tuples between different
18  * processes
19  */
20
21 #ifndef GSCPIPC_H
22 #define GSCPIPC_H
23
24 #include "gsconfig.h"
25 #include "gstypes.h"
26 #include "fta.h"
27
28 #define RESERVED_FOR_LOW_LEVEL 0
29
30 #define FTACALLBACK 1
31
32 extern gs_uint64_t intupledrop;
33 extern gs_uint64_t outtupledrop;
34 extern gs_uint64_t intuple;
35 extern gs_uint64_t outtuple;
36 extern gs_uint64_t inbytes;
37 extern gs_uint64_t outbytes;
38 extern gs_uint64_t cycles;
39
40
41 /* shared ringbuffer data structure used */
42
43 #if defined(__sparc__) && defined(__sun__)
44 #define ALIGN64
45 #endif
46
47 struct tuple {
48     FTAID f;
49     gs_int32_t  sz;
50     gs_uint32_t  next;
51 #ifdef ALIGN64
52     gs_uint32_t  alignment;
53 #endif
54     gs_int8_t  data[1];
55 }__attribute__ ((__packed__));
56
57 struct ringbuf {
58     gs_uint32_t   mqhint;
59     gs_uint32_t   writer;
60     gs_uint32_t   reader;
61     gs_uint32_t   end;
62     gs_int32_t  length;
63 #ifdef ALIGN64
64     gs_uint32_t  alignment;
65 #endif
66     FTAID  srcid;
67     FTAID  destid;
68     gs_int8_t  start[1];
69 }__attribute__ ((__packed__));
70
71 /* adds a buffer to the end of the sidequeue*/
72 gs_retval_t sidequeue_append(FTAID ftaid, gs_sp_t buf, gs_int32_t length);
73
74 /* removes a buffer from the top of the sidequeue*/
75 gs_retval_t sidequeue_pop(FTAID * ftaid, gs_sp_t buf, gs_int32_t * length);
76
77 /*
78  *used to contact the clearinghouse process returns the MSGID of
79  * the current process negative result indicates a problem
80  */
81
82 gs_retval_t  gscpipc_init(gs_int32_t  clearinghouse);
83
84 /* used to disassociate process from clearinghouse */
85 gs_retval_t  gscpipc_free();
86
87 /* sends a message to a process */
88 gs_retval_t  gscpipc_send(FTAID f, gs_int32_t  operation, gs_sp_t buf, gs_int32_t  length, gs_int32_t  block);
89
90 /* retrieve a message buf has to be at least of size MAXMSGSZ returns 0
91  if no message is available -1 on an error and 1 on sucess*/
92 gs_retval_t  gscpipc_read(FTAID * f, gs_int32_t  * operation, gs_sp_t buf, gs_int32_t  * lenght, gs_int32_t  block);
93
94 /* allocate a ringbuffer which allows receiving data from
95  * the other process returns 0 if didn't succeed.
96  * returns an existing buffer if it exists  and increments the refcnt*/
97
98 struct ringbuf * gscpipc_createshm(FTAID f, gs_int32_t  length);
99
100 /* finds a ringbuffer to send which was allocated by
101  * gscpipc_creatshm and return 0 on an error */
102
103 struct ringbuf * gscpipc_getshm(FTAID f);
104
105 /* frees shared memory to a particular proccess identified
106  * by ftaid if reference counter reaches 0
107  */
108 gs_retval_t  gscpipc_freeshm(FTAID f);
109
110
111 /* returns true if on any sending ringbuffer the mqhint bit is true
112  * can be used in lfta rts to indicate that the message queue should
113  * be checked.
114  */
115
116 gs_retval_t  gscpipc_mqhint();
117
118 /* Access macros for ringbuffer */
119
120 #ifdef ALIGN64
121 #define UP64(x) ((((x)+7)/8)*8)
122 #else
123 #define UP64(x) x
124 #endif
125
126 #define CURWRITE(buf)  ((struct tuple *)(&((buf)->start[(buf)->writer])))
127 #define ADVANCEWRITE(buf)  CURWRITE(buf)->next=\
128 ((buf)->end > ((buf)->writer+UP64(CURWRITE(buf)->sz))+sizeof(struct tuple)-1)\
129 ? ((buf)->writer+UP64(CURWRITE(buf)->sz)+sizeof(struct tuple)-1) : 0; \
130 (buf)->writer=CURWRITE(buf)->next;
131 #define CURREAD(buf)  ((struct tuple *)(&((buf)->start[(buf)->reader])))
132 #define ADVANCEREAD(buf) (buf)->reader=\
133 CURREAD(buf)->next
134 #define UNREAD(buf) ((buf)->reader != (buf)->writer)
135 #define SPACETOWRITE(buf)   ((((buf)->reader <= (buf)->writer) \
136 && ((buf)->reader+(buf)->end-(buf)->writer) > MAXTUPLESZ)\
137 || (((buf)->reader > (buf)->writer) && (((buf)->reader-(buf)->writer)>MAXTUPLESZ)))
138 #define HOWFULL(buf) (((((buf)->writer)-(buf)->reader)%((buf)->end)*1000)/((buf)->end))
139 /* conservative estimate of how many tuples of size tuplesz fit in a ringbuffer */
140 #define TUPLEFIT(buf,tuplesz) ((((((buf)->writer)-(buf)->reader)%((buf)->end))-MAXTUPLESZ)/ \
141 ((UP64(tuplesz))+sizeof(struct tuple)-1))
142 #endif