@@ -37,6 +37,11 @@ static int guc_batch_size;
3737static char * guc_database_name ;
3838static char * guc_username ;
3939static MemoryContext CurlMemContext = NULL ;
40+
41+ #if PG15_GTE
42+ static shmem_request_hook_type prev_shmem_request_hook = NULL ;
43+ #endif
44+
4045static shmem_startup_hook_type prev_shmem_startup_hook = NULL ;
4146static volatile sig_atomic_t got_sighup = false;
4247
@@ -357,12 +362,27 @@ void pg_net_worker(__attribute__ ((unused)) Datum main_arg) {
357362 proc_exit (EXIT_FAILURE );
358363}
359364
365+ static Size net_memsize (void ) {
366+ return MAXALIGN (sizeof (WorkerState ));
367+ }
368+
369+ #if PG15_GTE
370+ static void net_shmem_request (void ) {
371+ if (prev_shmem_request_hook )
372+ prev_shmem_request_hook ();
373+
374+ RequestAddinShmemSpace (net_memsize ());
375+ }
376+ #endif
377+
360378static void net_shmem_startup (void ) {
361379 if (prev_shmem_startup_hook )
362380 prev_shmem_startup_hook ();
363381
364382 bool found ;
365383
384+ LWLockAcquire (AddinShmemInitLock , LW_EXCLUSIVE );
385+
366386 worker_state = ShmemInitStruct ("pg_net worker state" , sizeof (WorkerState ), & found );
367387
368388 if (!found ) {
@@ -375,6 +395,8 @@ static void net_shmem_startup(void) {
375395 worker_state -> epfd = 0 ;
376396 worker_state -> curl_mhandle = NULL ;
377397 }
398+
399+ LWLockRelease (AddinShmemInitLock );
378400}
379401
380402void _PG_init (void ) {
@@ -397,6 +419,13 @@ void _PG_init(void) {
397419 .bgw_restart_time = net_worker_restart_time_sec ,
398420 });
399421
422+ #if PG15_GTE
423+ prev_shmem_request_hook = shmem_request_hook ;
424+ shmem_request_hook = net_shmem_request ;
425+ #else
426+ RequestAddinShmemSpace (net_memsize ());
427+ #endif
428+
400429 prev_shmem_startup_hook = shmem_startup_hook ;
401430 shmem_startup_hook = net_shmem_startup ;
402431
0 commit comments