23
23
#include "miscadmin.h"
24
24
#include "pgstat.h"
25
25
#include "replication/walsender.h"
26
+ #include "storage/condition_variable.h"
26
27
#include "storage/ipc.h"
27
28
#include "storage/latch.h"
28
29
#include "storage/proc.h"
59
60
*/
60
61
typedef struct
61
62
{
62
- pid_t pss_pid ;
63
- sig_atomic_t pss_signalFlags [NUM_PROCSIGNALS ];
63
+ volatile pid_t pss_pid ;
64
+ volatile sig_atomic_t pss_signalFlags [NUM_PROCSIGNALS ];
64
65
pg_atomic_uint64 pss_barrierGeneration ;
65
66
pg_atomic_uint32 pss_barrierCheckMask ;
67
+ ConditionVariable pss_barrierCV ;
66
68
} ProcSignalSlot ;
67
69
68
70
/*
@@ -93,7 +95,7 @@ typedef struct
93
95
((flags) &= ~(((uint32) 1) << (uint32) (type)))
94
96
95
97
static ProcSignalHeader * ProcSignal = NULL ;
96
- static volatile ProcSignalSlot * MyProcSignalSlot = NULL ;
98
+ static ProcSignalSlot * MyProcSignalSlot = NULL ;
97
99
98
100
static bool CheckProcSignal (ProcSignalReason reason );
99
101
static void CleanupProcSignalState (int status , Datum arg );
@@ -142,6 +144,7 @@ ProcSignalShmemInit(void)
142
144
MemSet (slot -> pss_signalFlags , 0 , sizeof (slot -> pss_signalFlags ));
143
145
pg_atomic_init_u64 (& slot -> pss_barrierGeneration , PG_UINT64_MAX );
144
146
pg_atomic_init_u32 (& slot -> pss_barrierCheckMask , 0 );
147
+ ConditionVariableInit (& slot -> pss_barrierCV );
145
148
}
146
149
}
147
150
}
@@ -156,7 +159,7 @@ ProcSignalShmemInit(void)
156
159
void
157
160
ProcSignalInit (int pss_idx )
158
161
{
159
- volatile ProcSignalSlot * slot ;
162
+ ProcSignalSlot * slot ;
160
163
uint64 barrier_generation ;
161
164
162
165
Assert (pss_idx >= 1 && pss_idx <= NumProcSignalSlots );
@@ -208,7 +211,7 @@ static void
208
211
CleanupProcSignalState (int status , Datum arg )
209
212
{
210
213
int pss_idx = DatumGetInt32 (arg );
211
- volatile ProcSignalSlot * slot ;
214
+ ProcSignalSlot * slot ;
212
215
213
216
slot = & ProcSignal -> psh_slot [pss_idx - 1 ];
214
217
Assert (slot == MyProcSignalSlot );
@@ -237,6 +240,7 @@ CleanupProcSignalState(int status, Datum arg)
237
240
* no barrier waits block on it.
238
241
*/
239
242
pg_atomic_write_u64 (& slot -> pss_barrierGeneration , PG_UINT64_MAX );
243
+ ConditionVariableBroadcast (& slot -> pss_barrierCV );
240
244
241
245
slot -> pss_pid = 0 ;
242
246
}
@@ -391,13 +395,11 @@ EmitProcSignalBarrier(ProcSignalBarrierType type)
391
395
void
392
396
WaitForProcSignalBarrier (uint64 generation )
393
397
{
394
- long timeout = 125L ;
395
-
396
398
Assert (generation <= pg_atomic_read_u64 (& ProcSignal -> psh_barrierGeneration ));
397
399
398
400
for (int i = NumProcSignalSlots - 1 ; i >= 0 ; i -- )
399
401
{
400
- volatile ProcSignalSlot * slot = & ProcSignal -> psh_slot [i ];
402
+ ProcSignalSlot * slot = & ProcSignal -> psh_slot [i ];
401
403
uint64 oldval ;
402
404
403
405
/*
@@ -409,20 +411,11 @@ WaitForProcSignalBarrier(uint64 generation)
409
411
oldval = pg_atomic_read_u64 (& slot -> pss_barrierGeneration );
410
412
while (oldval < generation )
411
413
{
412
- int events ;
413
-
414
- CHECK_FOR_INTERRUPTS ();
415
-
416
- events =
417
- WaitLatch (MyLatch ,
418
- WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH ,
419
- timeout , WAIT_EVENT_PROC_SIGNAL_BARRIER );
420
- ResetLatch (MyLatch );
421
-
414
+ ConditionVariableSleep (& slot -> pss_barrierCV ,
415
+ WAIT_EVENT_PROC_SIGNAL_BARRIER );
422
416
oldval = pg_atomic_read_u64 (& slot -> pss_barrierGeneration );
423
- if (events & WL_TIMEOUT )
424
- timeout = Min (timeout * 2 , 1000L );
425
417
}
418
+ ConditionVariableCancelSleep ();
426
419
}
427
420
428
421
/*
@@ -589,6 +582,7 @@ ProcessProcSignalBarrier(void)
589
582
* next called.
590
583
*/
591
584
pg_atomic_write_u64 (& MyProcSignalSlot -> pss_barrierGeneration , shared_gen );
585
+ ConditionVariableBroadcast (& MyProcSignalSlot -> pss_barrierCV );
592
586
}
593
587
594
588
/*
0 commit comments