* Count up number of child processes of specified types (dead_end children * are always excluded). */
| 6021 | * are always excluded). |
| 6022 | */ |
| 6023 | static int |
| 6024 | CountChildren(int target) |
| 6025 | { |
| 6026 | dlist_iter iter; |
| 6027 | int cnt = 0; |
| 6028 | |
| 6029 | dlist_foreach(iter, &BackendList) |
| 6030 | { |
| 6031 | Backend *bp = dlist_container(Backend, elem, iter.cur); |
| 6032 | |
| 6033 | if (bp->dead_end) |
| 6034 | continue; |
| 6035 | |
| 6036 | /* |
| 6037 | * Since target == BACKEND_TYPE_ALL is the most common case, we test |
| 6038 | * it first and avoid touching shared memory for every child. |
| 6039 | */ |
| 6040 | if (target != BACKEND_TYPE_ALL) |
| 6041 | { |
| 6042 | /* |
| 6043 | * Assign bkend_type for any recently announced WAL Sender |
| 6044 | * processes. |
| 6045 | */ |
| 6046 | if (bp->bkend_type == BACKEND_TYPE_NORMAL && |
| 6047 | IsPostmasterChildWalSender(bp->child_slot)) |
| 6048 | bp->bkend_type = BACKEND_TYPE_WALSND; |
| 6049 | |
| 6050 | if (!(target & bp->bkend_type)) |
| 6051 | continue; |
| 6052 | } |
| 6053 | |
| 6054 | cnt++; |
| 6055 | } |
| 6056 | return cnt; |
| 6057 | } |
| 6058 | |
| 6059 | |
| 6060 | /* |
no test coverage detected