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