File tree Expand file tree Collapse file tree 1 file changed +36
-17
lines changed Expand file tree Collapse file tree 1 file changed +36
-17
lines changed Original file line number Diff line number Diff line change @@ -666,29 +666,48 @@ supervisor_children_disable_obsolete(void)
666
666
return count ;
667
667
}
668
668
669
+ static inline int
670
+ _is_dead (const pid_t needle , pid_t * pincushion , register const int max )
671
+ {
672
+ for (register int i = 0 ; i < max ;++ i ) {
673
+ if (needle == pincushion [i ])
674
+ return 1 ;
675
+ }
676
+ return 0 ;
677
+ }
678
+
669
679
guint
670
680
supervisor_children_catharsis (void * udata , supervisor_cb_f cb )
671
681
{
672
- pid_t pid_dead ;
673
- guint count ;
674
682
struct child_s * sd ;
675
- struct child_info_s ci ;
683
+ guint count = 0 ;
684
+ int pids_idx = 0 ;
685
+ pid_t pid ;
686
+ pid_t pids [1024 ];
676
687
677
- count = 0 ;
678
- while ((pid_dead = waitpid (-1 , NULL , WNOHANG )) > 0 ) {
679
- FOREACH_CHILD (sd ) {
680
- if (sd -> pid == pid_dead ) {
681
- count ++ ;
682
- _child_notify_death (sd );
683
- if (cb ) {
684
- _child_get_info (sd , & ci );
685
- cb (udata , & ci );
686
- }
687
- sd -> pid = -1 ;
688
- break ;
689
- }
690
- }
688
+ g_assert_nonnull (cb );
689
+
690
+ /* Consume a batch of dead children */
691
+ while (pids_idx < 1024 && (pid = waitpid (-1 , NULL , WNOHANG )) > 0 )
692
+ pids [pids_idx ++ ] = pid ;
693
+ if (!pids_idx )
694
+ return 0 ;
695
+
696
+ /* Locate the concerned structures, for each dead child */
697
+ FOREACH_CHILD (sd ) {
698
+ if (!_is_dead (sd -> pid , pids , pids_idx ))
699
+ continue ;
700
+
701
+ count ++ ;
702
+ _child_notify_death (sd );
703
+
704
+ struct child_info_s ci = {};
705
+ _child_get_info (sd , & ci );
706
+ cb (udata , & ci );
707
+
708
+ sd -> pid = -1 ;
691
709
}
710
+
692
711
return count ;
693
712
}
694
713
You can’t perform that action at this time.
0 commit comments