PostgreSQL Source Code git master
Loading...
Searching...
No Matches
test_shmem.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "miscadmin.h"
#include "storage/shmem.h"
Include dependency graph for test_shmem.c:

Go to the source code of this file.

Data Structures

struct  TestShmemData
 

Typedefs

typedef struct TestShmemData TestShmemData
 

Functions

static void test_shmem_request (void *arg)
 
static void test_shmem_init (void *arg)
 
static void test_shmem_attach (void *arg)
 
void _PG_init (void)
 
 PG_FUNCTION_INFO_V1 (get_test_shmem_attach_count)
 
Datum get_test_shmem_attach_count (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static TestShmemDataTestShmem
 
static bool attached_or_initialized = false
 
static const ShmemCallbacks TestShmemCallbacks
 

Typedef Documentation

◆ TestShmemData

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 86 of file test_shmem.c.

87{
88 elog(LOG, "test_shmem module's _PG_init called");
90}
#define LOG
Definition elog.h:31
#define elog(elevel,...)
Definition elog.h:227
void RegisterShmemCallbacks(const ShmemCallbacks *callbacks)
Definition shmem.c:874
static const ShmemCallbacks TestShmemCallbacks
Definition test_shmem.c:42

References elog, LOG, RegisterShmemCallbacks(), and TestShmemCallbacks.

◆ get_test_shmem_attach_count()

Datum get_test_shmem_attach_count ( PG_FUNCTION_ARGS  )

Definition at line 94 of file test_shmem.c.

95{
97 elog(ERROR, "shmem area not attached or initialized in this process");
99 elog(ERROR, "shmem area not yet initialized");
101}
#define ERROR
Definition elog.h:39
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
static TestShmemData * TestShmem
Definition test_shmem.c:34
static bool attached_or_initialized
Definition test_shmem.c:36

References TestShmemData::attach_count, attached_or_initialized, elog, ERROR, TestShmemData::initialized, PG_RETURN_INT32, and TestShmem.

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( get_test_shmem_attach_count  )

◆ test_shmem_attach()

static void test_shmem_attach ( void arg)
static

Definition at line 73 of file test_shmem.c.

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}

References TestShmemData::attach_count, attached_or_initialized, elog, ERROR, TestShmemData::initialized, LOG, and TestShmem.

◆ test_shmem_init()

static void test_shmem_init ( void arg)
static

Definition at line 60 of file test_shmem.c.

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}

References attached_or_initialized, elog, ERROR, TestShmemData::initialized, LOG, and TestShmem.

◆ test_shmem_request()

static void test_shmem_request ( void arg)
static

Definition at line 50 of file test_shmem.c.

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}
#define ShmemRequestStruct(...)
Definition shmem.h:176
const char * name

References elog, LOG, name, ShmemRequestStruct, and TestShmem.

Variable Documentation

◆ attached_or_initialized

bool attached_or_initialized = false
static

Definition at line 36 of file test_shmem.c.

Referenced by get_test_shmem_attach_count(), test_shmem_attach(), and test_shmem_init().

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 25 of file test_shmem.c.

◆ TestShmem

TestShmemData* TestShmem
static

◆ TestShmemCallbacks

const ShmemCallbacks TestShmemCallbacks
static
Initial value:
= {
.request_fn = test_shmem_request,
.init_fn = test_shmem_init,
.attach_fn = test_shmem_attach,
}
#define SHMEM_CALLBACKS_ALLOW_AFTER_STARTUP
Definition shmem.h:167
static void test_shmem_attach(void *arg)
Definition test_shmem.c:73
static void test_shmem_request(void *arg)
Definition test_shmem.c:50
static void test_shmem_init(void *arg)
Definition test_shmem.c:60

Definition at line 42 of file test_shmem.c.

42 {
44 .request_fn = test_shmem_request,
45 .init_fn = test_shmem_init,
46 .attach_fn = test_shmem_attach,
47};

Referenced by _PG_init().