* Change the event mask and, in the WL_LATCH_SET case, the latch associated * with the WaitEvent. The latch may be changed to NULL to disable the latch * temporarily, and then set back to a latch later. * * 'pos' is the id returned by AddWaitEventToSet. */
| 1023 | * 'pos' is the id returned by AddWaitEventToSet. |
| 1024 | */ |
| 1025 | void |
| 1026 | ModifyWaitEvent(WaitEventSet *set, int pos, uint32 events, Latch *latch) |
| 1027 | { |
| 1028 | WaitEvent *event; |
| 1029 | #if defined(WAIT_USE_KQUEUE) |
| 1030 | int old_events; |
| 1031 | #endif |
| 1032 | |
| 1033 | Assert(pos < set->nevents); |
| 1034 | |
| 1035 | event = &set->events[pos]; |
| 1036 | #if defined(WAIT_USE_KQUEUE) |
| 1037 | old_events = event->events; |
| 1038 | #endif |
| 1039 | |
| 1040 | /* |
| 1041 | * If neither the event mask nor the associated latch changes, return |
| 1042 | * early. That's an important optimization for some sockets, where |
| 1043 | * ModifyWaitEvent is frequently used to switch from waiting for reads to |
| 1044 | * waiting on writes. |
| 1045 | */ |
| 1046 | if (events == event->events && |
| 1047 | (!(event->events & WL_LATCH_SET) || set->latch == latch)) |
| 1048 | return; |
| 1049 | |
| 1050 | if (event->events & WL_LATCH_SET && |
| 1051 | events != event->events) |
| 1052 | { |
| 1053 | elog(ERROR, "cannot modify latch event"); |
| 1054 | } |
| 1055 | |
| 1056 | if (event->events & WL_POSTMASTER_DEATH) |
| 1057 | { |
| 1058 | elog(ERROR, "cannot modify postmaster death event"); |
| 1059 | } |
| 1060 | |
| 1061 | /* FIXME: validate event mask */ |
| 1062 | event->events = events; |
| 1063 | |
| 1064 | if (events == WL_LATCH_SET) |
| 1065 | { |
| 1066 | if (latch && latch->owner_pid != MyProcPid) |
| 1067 | elog(ERROR, "cannot wait on a latch owned by another process"); |
| 1068 | set->latch = latch; |
| 1069 | |
| 1070 | /* |
| 1071 | * On Unix, we don't need to modify the kernel object because the |
| 1072 | * underlying pipe (if there is one) is the same for all latches so we |
| 1073 | * can return immediately. On Windows, we need to update our array of |
| 1074 | * handles, but we leave the old one in place and tolerate spurious |
| 1075 | * wakeups if the latch is disabled. |
| 1076 | */ |
| 1077 | #if defined(WAIT_USE_WIN32) |
| 1078 | if (!latch) |
| 1079 | return; |
| 1080 | #else |
| 1081 | return; |
| 1082 | #endif |
no test coverage detected