PostgreSQL Source Code  git master
test_dsm_registry.c File Reference
#include "postgres.h"
#include "fmgr.h"
#include "storage/dsm_registry.h"
#include "storage/lwlock.h"
Include dependency graph for test_dsm_registry.c:

Go to the source code of this file.

Data Structures

struct  TestDSMRegistryStruct
 

Typedefs

typedef struct TestDSMRegistryStruct TestDSMRegistryStruct
 

Functions

static void tdr_init_shmem (void *ptr)
 
static void tdr_attach_shmem (void)
 
 PG_FUNCTION_INFO_V1 (set_val_in_shmem)
 
Datum set_val_in_shmem (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (get_val_in_shmem)
 
Datum get_val_in_shmem (PG_FUNCTION_ARGS)
 

Variables

 PG_MODULE_MAGIC
 
static TestDSMRegistryStructtdr_state
 

Typedef Documentation

◆ TestDSMRegistryStruct

Function Documentation

◆ get_val_in_shmem()

Datum get_val_in_shmem ( PG_FUNCTION_ARGS  )

Definition at line 65 of file test_dsm_registry.c.

66 {
67  int ret;
68 
70 
72  ret = tdr_state->val;
74 
75  PG_RETURN_UINT32(ret);
76 }
#define PG_RETURN_UINT32(x)
Definition: fmgr.h:355
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_SHARED
Definition: lwlock.h:115
static TestDSMRegistryStruct * tdr_state
static void tdr_attach_shmem(void)

References TestDSMRegistryStruct::lck, LW_SHARED, LWLockAcquire(), LWLockRelease(), PG_RETURN_UINT32, tdr_attach_shmem(), tdr_state, and TestDSMRegistryStruct::val.

◆ PG_FUNCTION_INFO_V1() [1/2]

PG_FUNCTION_INFO_V1 ( get_val_in_shmem  )

◆ PG_FUNCTION_INFO_V1() [2/2]

PG_FUNCTION_INFO_V1 ( set_val_in_shmem  )

◆ set_val_in_shmem()

Datum set_val_in_shmem ( PG_FUNCTION_ARGS  )

Definition at line 52 of file test_dsm_registry.c.

53 {
55 
59 
61 }
#define PG_RETURN_VOID()
Definition: fmgr.h:349
#define PG_GETARG_UINT32(n)
Definition: fmgr.h:270
@ LW_EXCLUSIVE
Definition: lwlock.h:114

References TestDSMRegistryStruct::lck, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), PG_GETARG_UINT32, PG_RETURN_VOID, tdr_attach_shmem(), tdr_state, and TestDSMRegistryStruct::val.

◆ tdr_attach_shmem()

static void tdr_attach_shmem ( void  )
static

Definition at line 39 of file test_dsm_registry.c.

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 }
void * GetNamedDSMSegment(const char *name, size_t size, void(*init_callback)(void *ptr), bool *found)
Definition: dsm_registry.c:131
void LWLockRegisterTranche(int tranche_id, const char *tranche_name)
Definition: lwlock.c:628
uint16 tranche
Definition: lwlock.h:43
static void tdr_init_shmem(void *ptr)

References GetNamedDSMSegment(), TestDSMRegistryStruct::lck, LWLockRegisterTranche(), tdr_init_shmem(), tdr_state, and LWLock::tranche.

Referenced by get_val_in_shmem(), and set_val_in_shmem().

◆ tdr_init_shmem()

static void tdr_init_shmem ( void *  ptr)
static

Definition at line 30 of file test_dsm_registry.c.

31 {
33 
35  state->val = 0;
36 }
int LWLockNewTrancheId(void)
Definition: lwlock.c:603
void LWLockInitialize(LWLock *lock, int tranche_id)
Definition: lwlock.c:707
Definition: regguts.h:323

References LWLockInitialize(), and LWLockNewTrancheId().

Referenced by tdr_attach_shmem().

Variable Documentation

◆ PG_MODULE_MAGIC

PG_MODULE_MAGIC

Definition at line 19 of file test_dsm_registry.c.

◆ tdr_state

TestDSMRegistryStruct* tdr_state
static

Definition at line 27 of file test_dsm_registry.c.

Referenced by get_val_in_shmem(), set_val_in_shmem(), and tdr_attach_shmem().