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

Function AddWaitEventToSet

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

--- * Add an event to the set. Possible events are: * - WL_LATCH_SET: Wait for the latch to be set * - WL_POSTMASTER_DEATH: Wait for postmaster to die * - WL_SOCKET_READABLE: Wait for socket to become readable, * can be combined in one event with other WL_SOCKET_* events * - WL_SOCKET_WRITEABLE: Wait for socket to become writeable, * can be combined with other WL_SOCKET_* events * - WL_S

Source from the content-addressed store, hash-verified

937 * events.
938 */
939int
940AddWaitEventToSet(WaitEventSet *set, uint32 events, pgsocket fd, Latch *latch,
941 void *user_data)
942{
943 WaitEvent *event;
944
945 /* not enough space */
946 Assert(set->nevents < set->nevents_space);
947
948 if (events == WL_EXIT_ON_PM_DEATH)
949 {
950 events = WL_POSTMASTER_DEATH;
951 set->exit_on_postmaster_death = true;
952 }
953
954 if (latch)
955 {
956 if (latch->owner_pid != MyProcPid)
957 elog(ERROR, "cannot wait on a latch owned by another process");
958 if (set->latch)
959 elog(ERROR, "cannot wait on more than one latch");
960 if ((events & WL_LATCH_SET) != WL_LATCH_SET)
961 elog(ERROR, "latch events only support being set");
962 }
963 else
964 {
965 if (events & WL_LATCH_SET)
966 elog(ERROR, "cannot wait on latch without a specified latch");
967 }
968
969 /* waiting for socket readiness without a socket indicates a bug */
970 if (fd == PGINVALID_SOCKET && (events & WL_SOCKET_MASK))
971 elog(ERROR, "cannot wait on socket event without a socket");
972
973 event = &set->events[set->nevents];
974 event->pos = set->nevents++;
975 event->fd = fd;
976 event->events = events;
977 event->user_data = user_data;
978#ifdef WIN32
979 event->reset = false;
980#endif
981
982 if (events == WL_LATCH_SET)
983 {
984 set->latch = latch;
985 set->latch_pos = event->pos;
986#if defined(WAIT_USE_POLL)
987 event->fd = selfpipe_readfd;
988#elif defined(WAIT_USE_EPOLL)
989 event->fd = signal_fd;
990#else
991 event->fd = PGINVALID_SOCKET;
992#ifdef WAIT_USE_EPOLL
993 return event->pos;
994#endif
995#endif
996 }

Callers 9

receiveChunksUDPIFCFunction · 0.85
CheckCancelOnQDFunction · 0.85
InitializeLatchWaitSetFunction · 0.85
WaitLatchOrSocketFunction · 0.85
SysLoggerMainFunction · 0.85
PgstatCollectorMainFunction · 0.85
ExecAppendAsyncEventWaitFunction · 0.85
pq_initFunction · 0.85

Calls 4

WaitEventAdjustEpollFunction · 0.85
WaitEventAdjustKqueueFunction · 0.85
WaitEventAdjustPollFunction · 0.85
WaitEventAdjustWin32Function · 0.85

Tested by

no test coverage detected