72
72
#if defined(WAIT_USE_EPOLL ) || defined(WAIT_USE_POLL ) || \
73
73
defined(WAIT_USE_KQUEUE ) || defined(WAIT_USE_WIN32 )
74
74
/* don't overwrite manual choice */
75
- #elif defined(HAVE_SYS_EPOLL_H ) && defined( HAVE_SYS_SIGNALFD_H )
75
+ #elif defined(HAVE_SYS_EPOLL_H )
76
76
#define WAIT_USE_EPOLL
77
77
#elif defined(HAVE_KQUEUE )
78
78
#define WAIT_USE_KQUEUE
84
84
#error "no wait set implementation available"
85
85
#endif
86
86
87
+ /*
88
+ * By default, we use a self-pipe with poll() and a signalfd with epoll(), if
89
+ * available. We avoid signalfd on illumos for now based on problem reports.
90
+ * For testing the choice can also be manually specified.
91
+ */
92
+ #if defined(WAIT_USE_POLL ) || defined(WAIT_USE_EPOLL )
93
+ #if defined(WAIT_USE_SELF_PIPE ) || defined(WAIT_USE_SIGNALFD )
94
+ /* don't overwrite manual choice */
95
+ #elif defined(WAIT_USE_EPOLL ) && defined(HAVE_SYS_SIGNALFD_H ) && \
96
+ !defined(__illumos__ )
97
+ #define WAIT_USE_SIGNALFD
98
+ #else
99
+ #define WAIT_USE_SELF_PIPE
100
+ #endif
101
+ #endif
102
+
87
103
/* typedef in latch.h */
88
104
struct WaitEventSet
89
105
{
@@ -146,12 +162,12 @@ static WaitEventSet *LatchWaitSet;
146
162
static volatile sig_atomic_t waiting = false;
147
163
#endif
148
164
149
- #ifdef WAIT_USE_EPOLL
165
+ #ifdef WAIT_USE_SIGNALFD
150
166
/* On Linux, we'll receive SIGURG via a signalfd file descriptor. */
151
167
static int signal_fd = -1 ;
152
168
#endif
153
169
154
- #if defined( WAIT_USE_POLL )
170
+ #ifdef WAIT_USE_SELF_PIPE
155
171
/* Read and write ends of the self-pipe */
156
172
static int selfpipe_readfd = -1 ;
157
173
static int selfpipe_writefd = -1 ;
@@ -164,7 +180,7 @@ static void latch_sigurg_handler(SIGNAL_ARGS);
164
180
static void sendSelfPipeByte (void );
165
181
#endif
166
182
167
- #if defined(WAIT_USE_POLL ) || defined(WAIT_USE_EPOLL )
183
+ #if defined(WAIT_USE_SELF_PIPE ) || defined(WAIT_USE_SIGNALFD )
168
184
static void drain (void );
169
185
#endif
170
186
@@ -190,7 +206,7 @@ static inline int WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
190
206
void
191
207
InitializeLatchSupport (void )
192
208
{
193
- #if defined(WAIT_USE_POLL )
209
+ #if defined(WAIT_USE_SELF_PIPE )
194
210
int pipefd [2 ];
195
211
196
212
if (IsUnderPostmaster )
@@ -264,7 +280,7 @@ InitializeLatchSupport(void)
264
280
pqsignal (SIGURG , latch_sigurg_handler );
265
281
#endif
266
282
267
- #ifdef WAIT_USE_EPOLL
283
+ #ifdef WAIT_USE_SIGNALFD
268
284
sigset_t signalfd_mask ;
269
285
270
286
/* Block SIGURG, because we'll receive it through a signalfd. */
@@ -316,15 +332,15 @@ ShutdownLatchSupport(void)
316
332
LatchWaitSet = NULL ;
317
333
}
318
334
319
- #if defined(WAIT_USE_POLL )
335
+ #if defined(WAIT_USE_SELF_PIPE )
320
336
close (selfpipe_readfd );
321
337
close (selfpipe_writefd );
322
338
selfpipe_readfd = -1 ;
323
339
selfpipe_writefd = -1 ;
324
340
selfpipe_owner_pid = InvalidPid ;
325
341
#endif
326
342
327
- #if defined(WAIT_USE_EPOLL )
343
+ #if defined(WAIT_USE_SIGNALFD )
328
344
close (signal_fd );
329
345
signal_fd = -1 ;
330
346
#endif
@@ -341,9 +357,12 @@ InitLatch(Latch *latch)
341
357
latch -> owner_pid = MyProcPid ;
342
358
latch -> is_shared = false;
343
359
344
- #if defined(WAIT_USE_POLL )
360
+ #if defined(WAIT_USE_SELF_PIPE )
345
361
/* Assert InitializeLatchSupport has been called in this process */
346
362
Assert (selfpipe_readfd >= 0 && selfpipe_owner_pid == MyProcPid );
363
+ #elif defined(WAIT_USE_SIGNALFD )
364
+ /* Assert InitializeLatchSupport has been called in this process */
365
+ Assert (signal_fd >= 0 );
347
366
#elif defined(WAIT_USE_WIN32 )
348
367
latch -> event = CreateEvent (NULL , TRUE, FALSE, NULL );
349
368
if (latch -> event == NULL )
@@ -407,9 +426,12 @@ OwnLatch(Latch *latch)
407
426
/* Sanity checks */
408
427
Assert (latch -> is_shared );
409
428
410
- #if defined(WAIT_USE_POLL )
429
+ #if defined(WAIT_USE_SELF_PIPE )
411
430
/* Assert InitializeLatchSupport has been called in this process */
412
431
Assert (selfpipe_readfd >= 0 && selfpipe_owner_pid == MyProcPid );
432
+ #elif defined(WAIT_USE_SIGNALFD )
433
+ /* Assert InitializeLatchSupport has been called in this process */
434
+ Assert (signal_fd >= 0 );
413
435
#endif
414
436
415
437
owner_pid = latch -> owner_pid ;
@@ -620,7 +642,7 @@ SetLatch(Latch *latch)
620
642
return ;
621
643
else if (owner_pid == MyProcPid )
622
644
{
623
- #if defined(WAIT_USE_POLL )
645
+ #if defined(WAIT_USE_SELF_PIPE )
624
646
if (waiting )
625
647
sendSelfPipeByte ();
626
648
#else
@@ -907,9 +929,9 @@ AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch,
907
929
{
908
930
set -> latch = latch ;
909
931
set -> latch_pos = event -> pos ;
910
- #if defined(WAIT_USE_POLL )
932
+ #if defined(WAIT_USE_SELF_PIPE )
911
933
event -> fd = selfpipe_readfd ;
912
- #elif defined(WAIT_USE_EPOLL )
934
+ #elif defined(WAIT_USE_SIGNALFD )
913
935
event -> fd = signal_fd ;
914
936
#else
915
937
event -> fd = PGINVALID_SOCKET ;
@@ -2086,7 +2108,7 @@ GetNumRegisteredWaitEvents(WaitEventSet *set)
2086
2108
return set -> nevents ;
2087
2109
}
2088
2110
2089
- #if defined(WAIT_USE_POLL )
2111
+ #if defined(WAIT_USE_SELF_PIPE )
2090
2112
2091
2113
/*
2092
2114
* SetLatch uses SIGURG to wake up the process waiting on the latch.
@@ -2137,7 +2159,7 @@ sendSelfPipeByte(void)
2137
2159
2138
2160
#endif
2139
2161
2140
- #if defined(WAIT_USE_POLL ) || defined(WAIT_USE_EPOLL )
2162
+ #if defined(WAIT_USE_SELF_PIPE ) || defined(WAIT_USE_SIGNALFD )
2141
2163
2142
2164
/*
2143
2165
* Read all available data from self-pipe or signalfd.
@@ -2153,7 +2175,7 @@ drain(void)
2153
2175
int rc ;
2154
2176
int fd ;
2155
2177
2156
- #ifdef WAIT_USE_POLL
2178
+ #ifdef WAIT_USE_SELF_PIPE
2157
2179
fd = selfpipe_readfd ;
2158
2180
#else
2159
2181
fd = signal_fd ;
@@ -2171,7 +2193,7 @@ drain(void)
2171
2193
else
2172
2194
{
2173
2195
waiting = false;
2174
- #ifdef WAIT_USE_POLL
2196
+ #ifdef WAIT_USE_SELF_PIPE
2175
2197
elog (ERROR , "read() on self-pipe failed: %m" );
2176
2198
#else
2177
2199
elog (ERROR , "read() on signalfd failed: %m" );
@@ -2181,7 +2203,7 @@ drain(void)
2181
2203
else if (rc == 0 )
2182
2204
{
2183
2205
waiting = false;
2184
- #ifdef WAIT_USE_POLL
2206
+ #ifdef WAIT_USE_SELF_PIPE
2185
2207
elog (ERROR , "unexpected EOF on self-pipe" );
2186
2208
#else
2187
2209
elog (ERROR , "unexpected EOF on signalfd" );
0 commit comments