Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc179662

Browse files
committed
Make it easier to choose the used waiting primitive in unix_latch.c.
This allows for easier testing of the different primitives; inpreparation for adding a new primitive.Discussion: 20160114143931.GG10941@awork2.anarazel.deReviewed-By: Robert Haas
1 parent6bc4d95 commitc179662

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

‎src/backend/port/unix_latch.c

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,22 @@
5656
#include"storage/pmsignal.h"
5757
#include"storage/shmem.h"
5858

59+
/*
60+
* Select the fd readiness primitive to use. Normally the "most modern"
61+
* primitive supported by the OS will be used, but for testing it can be
62+
* useful to manually specify the used primitive. If desired, just add a
63+
* define somewhere before this block.
64+
*/
65+
#if defined(LATCH_USE_POLL)|| defined(LATCH_USE_SELECT)
66+
/* don't overwrite manual choice */
67+
#elif defined(HAVE_POLL)
68+
#defineLATCH_USE_POLL
69+
#elifHAVE_SYS_SELECT_H
70+
#defineLATCH_USE_SELECT
71+
#else
72+
#error "no latch implementation available"
73+
#endif
74+
5975
/* Are we currently in WaitLatch? The signal handler would like to know. */
6076
staticvolatilesig_atomic_twaiting= false;
6177

@@ -215,10 +231,10 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
215231
cur_time;
216232
longcur_timeout;
217233

218-
#ifdefHAVE_POLL
234+
#if defined(LATCH_USE_POLL)
219235
structpollfdpfds[3];
220236
intnfds;
221-
#else
237+
#elif defined(LATCH_USE_SELECT)
222238
structtimevaltv,
223239
*tvp;
224240
fd_setinput_mask;
@@ -248,7 +264,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
248264
Assert(timeout >=0&&timeout <=INT_MAX);
249265
cur_timeout=timeout;
250266

251-
#ifndefHAVE_POLL
267+
#ifdefLATCH_USE_SELECT
252268
tv.tv_sec=cur_timeout /1000L;
253269
tv.tv_usec= (cur_timeout %1000L)*1000L;
254270
tvp=&tv;
@@ -258,7 +274,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
258274
{
259275
cur_timeout=-1;
260276

261-
#ifndefHAVE_POLL
277+
#ifdefLATCH_USE_SELECT
262278
tvp=NULL;
263279
#endif
264280
}
@@ -292,16 +308,10 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
292308
}
293309

294310
/*
295-
* Must wait ... we use poll(2) if available, otherwise select(2).
296-
*
297-
* On at least older linux kernels select(), in violation of POSIX,
298-
* doesn't reliably return a socket as writable if closed - but we
299-
* rely on that. So far all the known cases of this problem are on
300-
* platforms that also provide a poll() implementation without that
301-
* bug. If we find one where that's not the case, we'll need to add a
302-
* workaround.
311+
* Must wait ... we use the polling interface determined at the top of
312+
* this file to do so.
303313
*/
304-
#ifdefHAVE_POLL
314+
#if defined(LATCH_USE_POLL)
305315
nfds=0;
306316
if (wakeEvents& (WL_SOCKET_READABLE |WL_SOCKET_WRITEABLE))
307317
{
@@ -397,8 +407,16 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
397407
result |=WL_POSTMASTER_DEATH;
398408
}
399409
}
400-
#else/* !HAVE_POLL */
410+
#elif defined(LATCH_USE_SELECT)
401411

412+
/*
413+
* On at least older linux kernels select(), in violation of POSIX,
414+
* doesn't reliably return a socket as writable if closed - but we
415+
* rely on that. So far all the known cases of this problem are on
416+
* platforms that also provide a poll() implementation without that
417+
* bug. If we find one where that's not the case, we'll need to add a
418+
* workaround.
419+
*/
402420
FD_ZERO(&input_mask);
403421
FD_ZERO(&output_mask);
404422

@@ -478,7 +496,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
478496
result |=WL_POSTMASTER_DEATH;
479497
}
480498
}
481-
#endif/*HAVE_POLL */
499+
#endif/*LATCH_USE_SELECT */
482500

483501
/* If we're not done, update cur_timeout for next iteration */
484502
if (result==0&& (wakeEvents&WL_TIMEOUT))
@@ -491,7 +509,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
491509
/* Timeout has expired, no need to continue looping */
492510
result |=WL_TIMEOUT;
493511
}
494-
#ifndefHAVE_POLL
512+
#ifdefLATCH_USE_SELECT
495513
else
496514
{
497515
tv.tv_sec=cur_timeout /1000L;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp