|
30 | 30 | /* Initially, we are not prepared to sleep on any condition variable. */
|
31 | 31 | static ConditionVariable *cv_sleep_target = NULL;
|
32 | 32 |
|
33 |
| -/* Reusable WaitEventSet. */ |
34 |
| -static WaitEventSet *cv_wait_event_set = NULL; |
35 |
| - |
36 | 33 | /*
|
37 | 34 | * Initialize a condition variable.
|
38 | 35 | */
|
@@ -62,23 +59,6 @@ ConditionVariablePrepareToSleep(ConditionVariable *cv)
|
62 | 59 | {
|
63 | 60 | int pgprocno = MyProc->pgprocno;
|
64 | 61 |
|
65 |
| - /* |
66 |
| - * If first time through in this process, create a WaitEventSet, which |
67 |
| - * we'll reuse for all condition variable sleeps. |
68 |
| - */ |
69 |
| - if (cv_wait_event_set == NULL) |
70 |
| - { |
71 |
| - WaitEventSet *new_event_set; |
72 |
| - |
73 |
| - new_event_set = CreateWaitEventSet(TopMemoryContext, 2); |
74 |
| - AddWaitEventToSet(new_event_set, WL_LATCH_SET, PGINVALID_SOCKET, |
75 |
| - MyLatch, NULL); |
76 |
| - AddWaitEventToSet(new_event_set, WL_EXIT_ON_PM_DEATH, PGINVALID_SOCKET, |
77 |
| - NULL, NULL); |
78 |
| - /* Don't set cv_wait_event_set until we have a correct WES. */ |
79 |
| - cv_wait_event_set = new_event_set; |
80 |
| - } |
81 |
| - |
82 | 62 | /*
|
83 | 63 | * If some other sleep is already prepared, cancel it; this is necessary
|
84 | 64 | * because we have just one static variable tracking the prepared sleep,
|
@@ -135,6 +115,7 @@ ConditionVariableTimedSleep(ConditionVariable *cv, long timeout,
|
135 | 115 | long cur_timeout = -1;
|
136 | 116 | instr_time start_time;
|
137 | 117 | instr_time cur_time;
|
| 118 | + int wait_events; |
138 | 119 |
|
139 | 120 | /*
|
140 | 121 | * If the caller didn't prepare to sleep explicitly, then do so now and
|
@@ -166,19 +147,20 @@ ConditionVariableTimedSleep(ConditionVariable *cv, long timeout,
|
166 | 147 | INSTR_TIME_SET_CURRENT(start_time);
|
167 | 148 | Assert(timeout >= 0 && timeout <= INT_MAX);
|
168 | 149 | cur_timeout = timeout;
|
| 150 | + wait_events = WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH; |
169 | 151 | }
|
| 152 | + else |
| 153 | + wait_events = WL_LATCH_SET | WL_EXIT_ON_PM_DEATH; |
170 | 154 |
|
171 | 155 | while (true)
|
172 | 156 | {
|
173 |
| - WaitEvent event; |
174 | 157 | bool done = false;
|
175 | 158 |
|
176 | 159 | /*
|
177 | 160 | * Wait for latch to be set. (If we're awakened for some other
|
178 | 161 | * reason, the code below will cope anyway.)
|
179 | 162 | */
|
180 |
| - (void) WaitEventSetWait(cv_wait_event_set, cur_timeout, &event, 1, |
181 |
| - wait_event_info); |
| 163 | + (void) WaitLatch(MyLatch, wait_events, cur_timeout, wait_event_info); |
182 | 164 |
|
183 | 165 | /* Reset latch before examining the state of the wait list. */
|
184 | 166 | ResetLatch(MyLatch);
|
|
0 commit comments