* It sets up the response queues for backend workers to return tuples * to the main backend and start the workers. */
| 536 | * to the main backend and start the workers. |
| 537 | */ |
| 538 | static shm_mq_handle ** |
| 539 | ExecParallelSetupTupleQueues(ParallelContext *pcxt, bool reinitialize) |
| 540 | { |
| 541 | shm_mq_handle **responseq; |
| 542 | char *tqueuespace; |
| 543 | int i; |
| 544 | |
| 545 | /* Skip this if no workers. */ |
| 546 | if (pcxt->nworkers == 0) |
| 547 | return NULL; |
| 548 | |
| 549 | /* Allocate memory for shared memory queue handles. */ |
| 550 | responseq = (shm_mq_handle **) |
| 551 | palloc(pcxt->nworkers * sizeof(shm_mq_handle *)); |
| 552 | |
| 553 | /* |
| 554 | * If not reinitializing, allocate space from the DSM for the queues; |
| 555 | * otherwise, find the already allocated space. |
| 556 | */ |
| 557 | if (!reinitialize) |
| 558 | tqueuespace = |
| 559 | shm_toc_allocate(pcxt->toc, |
| 560 | mul_size(PARALLEL_TUPLE_QUEUE_SIZE, |
| 561 | pcxt->nworkers)); |
| 562 | else |
| 563 | tqueuespace = shm_toc_lookup(pcxt->toc, PARALLEL_KEY_TUPLE_QUEUE, false); |
| 564 | |
| 565 | /* Create the queues, and become the receiver for each. */ |
| 566 | for (i = 0; i < pcxt->nworkers; ++i) |
| 567 | { |
| 568 | shm_mq *mq; |
| 569 | |
| 570 | mq = shm_mq_create(tqueuespace + |
| 571 | ((Size) i) * PARALLEL_TUPLE_QUEUE_SIZE, |
| 572 | (Size) PARALLEL_TUPLE_QUEUE_SIZE); |
| 573 | |
| 574 | shm_mq_set_receiver(mq, MyProc); |
| 575 | responseq[i] = shm_mq_attach(mq, pcxt->seg, NULL); |
| 576 | } |
| 577 | |
| 578 | /* Add array of queues to shm_toc, so others can find it. */ |
| 579 | if (!reinitialize) |
| 580 | shm_toc_insert(pcxt->toc, PARALLEL_KEY_TUPLE_QUEUE, tqueuespace); |
| 581 | |
| 582 | /* Return array of handles. */ |
| 583 | return responseq; |
| 584 | } |
| 585 | |
| 586 | /* |
| 587 | * Sets up the required infrastructure for backend workers to perform |
no test coverage detected