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 )
@@ -405,9 +424,12 @@ OwnLatch(Latch *latch)
405
424
/* Sanity checks */
406
425
Assert (latch -> is_shared );
407
426
408
- #if defined(WAIT_USE_POLL )
427
+ #if defined(WAIT_USE_SELF_PIPE )
409
428
/* Assert InitializeLatchSupport has been called in this process */
410
429
Assert (selfpipe_readfd >= 0 && selfpipe_owner_pid == MyProcPid );
430
+ #elif defined(WAIT_USE_SIGNALFD )
431
+ /* Assert InitializeLatchSupport has been called in this process */
432
+ Assert (signal_fd >= 0 );
411
433
#endif
412
434
413
435
if (latch -> owner_pid != 0 )
@@ -617,7 +639,7 @@ SetLatch(Latch *latch)
617
639
return ;
618
640
else if (owner_pid == MyProcPid )
619
641
{
620
- #if defined(WAIT_USE_POLL )
642
+ #if defined(WAIT_USE_SELF_PIPE )
621
643
if (waiting )
622
644
sendSelfPipeByte ();
623
645
#else
@@ -904,9 +926,9 @@ AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch,
904
926
{
905
927
set -> latch = latch ;
906
928
set -> latch_pos = event -> pos ;
907
- #if defined(WAIT_USE_POLL )
929
+ #if defined(WAIT_USE_SELF_PIPE )
908
930
event -> fd = selfpipe_readfd ;
909
- #elif defined(WAIT_USE_EPOLL )
931
+ #elif defined(WAIT_USE_SIGNALFD )
910
932
event -> fd = signal_fd ;
911
933
#else
912
934
event -> fd = PGINVALID_SOCKET ;
@@ -2023,7 +2045,7 @@ GetNumRegisteredWaitEvents(WaitEventSet *set)
2023
2045
return set -> nevents ;
2024
2046
}
2025
2047
2026
- #if defined(WAIT_USE_POLL )
2048
+ #if defined(WAIT_USE_SELF_PIPE )
2027
2049
2028
2050
/*
2029
2051
* SetLatch uses SIGURG to wake up the process waiting on the latch.
@@ -2074,7 +2096,7 @@ sendSelfPipeByte(void)
2074
2096
2075
2097
#endif
2076
2098
2077
- #if defined(WAIT_USE_POLL ) || defined(WAIT_USE_EPOLL )
2099
+ #if defined(WAIT_USE_SELF_PIPE ) || defined(WAIT_USE_SIGNALFD )
2078
2100
2079
2101
/*
2080
2102
* Read all available data from self-pipe or signalfd.
@@ -2090,7 +2112,7 @@ drain(void)
2090
2112
int rc ;
2091
2113
int fd ;
2092
2114
2093
- #ifdef WAIT_USE_POLL
2115
+ #ifdef WAIT_USE_SELF_PIPE
2094
2116
fd = selfpipe_readfd ;
2095
2117
#else
2096
2118
fd = signal_fd ;
@@ -2108,7 +2130,7 @@ drain(void)
2108
2130
else
2109
2131
{
2110
2132
waiting = false;
2111
- #ifdef WAIT_USE_POLL
2133
+ #ifdef WAIT_USE_SELF_PIPE
2112
2134
elog (ERROR , "read() on self-pipe failed: %m" );
2113
2135
#else
2114
2136
elog (ERROR , "read() on signalfd failed: %m" );
@@ -2118,7 +2140,7 @@ drain(void)
2118
2140
else if (rc == 0 )
2119
2141
{
2120
2142
waiting = false;
2121
- #ifdef WAIT_USE_POLL
2143
+ #ifdef WAIT_USE_SELF_PIPE
2122
2144
elog (ERROR , "unexpected EOF on self-pipe" );
2123
2145
#else
2124
2146
elog (ERROR , "unexpected EOF on signalfd" );
0 commit comments