|
58 | 58 | * allowing die interrupts: HOLD_CANCEL_INTERRUPTS() and
|
59 | 59 | * RESUME_CANCEL_INTERRUPTS().
|
60 | 60 | *
|
| 61 | + * Note that ProcessInterrupts() has also acquired a number of tasks that |
| 62 | + * do not necessarily cause a query-cancel-or-die response. Hence, it's |
| 63 | + * possible that it will just clear InterruptPending and return. |
| 64 | + * |
| 65 | + * INTERRUPTS_PENDING_CONDITION() can be checked to see whether an |
| 66 | + * interrupt needs to be serviced, without trying to do so immediately. |
| 67 | + * Some callers are also interested in INTERRUPTS_CAN_BE_PROCESSED(), |
| 68 | + * which tells whether ProcessInterrupts is sure to clear the interrupt. |
| 69 | + * |
61 | 70 | * Special mechanisms are used to let an interrupt be accepted when we are
|
62 | 71 | * waiting for a lock or when we are waiting for command input (but, of
|
63 | 72 | * course, only if the interrupt holdoff counter is zero). See the
|
@@ -95,24 +104,27 @@ extern PGDLLIMPORT volatile uint32 CritSectionCount;
|
95 | 104 | /* in tcop/postgres.c */
|
96 | 105 | extern void ProcessInterrupts(void);
|
97 | 106 |
|
| 107 | +/* Test whether an interrupt is pending */ |
98 | 108 | #ifndef WIN32
|
| 109 | +#define INTERRUPTS_PENDING_CONDITION() \ |
| 110 | + (InterruptPending) |
| 111 | +#else |
| 112 | +#define INTERRUPTS_PENDING_CONDITION() \ |
| 113 | + (UNBLOCKED_SIGNAL_QUEUE() ? pgwin32_dispatch_queued_signals() : 0, \ |
| 114 | + InterruptPending) |
| 115 | +#endif |
99 | 116 |
|
| 117 | +/* Service interrupt, if one is pending and it's safe to service it now */ |
100 | 118 | #define CHECK_FOR_INTERRUPTS() \
|
101 | 119 | do { \
|
102 |
| - if (InterruptPending) \ |
103 |
| - ProcessInterrupts(); \ |
104 |
| -} while(0) |
105 |
| -#else /* WIN32 */ |
106 |
| - |
107 |
| -#define CHECK_FOR_INTERRUPTS() \ |
108 |
| -do { \ |
109 |
| - if (UNBLOCKED_SIGNAL_QUEUE()) \ |
110 |
| - pgwin32_dispatch_queued_signals(); \ |
111 |
| - if (InterruptPending) \ |
| 120 | + if (INTERRUPTS_PENDING_CONDITION()) \ |
112 | 121 | ProcessInterrupts(); \
|
113 | 122 | } while(0)
|
114 |
| -#endif /* WIN32 */ |
115 | 123 |
|
| 124 | +/* Is ProcessInterrupts() guaranteed to clear InterruptPending? */ |
| 125 | +#define INTERRUPTS_CAN_BE_PROCESSED() \ |
| 126 | + (InterruptHoldoffCount == 0 && CritSectionCount == 0 && \ |
| 127 | + QueryCancelHoldoffCount == 0) |
116 | 128 |
|
117 | 129 | #define HOLD_INTERRUPTS() (InterruptHoldoffCount++)
|
118 | 130 |
|
|
0 commit comments