7272#if defined(WAIT_USE_EPOLL ) || defined(WAIT_USE_POLL ) || \
7373 defined(WAIT_USE_KQUEUE ) || defined(WAIT_USE_WIN32 )
7474/* don't overwrite manual choice */
75- #elif defined(HAVE_SYS_EPOLL_H ) && defined( HAVE_SYS_SIGNALFD_H )
75+ #elif defined(HAVE_SYS_EPOLL_H )
7676#define WAIT_USE_EPOLL
7777#elif defined(HAVE_KQUEUE )
7878#define WAIT_USE_KQUEUE
8484#error "no wait set implementation available"
8585#endif
8686
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+
87103/* typedef in latch.h */
88104struct WaitEventSet
89105{
@@ -146,12 +162,12 @@ static WaitEventSet *LatchWaitSet;
146162static volatile sig_atomic_t waiting = false;
147163#endif
148164
149- #ifdef WAIT_USE_EPOLL
165+ #ifdef WAIT_USE_SIGNALFD
150166/* On Linux, we'll receive SIGURG via a signalfd file descriptor. */
151167static int signal_fd = -1 ;
152168#endif
153169
154- #if defined( WAIT_USE_POLL )
170+ #ifdef WAIT_USE_SELF_PIPE
155171/* Read and write ends of the self-pipe */
156172static int selfpipe_readfd = -1 ;
157173static int selfpipe_writefd = -1 ;
@@ -164,7 +180,7 @@ static void latch_sigurg_handler(SIGNAL_ARGS);
164180static void sendSelfPipeByte (void );
165181#endif
166182
167- #if defined(WAIT_USE_POLL ) || defined(WAIT_USE_EPOLL )
183+ #if defined(WAIT_USE_SELF_PIPE ) || defined(WAIT_USE_SIGNALFD )
168184static void drain (void );
169185#endif
170186
@@ -190,7 +206,7 @@ static inline int WaitEventSetWaitBlock(WaitEventSet *set, int cur_timeout,
190206void
191207InitializeLatchSupport (void )
192208{
193- #if defined(WAIT_USE_POLL )
209+ #if defined(WAIT_USE_SELF_PIPE )
194210 int pipefd [2 ];
195211
196212 if (IsUnderPostmaster )
@@ -264,7 +280,7 @@ InitializeLatchSupport(void)
264280 pqsignal (SIGURG , latch_sigurg_handler );
265281#endif
266282
267- #ifdef WAIT_USE_EPOLL
283+ #ifdef WAIT_USE_SIGNALFD
268284 sigset_t signalfd_mask ;
269285
270286 /* Block SIGURG, because we'll receive it through a signalfd. */
@@ -316,15 +332,15 @@ ShutdownLatchSupport(void)
316332 LatchWaitSet = NULL ;
317333 }
318334
319- #if defined(WAIT_USE_POLL )
335+ #if defined(WAIT_USE_SELF_PIPE )
320336 close (selfpipe_readfd );
321337 close (selfpipe_writefd );
322338 selfpipe_readfd = -1 ;
323339 selfpipe_writefd = -1 ;
324340 selfpipe_owner_pid = InvalidPid ;
325341#endif
326342
327- #if defined(WAIT_USE_EPOLL )
343+ #if defined(WAIT_USE_SIGNALFD )
328344 close (signal_fd );
329345 signal_fd = -1 ;
330346#endif
@@ -341,9 +357,12 @@ InitLatch(Latch *latch)
341357 latch -> owner_pid = MyProcPid ;
342358 latch -> is_shared = false;
343359
344- #if defined(WAIT_USE_POLL )
360+ #if defined(WAIT_USE_SELF_PIPE )
345361 /* Assert InitializeLatchSupport has been called in this process */
346362 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 );
347366#elif defined(WAIT_USE_WIN32 )
348367 latch -> event = CreateEvent (NULL , TRUE, FALSE, NULL );
349368 if (latch -> event == NULL )
@@ -405,9 +424,12 @@ OwnLatch(Latch *latch)
405424 /* Sanity checks */
406425 Assert (latch -> is_shared );
407426
408- #if defined(WAIT_USE_POLL )
427+ #if defined(WAIT_USE_SELF_PIPE )
409428 /* Assert InitializeLatchSupport has been called in this process */
410429 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 );
411433#endif
412434
413435 if (latch -> owner_pid != 0 )
@@ -618,7 +640,7 @@ SetLatch(Latch *latch)
618640 return ;
619641 else if (owner_pid == MyProcPid )
620642 {
621- #if defined(WAIT_USE_POLL )
643+ #if defined(WAIT_USE_SELF_PIPE )
622644 if (waiting )
623645 sendSelfPipeByte ();
624646#else
@@ -983,9 +1005,9 @@ AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch,
9831005 {
9841006 set -> latch = latch ;
9851007 set -> latch_pos = event -> pos ;
986- #if defined(WAIT_USE_POLL )
1008+ #if defined(WAIT_USE_SELF_PIPE )
9871009 event -> fd = selfpipe_readfd ;
988- #elif defined(WAIT_USE_EPOLL )
1010+ #elif defined(WAIT_USE_SIGNALFD )
9891011 event -> fd = signal_fd ;
9901012#else
9911013 event -> fd = PGINVALID_SOCKET ;
@@ -2102,7 +2124,7 @@ GetNumRegisteredWaitEvents(WaitEventSet *set)
21022124 return set -> nevents ;
21032125}
21042126
2105- #if defined(WAIT_USE_POLL )
2127+ #if defined(WAIT_USE_SELF_PIPE )
21062128
21072129/*
21082130 * SetLatch uses SIGURG to wake up the process waiting on the latch.
@@ -2153,7 +2175,7 @@ sendSelfPipeByte(void)
21532175
21542176#endif
21552177
2156- #if defined(WAIT_USE_POLL ) || defined(WAIT_USE_EPOLL )
2178+ #if defined(WAIT_USE_SELF_PIPE ) || defined(WAIT_USE_SIGNALFD )
21572179
21582180/*
21592181 * Read all available data from self-pipe or signalfd.
@@ -2169,7 +2191,7 @@ drain(void)
21692191 int rc ;
21702192 int fd ;
21712193
2172- #ifdef WAIT_USE_POLL
2194+ #ifdef WAIT_USE_SELF_PIPE
21732195 fd = selfpipe_readfd ;
21742196#else
21752197 fd = signal_fd ;
@@ -2187,7 +2209,7 @@ drain(void)
21872209 else
21882210 {
21892211 waiting = false;
2190- #ifdef WAIT_USE_POLL
2212+ #ifdef WAIT_USE_SELF_PIPE
21912213 elog (ERROR , "read() on self-pipe failed: %m" );
21922214#else
21932215 elog (ERROR , "read() on signalfd failed: %m" );
@@ -2197,7 +2219,7 @@ drain(void)
21972219 else if (rc == 0 )
21982220 {
21992221 waiting = false;
2200- #ifdef WAIT_USE_POLL
2222+ #ifdef WAIT_USE_SELF_PIPE
22012223 elog (ERROR , "unexpected EOF on self-pipe" );
22022224#else
22032225 elog (ERROR , "unexpected EOF on signalfd" );
0 commit comments