PostgreSQL Source Code  git master
dsm_registry.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void * GetNamedDSMSegment (const char *name, size_t size, void(*init_callback)(void *ptr), bool *found)
 
Size DSMRegistryShmemSize (void)
 
void DSMRegistryShmemInit (void)
 

Function Documentation

◆ DSMRegistryShmemInit()

void DSMRegistryShmemInit ( void  )

Definition at line 69 of file dsm_registry.c.

70 {
71  bool found;
72 
74  ShmemInitStruct("DSM Registry Data",
76  &found);
77 
78  if (!found)
79  {
82  }
83 }
#define DSA_HANDLE_INVALID
Definition: dsa.h:139
#define DSHASH_HANDLE_INVALID
Definition: dshash.h:27
static DSMRegistryCtxStruct * DSMRegistryCtx
Definition: dsm_registry.c:41
Size DSMRegistryShmemSize(void)
Definition: dsm_registry.c:63
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:387
dshash_table_handle dshh
Definition: dsm_registry.c:38

References DSA_HANDLE_INVALID, DSMRegistryCtxStruct::dsah, DSHASH_HANDLE_INVALID, DSMRegistryCtxStruct::dshh, DSMRegistryCtx, DSMRegistryShmemSize(), and ShmemInitStruct().

Referenced by CreateOrAttachShmemStructs().

◆ DSMRegistryShmemSize()

Size DSMRegistryShmemSize ( void  )

Definition at line 63 of file dsm_registry.c.

64 {
65  return MAXALIGN(sizeof(DSMRegistryCtxStruct));
66 }
#define MAXALIGN(LEN)
Definition: c.h:811

References MAXALIGN.

Referenced by CalculateShmemSize(), and DSMRegistryShmemInit().

◆ GetNamedDSMSegment()

void* GetNamedDSMSegment ( const char *  name,
size_t  size,
void(*)(void *ptr)  init_callback,
bool found 
)

Definition at line 131 of file dsm_registry.c.

133 {
134  DSMRegistryEntry *entry;
135  MemoryContext oldcontext;
136  void *ret;
137 
138  Assert(found);
139 
140  if (!name || *name == '\0')
141  ereport(ERROR,
142  (errmsg("DSM segment name cannot be empty")));
143 
144  if (strlen(name) >= offsetof(DSMRegistryEntry, handle))
145  ereport(ERROR,
146  (errmsg("DSM segment name too long")));
147 
148  if (size == 0)
149  ereport(ERROR,
150  (errmsg("DSM segment size must be nonzero")));
151 
152  /* Be sure any local memory allocated by DSM/DSA routines is persistent. */
154 
155  /* Connect to the registry. */
157 
159  if (!(*found))
160  {
161  /* Initialize the segment. */
162  dsm_segment *seg = dsm_create(size, 0);
163 
164  dsm_pin_segment(seg);
165  dsm_pin_mapping(seg);
166  entry->handle = dsm_segment_handle(seg);
167  entry->size = size;
168  ret = dsm_segment_address(seg);
169 
170  if (init_callback)
171  (*init_callback) (ret);
172  }
173  else if (entry->size != size)
174  {
175  ereport(ERROR,
176  (errmsg("requested DSM segment size does not match size of "
177  "existing segment")));
178  }
179  else
180  {
181  dsm_segment *seg = dsm_find_mapping(entry->handle);
182 
183  /* If the existing segment is not already attached, attach it now. */
184  if (seg == NULL)
185  {
186  seg = dsm_attach(entry->handle);
187  if (seg == NULL)
188  elog(ERROR, "could not map dynamic shared memory segment");
189 
190  dsm_pin_mapping(seg);
191  }
192 
193  ret = dsm_segment_address(seg);
194  }
195 
197  MemoryContextSwitchTo(oldcontext);
198 
199  return ret;
200 }
#define Assert(condition)
Definition: c.h:858
void dshash_release_lock(dshash_table *hash_table, void *entry)
Definition: dshash.c:558
void * dshash_find_or_insert(dshash_table *hash_table, const void *key, bool *found)
Definition: dshash.c:433
dsm_handle dsm_segment_handle(dsm_segment *seg)
Definition: dsm.c:1123
void * dsm_segment_address(dsm_segment *seg)
Definition: dsm.c:1095
dsm_segment * dsm_attach(dsm_handle h)
Definition: dsm.c:665
dsm_segment * dsm_create(Size size, int flags)
Definition: dsm.c:516
void dsm_pin_mapping(dsm_segment *seg)
Definition: dsm.c:915
void dsm_pin_segment(dsm_segment *seg)
Definition: dsm.c:955
dsm_segment * dsm_find_mapping(dsm_handle handle)
Definition: dsm.c:1076
static void init_dsm_registry(void)
Definition: dsm_registry.c:91
static dshash_table * dsm_registry_table
Definition: dsm_registry.c:60
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:224
#define ereport(elevel,...)
Definition: elog.h:149
MemoryContext TopMemoryContext
Definition: mcxt.c:149
MemoryContextSwitchTo(old_ctx)
static pg_noinline void Size size
Definition: slab.c:607
dsm_handle handle
Definition: dsm_registry.c:46
const char * name

References Assert, dshash_find_or_insert(), dshash_release_lock(), dsm_attach(), dsm_create(), dsm_find_mapping(), dsm_pin_mapping(), dsm_pin_segment(), dsm_registry_table, dsm_segment_address(), dsm_segment_handle(), elog, ereport, errmsg(), ERROR, DSMRegistryEntry::handle, init_dsm_registry(), MemoryContextSwitchTo(), name, DSMRegistryEntry::size, size, and TopMemoryContext.

Referenced by apw_init_shmem(), injection_init_shmem(), and tdr_attach_shmem().