Skip to content

Commit 1ae1ad9

Browse files
nathan-bossartCommitfest Bot
authored andcommitted
Fix shmem_startup_hook documentation.
1 parent 06473f5 commit 1ae1ad9

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

doc/src/sgml/xfunc.sgml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3668,11 +3668,14 @@ LWLockRelease(AddinShmemInitLock);
36683668
</programlisting>
36693669
<literal>shmem_startup_hook</literal> provides a convenient place for the
36703670
initialization code, but it is not strictly required that all such code
3671-
be placed in this hook. Each backend will execute the registered
3672-
<literal>shmem_startup_hook</literal> shortly after it attaches to shared
3673-
memory. Note that add-ins should still acquire
3671+
be placed in this hook. On Windows (and anywhere else where
3672+
<literal>EXEC_BACKEND</literal> is defined), each backend executes the
3673+
registered <literal>shmem_startup_hook</literal> shortly after it
3674+
attaches to shared memory, so add-ins should still acquire
36743675
<function>AddinShmemInitLock</function> within this hook, as shown in the
3675-
example above.
3676+
example above. On other platforms, the postmaster process executes the
3677+
<literal>shmem_startup_hook</literal> once, and each backend
3678+
automatically inherits the pointers to shared memory.
36763679
</para>
36773680

36783681
<para>

src/test/modules/test_slru/test_slru.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,8 @@ test_slru_shmem_startup(void)
219219
*/
220220
const bool long_segment_names = true;
221221
const char slru_dir_name[] = "pg_test_slru";
222-
int test_tranche_id;
223-
int test_buffer_tranche_id;
222+
int test_tranche_id = -1;
223+
int test_buffer_tranche_id = -1;
224224

225225
if (prev_shmem_startup_hook)
226226
prev_shmem_startup_hook();
@@ -231,10 +231,19 @@ test_slru_shmem_startup(void)
231231
*/
232232
(void) MakePGDirectory(slru_dir_name);
233233

234-
/* initialize the SLRU facility */
235-
test_tranche_id = LWLockNewTrancheId("test_slru_tranche");
236-
237-
test_buffer_tranche_id = LWLockNewTrancheId("test_buffer_tranche");
234+
/*
235+
* Initialize the SLRU facility.
236+
*
237+
* In EXEC_BACKEND builds, the shmem_startup_hook is called in the
238+
* postmaster and in each backend, but we only need to generate the LWLock
239+
* tranches once. Note that these IDs are not used by SimpleLruInit() in
240+
* the IsUnderPostmaster (i.e., backend) case.
241+
*/
242+
if (!IsUnderPostmaster)
243+
{
244+
test_tranche_id = LWLockNewTrancheId("test_slru_tranche");
245+
test_buffer_tranche_id = LWLockNewTrancheId("test_buffer_tranche");
246+
}
238247

239248
TestSlruCtl->PagePrecedes = test_slru_page_precedes_logically;
240249
SimpleLruInit(TestSlruCtl, "TestSLRU",

0 commit comments

Comments
 (0)