* Enable the specified timeout reason */
| 154 | * Enable the specified timeout reason |
| 155 | */ |
| 156 | static void |
| 157 | enable_timeout(TimeoutId id, TimestampTz now, TimestampTz fin_time) |
| 158 | { |
| 159 | int i; |
| 160 | |
| 161 | /* Assert request is sane */ |
| 162 | Assert(all_timeouts_initialized); |
| 163 | Assert(all_timeouts[id].timeout_handler != NULL); |
| 164 | |
| 165 | /* |
| 166 | * If this timeout was already active, momentarily disable it. We |
| 167 | * interpret the call as a directive to reschedule the timeout. |
| 168 | */ |
| 169 | if (all_timeouts[id].active) |
| 170 | remove_timeout_index(find_active_timeout(id)); |
| 171 | |
| 172 | /* |
| 173 | * Find out the index where to insert the new timeout. We sort by |
| 174 | * fin_time, and for equal fin_time by priority. |
| 175 | */ |
| 176 | for (i = 0; i < num_active_timeouts; i++) |
| 177 | { |
| 178 | timeout_params *old_timeout = active_timeouts[i]; |
| 179 | |
| 180 | if (fin_time < old_timeout->fin_time) |
| 181 | break; |
| 182 | if (fin_time == old_timeout->fin_time && id < old_timeout->index) |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * Mark the timeout active, and insert it into the active list. |
| 188 | */ |
| 189 | all_timeouts[id].indicator = false; |
| 190 | all_timeouts[id].start_time = now; |
| 191 | all_timeouts[id].fin_time = fin_time; |
| 192 | |
| 193 | insert_timeout(id, i); |
| 194 | } |
| 195 | |
| 196 | /* |
| 197 | * Schedule alarm for the next active timeout, if any |
no test coverage detected