Fix 32392 [2.44 Regression] gprofng fails to build on i686-linux-gnu
[binutils-gdb.git] / gprofng / src / ipcio.h
blob7cef74311b8c7e5580d4473f2abc64fcb899544c
1 /* Copyright (C) 2021-2024 Free Software Foundation, Inc.
2 Contributed by Oracle.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 /* Defines the external interface between er_ipc and the routines */
23 #ifndef _IPCIO_H
24 #define _IPCIO_H
25 #include <pthread.h>
26 #include "gp-defs.h"
27 #include "StringBuilder.h"
29 class DbeThreadPool;
30 typedef long long DbeObj;
31 typedef void *Object;
32 typedef char *String;
34 #define BUFFER_SIZE_SMALL 512
35 #define BUFFER_SIZE_MEDIUM 512
36 #define BUFFER_SIZE_LARGE 1024*1024
38 #define REQUEST_HAS_NO_BODY 0xFFFFFFFF
39 #define RESPONSE_STATUS_DEFAULT 0
40 #define RESPONSE_STATUS_SUCCESS 1
41 #define RESPONSE_STATUS_FAILURE 2
42 #define RESPONSE_STATUS_CANCELLED 3
43 #define RESPONSE_STATUS_ERROR 4
45 #define RESPONSE_TYPE_ACK 0
46 #define RESPONSE_TYPE_PROGRESS 1
47 #define RESPONSE_TYPE_COMPLETE 2
48 #define RESPONSE_TYPE_HANDSHAKE 3
49 #define HEADER_MARKER 0xff
51 #define REQUEST_TYPE_DEFAULT 0
52 #define REQUEST_TYPE_CANCEL 1
53 #define REQUEST_TYPE_HANDSHAKE 2
55 #define IPC_PROTOCOL_STR "IPC_PROTOCOL_38"
56 #define IPC_VERSION_NUMBER 38
58 enum IPCrequestStatus
60 INITIALIZED = 0,
61 IN_PROGRESS,
62 COMPLETED,
63 CANCELLED_DEFAULT,
64 CANCELLED_IMMEDIATE,
65 UNDEFINED_REGUEST
68 enum IPCTraceLevel
70 TRACE_LVL_0 = 0,
71 TRACE_LVL_1,
72 TRACE_LVL_2,
73 TRACE_LVL_3,
74 TRACE_LVL_4
77 class IPCrequest
79 char *buf;
80 int size;
81 int idx;
82 int requestID;
83 int channelID;
84 IPCrequestStatus status;
85 bool cancelImmediate;
86 public:
87 IPCrequest (int, int, int);
88 ~IPCrequest ();
89 IPCrequestStatus getStatus ();
90 void setStatus (IPCrequestStatus);
91 void read ();
93 int getRequestID () { return requestID; }
94 int getChannelID () { return channelID; }
95 bool isCancelImmediate () { return cancelImmediate; }
96 void setCancelImmediate () { cancelImmediate = true; }
97 char rgetc () { return buf[idx++]; }
100 class IPCresponse
102 public:
103 IPCresponse (int sz);
104 ~IPCresponse ();
106 int getRequestID () { return requestID; }
107 int getChannelID () { return channelID; }
108 void setRequestID (int r) { requestID = r; }
109 void setChannelID (int c) { channelID = c; }
110 void setResponseType (int r) { responseType = r; }
111 void setResponseStatus (int s) { responseStatus = s; }
112 int getCurBufSize () { return sb->capacity (); }
113 void sendByte (int);
114 void sendIVal (int);
115 void sendLVal (long long);
116 void sendDVal (double);
117 void sendSVal (const char *);
118 void sendBVal (bool);
119 void sendCVal (char);
120 void sendAVal (void*);
121 void print (void);
122 void reset ();
123 IPCresponse *next;
125 private:
126 int requestID;
127 int channelID;
128 int responseType;
129 int responseStatus;
130 StringBuilder *sb;
133 class BufferPool
135 public:
136 BufferPool ();
137 ~BufferPool ();
138 IPCresponse* getNewResponse (int);
139 void recycle (IPCresponse *);
140 private:
141 pthread_mutex_t p_mutex;
142 IPCresponse *smallBuf;
143 IPCresponse *largeBuf;
146 // Read from the wire
147 int readInt (IPCrequest*);
148 bool readBoolean (IPCrequest*);
149 long long readLong (IPCrequest*);
150 DbeObj readObject (IPCrequest*);
151 Object readArray (IPCrequest*);
152 String readString (IPCrequest*);
153 void readRequestHeader ();
155 // write to the wire
156 void writeError (const char *, IPCrequest*);
157 void writeString (const char *, IPCrequest*);
158 void writeBoolean (bool, IPCrequest*);
159 void writeInt (int, IPCrequest*);
160 void writeChar (char, IPCrequest*);
161 void writeLong (long long, IPCrequest*);
162 void writeDouble (double, IPCrequest*);
163 void writeArray (void *, IPCrequest*);
164 void writeObject (DbeObj, IPCrequest*);
165 void writeResponseGeneric (int, int, int);
166 int setProgress (int, const char *); // Update the progress bar
167 int ipc_doWork (void *); // The argument is an IPCrequest
169 extern int ipc_flags;
170 extern int ipc_single_threaded_mode;
171 extern DbeThreadPool *responseThreadPool;
172 extern DbeThreadPool *ipcThreadPool;
173 extern int cancelRequestedChannelID;
174 extern int cancellableChannelID;
175 extern int error_flag;
177 void ipc_default_log (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
178 void ipc_response_log (IPCTraceLevel, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
179 void ipc_request_log (IPCTraceLevel, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
181 #endif