* InitProcess -- initialize a per-process data structure for this backend */
| 346 | * InitProcess -- initialize a per-process data structure for this backend |
| 347 | */ |
| 348 | void |
| 349 | InitProcess(void) |
| 350 | { |
| 351 | PGPROC *volatile *procgloballist; |
| 352 | |
| 353 | /* |
| 354 | * WAL sender, etc are marked as GP_ROLE_UTILITY to prevent unwanted |
| 355 | * GP_ROLE_DISPATCH MyProc settings such as mppSessionId being valid and |
| 356 | * mppIsWriter set to true. |
| 357 | */ |
| 358 | if (am_walsender || am_ftshandler || am_faulthandler) |
| 359 | Gp_role = GP_ROLE_UTILITY; |
| 360 | |
| 361 | /* |
| 362 | * ProcGlobal should be set up already (if we are a backend, we inherit |
| 363 | * this by fork() or EXEC_BACKEND mechanism from the postmaster). |
| 364 | */ |
| 365 | if (ProcGlobal == NULL) |
| 366 | elog(PANIC, "proc header uninitialized"); |
| 367 | |
| 368 | if (MyProc != NULL) |
| 369 | elog(ERROR, "you already exist"); |
| 370 | |
| 371 | /* Decide which list should supply our PGPROC. */ |
| 372 | if (IsAnyAutoVacuumProcess()) |
| 373 | procgloballist = &ProcGlobal->autovacFreeProcs; |
| 374 | else if (IsAnyLoginMonitorProcess()) |
| 375 | procgloballist = &ProcGlobal->lmFreeProcs; |
| 376 | else if (IsBackgroundWorker) |
| 377 | procgloballist = &ProcGlobal->bgworkerFreeProcs; |
| 378 | else if (am_walsender) |
| 379 | procgloballist = &ProcGlobal->walsenderFreeProcs; |
| 380 | else |
| 381 | procgloballist = &ProcGlobal->freeProcs; |
| 382 | |
| 383 | /* |
| 384 | * Try to get a proc struct from the appropriate free list. If this |
| 385 | * fails, we must be out of PGPROC structures (not to mention semaphores). |
| 386 | * |
| 387 | * While we are holding the ProcStructLock, also copy the current shared |
| 388 | * estimate of spins_per_delay to local storage. |
| 389 | */ |
| 390 | SpinLockAcquire(ProcStructLock); |
| 391 | |
| 392 | set_spins_per_delay(ProcGlobal->spins_per_delay); |
| 393 | |
| 394 | MyProc = *procgloballist; |
| 395 | |
| 396 | if (MyProc != NULL) |
| 397 | { |
| 398 | *procgloballist = (PGPROC *) MyProc->links.next; |
| 399 | SpinLockRelease(ProcStructLock); |
| 400 | } |
| 401 | else |
| 402 | { |
| 403 | /* |
| 404 | * If we reach here, all the PGPROCs are in use. This is one of the |
| 405 | * possible places to detect "too many backends", so give the standard |
no test coverage detected