PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
shmem.h File Reference
#include "utils/hsearch.h"
Include dependency graph for shmem.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SHM_QUEUE
 
struct  ShmemIndexEnt
 

Macros

#define SHMEM_INDEX_KEYSIZE   (48)
 
#define SHMEM_INDEX_SIZE   (64)
 

Typedefs

typedef struct SHM_QUEUE SHM_QUEUE
 

Functions

void InitShmemAccess (void *seghdr)
 
void InitShmemAllocation (void)
 
void * ShmemAlloc (Size size)
 
void * ShmemAllocNoError (Size size)
 
void * ShmemAllocUnlocked (Size size)
 
bool ShmemAddrIsValid (const void *addr)
 
void InitShmemIndex (void)
 
HTABShmemInitHash (const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
 
void * ShmemInitStruct (const char *name, Size size, bool *foundPtr)
 
Size add_size (Size s1, Size s2)
 
Size mul_size (Size s1, Size s2)
 
void RequestAddinShmemSpace (Size size)
 
void SHMQueueInit (SHM_QUEUE *queue)
 
void SHMQueueElemInit (SHM_QUEUE *queue)
 
void SHMQueueDelete (SHM_QUEUE *queue)
 
void SHMQueueInsertBefore (SHM_QUEUE *queue, SHM_QUEUE *elem)
 
void SHMQueueInsertAfter (SHM_QUEUE *queue, SHM_QUEUE *elem)
 
Pointer SHMQueueNext (const SHM_QUEUE *queue, const SHM_QUEUE *curElem, Size linkOffset)
 
Pointer SHMQueuePrev (const SHM_QUEUE *queue, const SHM_QUEUE *curElem, Size linkOffset)
 
bool SHMQueueEmpty (const SHM_QUEUE *queue)
 
bool SHMQueueIsDetached (const SHM_QUEUE *queue)
 

Macro Definition Documentation

#define SHMEM_INDEX_KEYSIZE   (48)

Definition at line 53 of file shmem.h.

Referenced by InitShmemIndex().

#define SHMEM_INDEX_SIZE   (64)

Definition at line 55 of file shmem.h.

Referenced by CreateSharedMemoryAndSemaphores(), and InitShmemIndex().

Typedef Documentation

Function Documentation

Size add_size ( Size  s1,
Size  s2 
)

Definition at line 475 of file shmem.c.

References ereport, errcode(), errmsg(), ERROR, result, and s2.

Referenced by ApplyLauncherShmemSize(), AsyncShmemInit(), AsyncShmemSize(), AutoVacuumShmemSize(), BackendStatusShmemSize(), BackgroundWorkerShmemSize(), BTreeShmemSize(), BufferShmemSize(), CheckpointerShmemSize(), CreateSharedMemoryAndSemaphores(), CreateSharedProcArray(), estimate_variable_size(), EstimateComboCIDStateSpace(), EstimateGUCStateSpace(), EstimateLibraryStateSpace(), EstimateParamListSpace(), EstimateSnapshotSpace(), EstimateTransactionStateSpace(), ExecBitmapHeapEstimate(), hash_estimate_size(), heap_parallelscan_estimate(), index_parallelscan_estimate(), index_parallelscan_initialize(), LockShmemSize(), LWLockShmemSize(), MultiXactShmemSize(), pgss_memsize(), PMSignalShmemSize(), PredicateLockShmemSize(), ProcArrayShmemSize(), ProcGlobalShmemSize(), ReplicationOriginShmemSize(), ReplicationSlotsShmemSize(), RequestAddinShmemSpace(), SerializeTransactionState(), shm_toc_estimate(), SInvalShmemSize(), SnapMgrShmemSize(), StrategyShmemSize(), TwoPhaseShmemSize(), WalRcvShmemSize(), WalSndShmemSize(), and XLOGShmemSize().

476 {
477  Size result;
478 
479  result = s1 + s2;
480  /* We are assuming Size is an unsigned type here... */
481  if (result < s1 || result < s2)
482  ereport(ERROR,
483  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
484  errmsg("requested shared memory size overflows size_t")));
485  return result;
486 }
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
char * s1
#define ereport(elevel, rest)
Definition: elog.h:122
char * s2
size_t Size
Definition: c.h:356
int errmsg(const char *fmt,...)
Definition: elog.c:797
void InitShmemAccess ( void *  seghdr)

Definition at line 97 of file shmem.c.

References ShmemBase, ShmemEnd, and PGShmemHeader::totalsize.

Referenced by CreateSharedMemoryAndSemaphores().

98 {
99  PGShmemHeader *shmhdr = (PGShmemHeader *) seghdr;
100 
101  ShmemSegHdr = shmhdr;
102  ShmemBase = (void *) shmhdr;
103  ShmemEnd = (char *) ShmemBase + shmhdr->totalsize;
104 }
static PGShmemHeader * ShmemSegHdr
Definition: shmem.c:78
static void * ShmemBase
Definition: shmem.c:80
static void * ShmemEnd
Definition: shmem.c:82
Size totalsize
Definition: pg_shmem.h:34
void InitShmemAllocation ( void  )

Definition at line 112 of file shmem.c.

References Assert, CACHELINEALIGN, PGShmemHeader::freeoffset, PGShmemHeader::index, NULL, ShmemAlloc(), ShmemAllocUnlocked(), ShmemLock, ShmemSegHdr, ShmemVariableCache, and SpinLockInit.

Referenced by CreateSharedMemoryAndSemaphores().

113 {
114  PGShmemHeader *shmhdr = ShmemSegHdr;
115  char *aligned;
116 
117  Assert(shmhdr != NULL);
118 
119  /*
120  * Initialize the spinlock used by ShmemAlloc. We must use
121  * ShmemAllocUnlocked, since obviously ShmemAlloc can't be called yet.
122  */
124 
126 
127  /*
128  * Allocations after this point should go through ShmemAlloc, which
129  * expects to allocate everything on cache line boundaries. Make sure the
130  * first allocation begins on a cache line boundary.
131  */
132  aligned = (char *)
133  (CACHELINEALIGN((((char *) shmhdr) + shmhdr->freeoffset)));
134  shmhdr->freeoffset = aligned - (char *) shmhdr;
135 
136  /* ShmemIndex can't be set up yet (need LWLocks first) */
137  shmhdr->index = NULL;
138  ShmemIndex = (HTAB *) NULL;
139 
140  /*
141  * Initialize ShmemVariableCache for transaction manager. (This doesn't
142  * really belong here, but not worth moving.)
143  */
145  ShmemAlloc(sizeof(*ShmemVariableCache));
146  memset(ShmemVariableCache, 0, sizeof(*ShmemVariableCache));
147 }
int slock_t
Definition: s_lock.h:888
VariableCacheData * VariableCache
Definition: transam.h:145
static PGShmemHeader * ShmemSegHdr
Definition: shmem.c:78
#define SpinLockInit(lock)
Definition: spin.h:60
void * ShmemAlloc(Size size)
Definition: shmem.c:157
static HTAB * ShmemIndex
Definition: shmem.c:87
Definition: dynahash.c:193
VariableCache ShmemVariableCache
Definition: varsup.c:34
void * ShmemAllocUnlocked(Size size)
Definition: shmem.c:227
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define CACHELINEALIGN(LEN)
Definition: c.h:591
Size freeoffset
Definition: pg_shmem.h:35
slock_t * ShmemLock
Definition: shmem.c:84
void * index
Definition: pg_shmem.h:37
void InitShmemIndex ( void  )

Definition at line 272 of file shmem.c.

References HASHCTL::entrysize, HASH_ELEM, HASHCTL::keysize, SHMEM_INDEX_KEYSIZE, SHMEM_INDEX_SIZE, and ShmemInitHash().

Referenced by CreateSharedMemoryAndSemaphores().

273 {
274  HASHCTL info;
275  int hash_flags;
276 
277  /*
278  * Create the shared memory shmem index.
279  *
280  * Since ShmemInitHash calls ShmemInitStruct, which expects the ShmemIndex
281  * hashtable to exist already, we have a bit of a circularity problem in
282  * initializing the ShmemIndex itself. The special "ShmemIndex" hash
283  * table name will tell ShmemInitStruct to fake it.
284  */
286  info.entrysize = sizeof(ShmemIndexEnt);
287  hash_flags = HASH_ELEM;
288 
289  ShmemIndex = ShmemInitHash("ShmemIndex",
291  &info, hash_flags);
292 }
#define SHMEM_INDEX_SIZE
Definition: shmem.h:55
#define HASH_ELEM
Definition: hsearch.h:87
Size entrysize
Definition: hsearch.h:73
static HTAB * ShmemIndex
Definition: shmem.c:87
Size keysize
Definition: hsearch.h:72
#define SHMEM_INDEX_KEYSIZE
Definition: shmem.h:53
HTAB * ShmemInitHash(const char *name, long init_size, long max_size, HASHCTL *infoP, int hash_flags)
Definition: shmem.c:317
Size mul_size ( Size  s1,
Size  s2 
)

Definition at line 492 of file shmem.c.

References ereport, errcode(), errmsg(), ERROR, result, and s2.

Referenced by ApplyLauncherShmemSize(), AsyncShmemInit(), AsyncShmemSize(), AutoVacuumShmemSize(), BackendStatusShmemSize(), BackgroundWorkerShmemSize(), BTreeShmemSize(), BufferShmemSize(), CheckpointerShmemSize(), CreateSharedBackendStatus(), CreateSharedProcArray(), EstimateComboCIDStateSpace(), EstimateSnapshotSpace(), EstimateTransactionStateSpace(), ExecInitParallelPlan(), ExecParallelRetrieveInstrumentation(), ExecParallelSetupTupleQueues(), hash_estimate_size(), InitializeParallelDSM(), InitPredicateLocks(), LWLockShmemSize(), PGSemaphoreShmemSize(), PMSignalShmemSize(), PredicateLockShmemSize(), ProcArrayShmemSize(), ProcGlobalShmemSize(), ReplicationOriginShmemSize(), ReplicationSlotsShmemSize(), shm_toc_estimate(), SInvalShmemSize(), SnapMgrShmemSize(), TwoPhaseShmemSize(), WalSndShmemSize(), and XLOGShmemSize().

493 {
494  Size result;
495 
496  if (s1 == 0 || s2 == 0)
497  return 0;
498  result = s1 * s2;
499  /* We are assuming Size is an unsigned type here... */
500  if (result / s2 != s1)
501  ereport(ERROR,
502  (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
503  errmsg("requested shared memory size overflows size_t")));
504  return result;
505 }
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
#define ERROR
Definition: elog.h:43
char * s1
#define ereport(elevel, rest)
Definition: elog.h:122
char * s2
size_t Size
Definition: c.h:356
int errmsg(const char *fmt,...)
Definition: elog.c:797
void RequestAddinShmemSpace ( Size  size)

Definition at line 69 of file ipci.c.

References add_size(), addin_request_allowed, IsUnderPostmaster, and total_addin_request.

Referenced by _PG_init().

70 {
72  return; /* too late */
74 }
bool IsUnderPostmaster
Definition: globals.c:100
static bool addin_request_allowed
Definition: ipci.c:54
static Size total_addin_request
Definition: ipci.c:53
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
bool ShmemAddrIsValid ( const void *  addr)

Definition at line 263 of file shmem.c.

References ShmemBase, and ShmemEnd.

Referenced by NextPredXact(), ReleasePredXact(), ShmemInitStruct(), SHMQueueDelete(), SHMQueueElemInit(), SHMQueueEmpty(), SHMQueueInit(), SHMQueueInsertAfter(), SHMQueueInsertBefore(), SHMQueueIsDetached(), SHMQueueNext(), and SHMQueuePrev().

264 {
265  return (addr >= ShmemBase) && (addr < ShmemEnd);
266 }
static void * ShmemBase
Definition: shmem.c:80
static void * ShmemEnd
Definition: shmem.c:82
void* ShmemAlloc ( Size  size)

Definition at line 157 of file shmem.c.

References ereport, errcode(), errmsg(), ERROR, and ShmemAllocNoError().

Referenced by CreateLWLocks(), InitPredicateLocks(), InitProcGlobal(), InitShmemAllocation(), ShmemInitStruct(), and SimpleLruInit().

158 {
159  void *newSpace;
160 
161  newSpace = ShmemAllocNoError(size);
162  if (!newSpace)
163  ereport(ERROR,
164  (errcode(ERRCODE_OUT_OF_MEMORY),
165  errmsg("out of shared memory (%zu bytes requested)",
166  size)));
167  return newSpace;
168 }
int errcode(int sqlerrcode)
Definition: elog.c:575
void * ShmemAllocNoError(Size size)
Definition: shmem.c:176
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
int errmsg(const char *fmt,...)
Definition: elog.c:797
void* ShmemAllocNoError ( Size  size)

Definition at line 176 of file shmem.c.

References Assert, CACHELINEALIGN, PGShmemHeader::freeoffset, NULL, ShmemBase, ShmemLock, SpinLockAcquire, SpinLockRelease, and totalsize.

Referenced by ShmemAlloc(), ShmemInitHash(), and ShmemInitStruct().

177 {
178  Size newStart;
179  Size newFree;
180  void *newSpace;
181 
182  /*
183  * Ensure all space is adequately aligned. We used to only MAXALIGN this
184  * space but experience has proved that on modern systems that is not good
185  * enough. Many parts of the system are very sensitive to critical data
186  * structures getting split across cache line boundaries. To avoid that,
187  * attempt to align the beginning of the allocation to a cache line
188  * boundary. The calling code will still need to be careful about how it
189  * uses the allocated space - e.g. by padding each element in an array of
190  * structures out to a power-of-two size - but without this, even that
191  * won't be sufficient.
192  */
193  size = CACHELINEALIGN(size);
194 
195  Assert(ShmemSegHdr != NULL);
196 
198 
199  newStart = ShmemSegHdr->freeoffset;
200 
201  newFree = newStart + size;
202  if (newFree <= ShmemSegHdr->totalsize)
203  {
204  newSpace = (void *) ((char *) ShmemBase + newStart);
205  ShmemSegHdr->freeoffset = newFree;
206  }
207  else
208  newSpace = NULL;
209 
211 
212  /* note this assert is okay with newSpace == NULL */
213  Assert(newSpace == (void *) CACHELINEALIGN(newSpace));
214 
215  return newSpace;
216 }
static PGShmemHeader * ShmemSegHdr
Definition: shmem.c:78
static void * ShmemBase
Definition: shmem.c:80
#define SpinLockAcquire(lock)
Definition: spin.h:62
static uint64 totalsize
#define SpinLockRelease(lock)
Definition: spin.h:64
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define CACHELINEALIGN(LEN)
Definition: c.h:591
Size freeoffset
Definition: pg_shmem.h:35
size_t Size
Definition: c.h:356
slock_t * ShmemLock
Definition: shmem.c:84
void* ShmemAllocUnlocked ( Size  size)

Definition at line 227 of file shmem.c.

References Assert, ereport, errcode(), errmsg(), ERROR, PGShmemHeader::freeoffset, MAXALIGN, NULL, ShmemBase, and PGShmemHeader::totalsize.

Referenced by InitShmemAllocation(), PGReserveSemaphores(), and SpinlockSemaInit().

228 {
229  Size newStart;
230  Size newFree;
231  void *newSpace;
232 
233  /*
234  * Ensure allocated space is adequately aligned.
235  */
236  size = MAXALIGN(size);
237 
238  Assert(ShmemSegHdr != NULL);
239 
240  newStart = ShmemSegHdr->freeoffset;
241 
242  newFree = newStart + size;
243  if (newFree > ShmemSegHdr->totalsize)
244  ereport(ERROR,
245  (errcode(ERRCODE_OUT_OF_MEMORY),
246  errmsg("out of shared memory (%zu bytes requested)",
247  size)));
248  ShmemSegHdr->freeoffset = newFree;
249 
250  newSpace = (void *) ((char *) ShmemBase + newStart);
251 
252  Assert(newSpace == (void *) MAXALIGN(newSpace));
253 
254  return newSpace;
255 }
static PGShmemHeader * ShmemSegHdr
Definition: shmem.c:78
int errcode(int sqlerrcode)
Definition: elog.c:575
static void * ShmemBase
Definition: shmem.c:80
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:122
Size totalsize
Definition: pg_shmem.h:34
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
Size freeoffset
Definition: pg_shmem.h:35
size_t Size
Definition: c.h:356
#define MAXALIGN(LEN)
Definition: c.h:588
int errmsg(const char *fmt,...)
Definition: elog.c:797
HTAB* ShmemInitHash ( const char *  name,
long  init_size,
long  max_size,
HASHCTL infoP,
int  hash_flags 
)

Definition at line 317 of file shmem.c.

References HASHCTL::alloc, HASHCTL::dsize, HASH_ALLOC, HASH_ATTACH, hash_create(), HASH_DIRSIZE, hash_get_shared_size(), hash_select_dirsize(), HASH_SHARED_MEM, HASHCTL::hctl, HASHCTL::max_dsize, ShmemAllocNoError(), and ShmemInitStruct().

Referenced by InitBufTable(), InitLocks(), InitPredicateLocks(), InitShmemIndex(), and pgss_shmem_startup().

322 {
323  bool found;
324  void *location;
325 
326  /*
327  * Hash tables allocated in shared memory have a fixed directory; it can't
328  * grow or other backends wouldn't be able to find it. So, make sure we
329  * make it big enough to start with.
330  *
331  * The shared memory allocator must be specified too.
332  */
333  infoP->dsize = infoP->max_dsize = hash_select_dirsize(max_size);
334  infoP->alloc = ShmemAllocNoError;
335  hash_flags |= HASH_SHARED_MEM | HASH_ALLOC | HASH_DIRSIZE;
336 
337  /* look it up in the shmem index */
338  location = ShmemInitStruct(name,
339  hash_get_shared_size(infoP, hash_flags),
340  &found);
341 
342  /*
343  * if it already exists, attach to it rather than allocate and initialize
344  * new space
345  */
346  if (found)
347  hash_flags |= HASH_ATTACH;
348 
349  /* Pass location of hashtable header to hash_create */
350  infoP->hctl = (HASHHDR *) location;
351 
352  return hash_create(name, init_size, infoP, hash_flags);
353 }
void * ShmemAllocNoError(Size size)
Definition: shmem.c:176
#define HASH_SHARED_MEM
Definition: hsearch.h:94
long dsize
Definition: hsearch.h:69
#define HASH_ATTACH
Definition: hsearch.h:95
long max_dsize
Definition: hsearch.h:70
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
HashAllocFunc alloc
Definition: hsearch.h:77
HTAB * hash_create(const char *tabname, long nelem, HASHCTL *info, int flags)
Definition: dynahash.c:301
long hash_select_dirsize(long num_entries)
Definition: dynahash.c:758
Size hash_get_shared_size(HASHCTL *info, int flags)
Definition: dynahash.c:782
HASHHDR * hctl
Definition: hsearch.h:79
const char * name
Definition: encode.c:521
#define HASH_DIRSIZE
Definition: hsearch.h:85
#define HASH_ALLOC
Definition: hsearch.h:92
void* ShmemInitStruct ( const char *  name,
Size  size,
bool foundPtr 
)

Definition at line 372 of file shmem.c.

References Assert, CACHELINEALIGN, ereport, errcode(), errmsg(), ERROR, FALSE, HASH_ENTER_NULL, HASH_REMOVE, hash_search(), PGShmemHeader::index, IsUnderPostmaster, ShmemIndexEnt::location, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), NULL, result, ShmemAddrIsValid(), ShmemAlloc(), ShmemAllocNoError(), ShmemSegHdr, ShmemIndexEnt::size, and TRUE.

Referenced by ApplyLauncherShmemInit(), AsyncShmemInit(), AutoVacuumShmemInit(), BackendRandomShmemInit(), BackgroundWorkerShmemInit(), BTreeShmemInit(), CheckpointerShmemInit(), CommitTsShmemInit(), CreateSharedBackendStatus(), CreateSharedInvalidationState(), CreateSharedProcArray(), InitBufferPool(), InitLocks(), InitPredicateLocks(), InitProcGlobal(), MultiXactShmemInit(), OldSerXidInit(), pgss_shmem_startup(), PMSignalShmemInit(), ProcSignalShmemInit(), ReplicationOriginShmemInit(), ReplicationSlotsShmemInit(), ShmemInitHash(), SimpleLruInit(), SnapMgrInit(), StrategyInitialize(), SyncScanShmemInit(), TwoPhaseShmemInit(), WalRcvShmemInit(), WalSndShmemInit(), and XLOGShmemInit().

373 {
375  void *structPtr;
376 
377  LWLockAcquire(ShmemIndexLock, LW_EXCLUSIVE);
378 
379  if (!ShmemIndex)
380  {
381  PGShmemHeader *shmemseghdr = ShmemSegHdr;
382 
383  /* Must be trying to create/attach to ShmemIndex itself */
384  Assert(strcmp(name, "ShmemIndex") == 0);
385 
386  if (IsUnderPostmaster)
387  {
388  /* Must be initializing a (non-standalone) backend */
389  Assert(shmemseghdr->index != NULL);
390  structPtr = shmemseghdr->index;
391  *foundPtr = TRUE;
392  }
393  else
394  {
395  /*
396  * If the shmem index doesn't exist, we are bootstrapping: we must
397  * be trying to init the shmem index itself.
398  *
399  * Notice that the ShmemIndexLock is released before the shmem
400  * index has been initialized. This should be OK because no other
401  * process can be accessing shared memory yet.
402  */
403  Assert(shmemseghdr->index == NULL);
404  structPtr = ShmemAlloc(size);
405  shmemseghdr->index = structPtr;
406  *foundPtr = FALSE;
407  }
408  LWLockRelease(ShmemIndexLock);
409  return structPtr;
410  }
411 
412  /* look it up in the shmem index */
413  result = (ShmemIndexEnt *)
415 
416  if (!result)
417  {
418  LWLockRelease(ShmemIndexLock);
419  ereport(ERROR,
420  (errcode(ERRCODE_OUT_OF_MEMORY),
421  errmsg("could not create ShmemIndex entry for data structure \"%s\"",
422  name)));
423  }
424 
425  if (*foundPtr)
426  {
427  /*
428  * Structure is in the shmem index so someone else has allocated it
429  * already. The size better be the same as the size we are trying to
430  * initialize to, or there is a name conflict (or worse).
431  */
432  if (result->size != size)
433  {
434  LWLockRelease(ShmemIndexLock);
435  ereport(ERROR,
436  (errmsg("ShmemIndex entry size is wrong for data structure"
437  " \"%s\": expected %zu, actual %zu",
438  name, size, result->size)));
439  }
440  structPtr = result->location;
441  }
442  else
443  {
444  /* It isn't in the table yet. allocate and initialize it */
445  structPtr = ShmemAllocNoError(size);
446  if (structPtr == NULL)
447  {
448  /* out of memory; remove the failed ShmemIndex entry */
450  LWLockRelease(ShmemIndexLock);
451  ereport(ERROR,
452  (errcode(ERRCODE_OUT_OF_MEMORY),
453  errmsg("not enough shared memory for data structure"
454  " \"%s\" (%zu bytes requested)",
455  name, size)));
456  }
457  result->size = size;
458  result->location = structPtr;
459  }
460 
461  LWLockRelease(ShmemIndexLock);
462 
463  Assert(ShmemAddrIsValid(structPtr));
464 
465  Assert(structPtr == (void *) CACHELINEALIGN(structPtr));
466 
467  return structPtr;
468 }
static PGShmemHeader * ShmemSegHdr
Definition: shmem.c:78
Size size
Definition: shmem.h:62
int errcode(int sqlerrcode)
Definition: elog.c:575
return result
Definition: formatting.c:1618
void * ShmemAllocNoError(Size size)
Definition: shmem.c:176
void * ShmemAlloc(Size size)
Definition: shmem.c:157
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1715
static HTAB * ShmemIndex
Definition: shmem.c:87
#define ERROR
Definition: elog.h:43
void * location
Definition: shmem.h:61
#define FALSE
Definition: c.h:221
bool IsUnderPostmaster
Definition: globals.c:100
#define ereport(elevel, rest)
Definition: elog.h:122
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:263
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define CACHELINEALIGN(LEN)
Definition: c.h:591
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1111
const char * name
Definition: encode.c:521
int errmsg(const char *fmt,...)
Definition: elog.c:797
void * index
Definition: pg_shmem.h:37
#define TRUE
Definition: c.h:217
void SHMQueueDelete ( SHM_QUEUE queue)

Definition at line 68 of file shmqueue.c.

References Assert, SHM_QUEUE::next, NULL, SHM_QUEUE::prev, and ShmemAddrIsValid().

Referenced by CheckTargetForConflictsIn(), CleanUpLock(), ClearOldPredicateLocks(), CreatePredXact(), DeleteChildTargetLocks(), DeleteLockTarget(), DropAllPredicateLocksFromTable(), LockAcquireExtended(), PostPrepare_Locks(), ProcWakeup(), ReleaseOneSerializableXact(), ReleasePredXact(), ReleaseRWConflict(), RemoveFromWaitQueue(), SetPossibleUnsafeConflict(), SetRWConflict(), SummarizeOldestCommittedSxact(), SyncRepCancelWait(), SyncRepCleanupAtProcExit(), SyncRepWakeQueue(), and TransferPredicateLocksToNewTarget().

69 {
70  SHM_QUEUE *nextElem = queue->next;
71  SHM_QUEUE *prevElem = queue->prev;
72 
73  Assert(ShmemAddrIsValid(queue));
74  Assert(ShmemAddrIsValid(nextElem));
75  Assert(ShmemAddrIsValid(prevElem));
76 
77  prevElem->next = queue->next;
78  nextElem->prev = queue->prev;
79 
80  queue->prev = queue->next = NULL;
81 }
struct SHM_QUEUE * next
Definition: shmem.h:31
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:263
struct SHM_QUEUE * prev
Definition: shmem.h:30
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
void SHMQueueElemInit ( SHM_QUEUE queue)

Definition at line 57 of file shmqueue.c.

References Assert, SHM_QUEUE::next, NULL, SHM_QUEUE::prev, and ShmemAddrIsValid().

Referenced by GetSerializableTransactionSnapshotInt(), InitAuxiliaryProcess(), InitProcess(), MarkAsPreparing(), and predicatelock_twophase_recover().

58 {
59  Assert(ShmemAddrIsValid(queue));
60  queue->prev = queue->next = NULL;
61 }
struct SHM_QUEUE * next
Definition: shmem.h:31
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:263
struct SHM_QUEUE * prev
Definition: shmem.h:30
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
bool SHMQueueEmpty ( const SHM_QUEUE queue)

Definition at line 180 of file shmqueue.c.

References Assert, FALSE, SHM_QUEUE::next, SHM_QUEUE::prev, ShmemAddrIsValid(), and TRUE.

Referenced by CheckForSerializableConflictOut(), CleanUpLock(), GetSafeSnapshot(), InitAuxiliaryProcess(), InitProcess(), lock_twophase_recover(), ProcKill(), ReleasePredicateLocks(), RemoveTargetIfNoLongerUsed(), RWConflictExists(), SetupLockInTable(), SummarizeOldestCommittedSxact(), and TransferPredicateLocksToNewTarget().

181 {
182  Assert(ShmemAddrIsValid(queue));
183 
184  if (queue->prev == queue)
185  {
186  Assert(queue->next == queue);
187  return TRUE;
188  }
189  return FALSE;
190 }
struct SHM_QUEUE * next
Definition: shmem.h:31
#define FALSE
Definition: c.h:221
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:263
struct SHM_QUEUE * prev
Definition: shmem.h:30
#define Assert(condition)
Definition: c.h:675
#define TRUE
Definition: c.h:217
void SHMQueueInit ( SHM_QUEUE queue)
void SHMQueueInsertAfter ( SHM_QUEUE queue,
SHM_QUEUE elem 
)

Definition at line 108 of file shmqueue.c.

References Assert, SHM_QUEUE::next, SHM_QUEUE::prev, and ShmemAddrIsValid().

Referenced by SyncRepQueueInsert().

109 {
110  SHM_QUEUE *nextPtr = queue->next;
111 
112  Assert(ShmemAddrIsValid(queue));
113  Assert(ShmemAddrIsValid(elem));
114 
115  elem->prev = nextPtr->prev;
116  elem->next = queue->next;
117  queue->next = elem;
118  nextPtr->prev = elem;
119 }
struct SHM_QUEUE * next
Definition: shmem.h:31
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:263
struct SHM_QUEUE * prev
Definition: shmem.h:30
#define Assert(condition)
Definition: c.h:675
void SHMQueueInsertBefore ( SHM_QUEUE queue,
SHM_QUEUE elem 
)

Definition at line 89 of file shmqueue.c.

References Assert, SHM_QUEUE::next, SHM_QUEUE::prev, and ShmemAddrIsValid().

Referenced by CreatePredicateLock(), CreatePredXact(), DeadLockCheck(), DropAllPredicateLocksFromTable(), InitPredicateLocks(), lock_twophase_recover(), PostPrepare_Locks(), ProcSleep(), ReleaseOneSerializableXact(), ReleasePredicateLocks(), ReleasePredXact(), ReleaseRWConflict(), SetPossibleUnsafeConflict(), SetRWConflict(), SetupLockInTable(), and TransferPredicateLocksToNewTarget().

90 {
91  SHM_QUEUE *prevPtr = queue->prev;
92 
93  Assert(ShmemAddrIsValid(queue));
94  Assert(ShmemAddrIsValid(elem));
95 
96  elem->next = prevPtr->next;
97  elem->prev = queue->prev;
98  queue->prev = elem;
99  prevPtr->next = elem;
100 }
struct SHM_QUEUE * next
Definition: shmem.h:31
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:263
struct SHM_QUEUE * prev
Definition: shmem.h:30
#define Assert(condition)
Definition: c.h:675
bool SHMQueueIsDetached ( const SHM_QUEUE queue)

Definition at line 47 of file shmqueue.c.

References Assert, NULL, SHM_QUEUE::prev, and ShmemAddrIsValid().

Referenced by SyncRepCancelWait(), SyncRepCleanupAtProcExit(), and SyncRepWaitForLSN().

48 {
49  Assert(ShmemAddrIsValid(queue));
50  return (queue->prev == NULL);
51 }
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:263
struct SHM_QUEUE * prev
Definition: shmem.h:30
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
Pointer SHMQueueNext ( const SHM_QUEUE queue,
const SHM_QUEUE curElem,
Size  linkOffset 
)
Pointer SHMQueuePrev ( const SHM_QUEUE queue,
const SHM_QUEUE curElem,
Size  linkOffset 
)

Definition at line 164 of file shmqueue.c.

References Assert, NULL, SHM_QUEUE::prev, and ShmemAddrIsValid().

Referenced by SyncRepQueueInsert().

165 {
166  SHM_QUEUE *elemPtr = curElem->prev;
167 
168  Assert(ShmemAddrIsValid(curElem));
169 
170  if (elemPtr == queue) /* back to the queue head? */
171  return NULL;
172 
173  return (Pointer) (((char *) elemPtr) - linkOffset);
174 }
char * Pointer
Definition: c.h:245
bool ShmemAddrIsValid(const void *addr)
Definition: shmem.c:263
struct SHM_QUEUE * prev
Definition: shmem.h:30
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675