MCPcopy Create free account
hub / github.com/apache/cloudberry / WaitEventAdjustKqueue

Function WaitEventAdjustKqueue

src/backend/storage/ipc/latch.c:1229–1325  ·  view source on GitHub ↗

* old_events is the previous event mask, used to compute what has changed. */

Source from the content-addressed store, hash-verified

1227 * old_events is the previous event mask, used to compute what has changed.
1228 */
1229static void
1230WaitEventAdjustKqueue(WaitEventSet *set, WaitEvent *event, int old_events)
1231{
1232 int rc;
1233 struct kevent k_ev[2];
1234 int count = 0;
1235 bool new_filt_read = false;
1236 bool old_filt_read = false;
1237 bool new_filt_write = false;
1238 bool old_filt_write = false;
1239
1240 if (old_events == event->events)
1241 return;
1242
1243 Assert(event->events != WL_LATCH_SET || set->latch != NULL);
1244 Assert(event->events == WL_LATCH_SET ||
1245 event->events == WL_POSTMASTER_DEATH ||
1246 (event->events & (WL_SOCKET_READABLE | WL_SOCKET_WRITEABLE)));
1247
1248 if (event->events == WL_POSTMASTER_DEATH)
1249 {
1250 /*
1251 * Unlike all the other implementations, we detect postmaster death
1252 * using process notification instead of waiting on the postmaster
1253 * alive pipe.
1254 */
1255 WaitEventAdjustKqueueAddPostmaster(&k_ev[count++], event);
1256 }
1257 else if (event->events == WL_LATCH_SET)
1258 {
1259 /* We detect latch wakeup using a signal event. */
1260 WaitEventAdjustKqueueAddLatch(&k_ev[count++], event);
1261 }
1262 else
1263 {
1264 /*
1265 * We need to compute the adds and deletes required to get from the
1266 * old event mask to the new event mask, since kevent treats readable
1267 * and writable as separate events.
1268 */
1269 if (old_events & WL_SOCKET_READABLE)
1270 old_filt_read = true;
1271 if (event->events & WL_SOCKET_READABLE)
1272 new_filt_read = true;
1273 if (old_events & WL_SOCKET_WRITEABLE)
1274 old_filt_write = true;
1275 if (event->events & WL_SOCKET_WRITEABLE)
1276 new_filt_write = true;
1277 if (old_filt_read && !new_filt_read)
1278 WaitEventAdjustKqueueAdd(&k_ev[count++], EVFILT_READ, EV_DELETE,
1279 event);
1280 else if (!old_filt_read && new_filt_read)
1281 WaitEventAdjustKqueueAdd(&k_ev[count++], EVFILT_READ, EV_ADD,
1282 event);
1283 if (old_filt_write && !new_filt_write)
1284 WaitEventAdjustKqueueAdd(&k_ev[count++], EVFILT_WRITE, EV_DELETE,
1285 event);
1286 else if (!old_filt_write && new_filt_write)

Callers 2

AddWaitEventToSetFunction · 0.85
ModifyWaitEventFunction · 0.85

Calls 7

WaitEventAdjustKqueueAddFunction · 0.85
PostmasterIsAliveFunction · 0.85
keventClass · 0.70
errmsgFunction · 0.50

Tested by

no test coverage detected