37
37
/*
38
38
* The postmaster's list of registered background workers, in private memory.
39
39
*/
40
- slist_head BackgroundWorkerList = SLIST_STATIC_INIT (BackgroundWorkerList );
40
+ dlist_head BackgroundWorkerList = DLIST_STATIC_INIT (BackgroundWorkerList );
41
41
42
42
/*
43
43
* BackgroundWorkerSlots exist in shared memory and can be accessed (via
@@ -168,7 +168,7 @@ BackgroundWorkerShmemInit(void)
168
168
& found );
169
169
if (!IsUnderPostmaster )
170
170
{
171
- slist_iter siter ;
171
+ dlist_iter iter ;
172
172
int slotno = 0 ;
173
173
174
174
BackgroundWorkerData -> total_slots = max_worker_processes ;
@@ -181,12 +181,12 @@ BackgroundWorkerShmemInit(void)
181
181
* correspondence between the postmaster's private list and the array
182
182
* in shared memory.
183
183
*/
184
- slist_foreach ( siter , & BackgroundWorkerList )
184
+ dlist_foreach ( iter , & BackgroundWorkerList )
185
185
{
186
186
BackgroundWorkerSlot * slot = & BackgroundWorkerData -> slot [slotno ];
187
187
RegisteredBgWorker * rw ;
188
188
189
- rw = slist_container (RegisteredBgWorker , rw_lnode , siter .cur );
189
+ rw = dlist_container (RegisteredBgWorker , rw_lnode , iter .cur );
190
190
Assert (slotno < max_worker_processes );
191
191
slot -> in_use = true;
192
192
slot -> terminate = false;
@@ -220,13 +220,13 @@ BackgroundWorkerShmemInit(void)
220
220
static RegisteredBgWorker *
221
221
FindRegisteredWorkerBySlotNumber (int slotno )
222
222
{
223
- slist_iter siter ;
223
+ dlist_iter iter ;
224
224
225
- slist_foreach ( siter , & BackgroundWorkerList )
225
+ dlist_foreach ( iter , & BackgroundWorkerList )
226
226
{
227
227
RegisteredBgWorker * rw ;
228
228
229
- rw = slist_container (RegisteredBgWorker , rw_lnode , siter .cur );
229
+ rw = dlist_container (RegisteredBgWorker , rw_lnode , iter .cur );
230
230
if (rw -> rw_shmem_slot == slotno )
231
231
return rw ;
232
232
}
@@ -413,29 +413,25 @@ BackgroundWorkerStateChange(bool allow_new_workers)
413
413
(errmsg_internal ("registering background worker \"%s\"" ,
414
414
rw -> rw_worker .bgw_name )));
415
415
416
- slist_push_head (& BackgroundWorkerList , & rw -> rw_lnode );
416
+ dlist_push_head (& BackgroundWorkerList , & rw -> rw_lnode );
417
417
}
418
418
}
419
419
420
420
/*
421
421
* Forget about a background worker that's no longer needed.
422
422
*
423
- * The worker must be identified by passing an slist_mutable_iter that
424
- * points to it. This convention allows deletion of workers during
425
- * searches of the worker list, and saves having to search the list again.
423
+ * NOTE: The entry is unlinked from BackgroundWorkerList. If the caller is
424
+ * iterating through it, better use a mutable iterator!
426
425
*
427
426
* Caller is responsible for notifying bgw_notify_pid, if appropriate.
428
427
*
429
428
* This function must be invoked only in the postmaster.
430
429
*/
431
430
void
432
- ForgetBackgroundWorker (slist_mutable_iter * cur )
431
+ ForgetBackgroundWorker (RegisteredBgWorker * rw )
433
432
{
434
- RegisteredBgWorker * rw ;
435
433
BackgroundWorkerSlot * slot ;
436
434
437
- rw = slist_container (RegisteredBgWorker , rw_lnode , cur -> cur );
438
-
439
435
Assert (rw -> rw_shmem_slot < max_worker_processes );
440
436
slot = & BackgroundWorkerData -> slot [rw -> rw_shmem_slot ];
441
437
Assert (slot -> in_use );
@@ -454,7 +450,7 @@ ForgetBackgroundWorker(slist_mutable_iter *cur)
454
450
(errmsg_internal ("unregistering background worker \"%s\"" ,
455
451
rw -> rw_worker .bgw_name )));
456
452
457
- slist_delete_current ( cur );
453
+ dlist_delete ( & rw -> rw_lnode );
458
454
pfree (rw );
459
455
}
460
456
@@ -480,17 +476,17 @@ ReportBackgroundWorkerPID(RegisteredBgWorker *rw)
480
476
* Report that the PID of a background worker is now zero because a
481
477
* previously-running background worker has exited.
482
478
*
479
+ * NOTE: The entry may be unlinked from BackgroundWorkerList. If the caller
480
+ * is iterating through it, better use a mutable iterator!
481
+ *
483
482
* This function should only be called from the postmaster.
484
483
*/
485
484
void
486
- ReportBackgroundWorkerExit (slist_mutable_iter * cur )
485
+ ReportBackgroundWorkerExit (RegisteredBgWorker * rw )
487
486
{
488
- RegisteredBgWorker * rw ;
489
487
BackgroundWorkerSlot * slot ;
490
488
int notify_pid ;
491
489
492
- rw = slist_container (RegisteredBgWorker , rw_lnode , cur -> cur );
493
-
494
490
Assert (rw -> rw_shmem_slot < max_worker_processes );
495
491
slot = & BackgroundWorkerData -> slot [rw -> rw_shmem_slot ];
496
492
slot -> pid = rw -> rw_pid ;
@@ -505,7 +501,7 @@ ReportBackgroundWorkerExit(slist_mutable_iter *cur)
505
501
*/
506
502
if (rw -> rw_terminate ||
507
503
rw -> rw_worker .bgw_restart_time == BGW_NEVER_RESTART )
508
- ForgetBackgroundWorker (cur );
504
+ ForgetBackgroundWorker (rw );
509
505
510
506
if (notify_pid != 0 )
511
507
kill (notify_pid , SIGUSR1 );
@@ -519,13 +515,13 @@ ReportBackgroundWorkerExit(slist_mutable_iter *cur)
519
515
void
520
516
BackgroundWorkerStopNotifications (pid_t pid )
521
517
{
522
- slist_iter siter ;
518
+ dlist_iter iter ;
523
519
524
- slist_foreach ( siter , & BackgroundWorkerList )
520
+ dlist_foreach ( iter , & BackgroundWorkerList )
525
521
{
526
522
RegisteredBgWorker * rw ;
527
523
528
- rw = slist_container (RegisteredBgWorker , rw_lnode , siter .cur );
524
+ rw = dlist_container (RegisteredBgWorker , rw_lnode , iter .cur );
529
525
if (rw -> rw_worker .bgw_notify_pid == pid )
530
526
rw -> rw_worker .bgw_notify_pid = 0 ;
531
527
}
@@ -546,14 +542,14 @@ BackgroundWorkerStopNotifications(pid_t pid)
546
542
void
547
543
ForgetUnstartedBackgroundWorkers (void )
548
544
{
549
- slist_mutable_iter iter ;
545
+ dlist_mutable_iter iter ;
550
546
551
- slist_foreach_modify (iter , & BackgroundWorkerList )
547
+ dlist_foreach_modify (iter , & BackgroundWorkerList )
552
548
{
553
549
RegisteredBgWorker * rw ;
554
550
BackgroundWorkerSlot * slot ;
555
551
556
- rw = slist_container (RegisteredBgWorker , rw_lnode , iter .cur );
552
+ rw = dlist_container (RegisteredBgWorker , rw_lnode , iter .cur );
557
553
Assert (rw -> rw_shmem_slot < max_worker_processes );
558
554
slot = & BackgroundWorkerData -> slot [rw -> rw_shmem_slot ];
559
555
@@ -564,7 +560,7 @@ ForgetUnstartedBackgroundWorkers(void)
564
560
/* ... then zap it, and notify the waiter */
565
561
int notify_pid = rw -> rw_worker .bgw_notify_pid ;
566
562
567
- ForgetBackgroundWorker (& iter );
563
+ ForgetBackgroundWorker (rw );
568
564
if (notify_pid != 0 )
569
565
kill (notify_pid , SIGUSR1 );
570
566
}
@@ -584,13 +580,13 @@ ForgetUnstartedBackgroundWorkers(void)
584
580
void
585
581
ResetBackgroundWorkerCrashTimes (void )
586
582
{
587
- slist_mutable_iter iter ;
583
+ dlist_mutable_iter iter ;
588
584
589
- slist_foreach_modify (iter , & BackgroundWorkerList )
585
+ dlist_foreach_modify (iter , & BackgroundWorkerList )
590
586
{
591
587
RegisteredBgWorker * rw ;
592
588
593
- rw = slist_container (RegisteredBgWorker , rw_lnode , iter .cur );
589
+ rw = dlist_container (RegisteredBgWorker , rw_lnode , iter .cur );
594
590
595
591
if (rw -> rw_worker .bgw_restart_time == BGW_NEVER_RESTART )
596
592
{
@@ -601,7 +597,7 @@ ResetBackgroundWorkerCrashTimes(void)
601
597
* parallel_terminate_count will get incremented after we've
602
598
* already zeroed parallel_register_count, which would be bad.)
603
599
*/
604
- ForgetBackgroundWorker (& iter );
600
+ ForgetBackgroundWorker (rw );
605
601
}
606
602
else
607
603
{
@@ -1036,7 +1032,7 @@ RegisterBackgroundWorker(BackgroundWorker *worker)
1036
1032
rw -> rw_crashed_at = 0 ;
1037
1033
rw -> rw_terminate = false;
1038
1034
1039
- slist_push_head (& BackgroundWorkerList , & rw -> rw_lnode );
1035
+ dlist_push_head (& BackgroundWorkerList , & rw -> rw_lnode );
1040
1036
}
1041
1037
1042
1038
/*
0 commit comments