PostgreSQL Source Code git master
Loading...
Searching...
No Matches
test_shmem.c
Go to the documentation of this file.
1/*-------------------------------------------------------------------------
2 *
3 * test_shmem.c
4 * Helpers to test shmem allocation routines
5 *
6 * Test basic memory allocation in an extension module. One notable feature
7 * that is not exercised by any other module in the repository is the
8 * allocating (non-DSM) shared memory after postmaster startup.
9 *
10 * Copyright (c) 2020-2026, PostgreSQL Global Development Group
11 *
12 * IDENTIFICATION
13 * src/test/modules/test_shmem/test_shmem.c
14 *
15 *-------------------------------------------------------------------------
16 */
17
18#include "postgres.h"
19
20#include "fmgr.h"
21#include "miscadmin.h"
22#include "storage/shmem.h"
23
24
26
33
35
36static bool attached_or_initialized = false;
37
38static void test_shmem_request(void *arg);
39static void test_shmem_init(void *arg);
40static void test_shmem_attach(void *arg);
41
44 .request_fn = test_shmem_request,
45 .init_fn = test_shmem_init,
46 .attach_fn = test_shmem_attach,
47};
48
49static void
51{
52 elog(LOG, "test_shmem_request callback called");
53
54 ShmemRequestStruct(.name = "test_shmem area",
55 .size = sizeof(TestShmemData),
56 .ptr = (void **) &TestShmem);
57}
58
59static void
61{
62 elog(LOG, "init callback called");
64 elog(ERROR, "shmem area already initialized");
65 TestShmem->initialized = true;
66
68 elog(ERROR, "attach or initialize already called in this process");
70}
71
72static void
74{
75 elog(LOG, "test_shmem_attach callback called");
77 elog(ERROR, "shmem area not yet initialized");
79
81 elog(ERROR, "attach or initialize already called in this process");
83}
84
85void
87{
88 elog(LOG, "test_shmem module's _PG_init called");
90}
91
95{
97 elog(ERROR, "shmem area not attached or initialized in this process");
99 elog(ERROR, "shmem area not yet initialized");
101}
Datum arg
Definition elog.c:1322
#define LOG
Definition elog.h:31
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:227
#define PG_FUNCTION_INFO_V1(funcname)
Definition fmgr.h:417
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
uint64_t Datum
Definition postgres.h:70
void RegisterShmemCallbacks(const ShmemCallbacks *callbacks)
Definition shmem.c:871
#define ShmemRequestStruct(...)
Definition shmem.h:176
#define SHMEM_CALLBACKS_ALLOW_AFTER_STARTUP
Definition shmem.h:167
void _PG_init(void)
Definition test_shmem.c:86
static TestShmemData * TestShmem
Definition test_shmem.c:34
static const ShmemCallbacks TestShmemCallbacks
Definition test_shmem.c:42
static bool attached_or_initialized
Definition test_shmem.c:36
PG_MODULE_MAGIC
Definition test_shmem.c:25
static void test_shmem_attach(void *arg)
Definition test_shmem.c:73
Datum get_test_shmem_attach_count(PG_FUNCTION_ARGS)
Definition test_shmem.c:94
static void test_shmem_request(void *arg)
Definition test_shmem.c:50
static void test_shmem_init(void *arg)
Definition test_shmem.c:60
const char * name