PostgreSQL Source Code  git master
test_dsm_registry.c
Go to the documentation of this file.
1 /*--------------------------------------------------------------------------
2  *
3  * test_dsm_registry.c
4  * Test the dynamic shared memory registry.
5  *
6  * Copyright (c) 2024, PostgreSQL Global Development Group
7  *
8  * IDENTIFICATION
9  * src/test/modules/test_dsm_registry/test_dsm_registry.c
10  *
11  * -------------------------------------------------------------------------
12  */
13 #include "postgres.h"
14 
15 #include "fmgr.h"
16 #include "storage/dsm_registry.h"
17 #include "storage/lwlock.h"
18 
20 
21 typedef struct TestDSMRegistryStruct
22 {
23  int val;
26 
28 
29 static void
30 tdr_init_shmem(void *ptr)
31 {
33 
35  state->val = 0;
36 }
37 
38 static void
40 {
41  bool found;
42 
43  tdr_state = GetNamedDSMSegment("test_dsm_registry",
44  sizeof(TestDSMRegistryStruct),
46  &found);
47  LWLockRegisterTranche(tdr_state->lck.tranche, "test_dsm_registry");
48 }
49 
51 Datum
53 {
55 
59 
61 }
62 
64 Datum
66 {
67  int ret;
68 
70 
72  ret = tdr_state->val;
74 
75  PG_RETURN_UINT32(ret);
76 }
void * GetNamedDSMSegment(const char *name, size_t size, void(*init_callback)(void *ptr), bool *found)
Definition: dsm_registry.c:131
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_RETURN_UINT32(x)
Definition: fmgr.h:355
#define PG_GETARG_UINT32(n)
Definition: fmgr.h:270
#define PG_FUNCTION_ARGS
Definition: fmgr.h:193
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1170
void LWLockRegisterTranche(int tranche_id, const char *tranche_name)
Definition: lwlock.c:630
int LWLockNewTrancheId(void)
Definition: lwlock.c:606
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1783
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:709
@ LW_SHARED
Definition: lwlock.h:115
@ LW_EXCLUSIVE
Definition: lwlock.h:114
uintptr_t Datum
Definition: postgres.h:64
Definition: lwlock.h:42
uint16 tranche
Definition: lwlock.h:43
Definition: regguts.h:323
static TestDSMRegistryStruct * tdr_state
Datum set_val_in_shmem(PG_FUNCTION_ARGS)
PG_MODULE_MAGIC
Datum get_val_in_shmem(PG_FUNCTION_ARGS)
static void tdr_attach_shmem(void)
static void tdr_init_shmem(void *ptr)
PG_FUNCTION_INFO_V1(set_val_in_shmem)
struct TestDSMRegistryStruct TestDSMRegistryStruct