PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
lockfuncs.c File Reference
#include "postgres.h"
#include "access/htup_details.h"
#include "access/xact.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "storage/predicate_internals.h"
#include "utils/array.h"
#include "utils/builtins.h"
Include dependency graph for lockfuncs.c:

Go to the source code of this file.

Data Structures

struct  PG_Lock_Status
 

Macros

#define NUM_LOCK_STATUS_COLUMNS   15
 
#define SET_LOCKTAG_INT64(tag, key64)
 
#define SET_LOCKTAG_INT32(tag, key1, key2)   SET_LOCKTAG_ADVISORY(tag, MyDatabaseId, key1, key2, 2)
 

Functions

static Datum VXIDGetDatum (BackendId bid, LocalTransactionId lxid)
 
Datum pg_lock_status (PG_FUNCTION_ARGS)
 
Datum pg_blocking_pids (PG_FUNCTION_ARGS)
 
static void PreventAdvisoryLocksInParallelMode (void)
 
Datum pg_advisory_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_shared_int8 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_xact_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_try_advisory_xact_lock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_shared_int4 (PG_FUNCTION_ARGS)
 
Datum pg_advisory_unlock_all (PG_FUNCTION_ARGS)
 

Variables

const char *const LockTagTypeNames []
 
static const char *const PredicateLockTagTypeNames []
 

Macro Definition Documentation

#define NUM_LOCK_STATUS_COLUMNS   15

Definition at line 56 of file lockfuncs.c.

Referenced by pg_lock_status().

#define SET_LOCKTAG_INT64 (   tag,
  key64 
)

Function Documentation

Datum pg_advisory_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 744 of file lockfuncs.c.

References ExclusiveLock, LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT32.

745 {
746  int32 key1 = PG_GETARG_INT32(0);
747  int32 key2 = PG_GETARG_INT32(1);
748  LOCKTAG tag;
749 
751  SET_LOCKTAG_INT32(tag, key1, key2);
752 
753  (void) LockAcquire(&tag, ExclusiveLock, true, false);
754 
755  PG_RETURN_VOID();
756 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_VOID()
Definition: fmgr.h:301
Datum pg_advisory_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 552 of file lockfuncs.c.

References ExclusiveLock, LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT64.

553 {
554  int64 key = PG_GETARG_INT64(0);
555  LOCKTAG tag;
556 
558  SET_LOCKTAG_INT64(tag, key);
559 
560  (void) LockAcquire(&tag, ExclusiveLock, true, false);
561 
562  PG_RETURN_VOID();
563 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_VOID()
Definition: fmgr.h:301
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
Datum pg_advisory_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 781 of file lockfuncs.c.

References LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT32, and ShareLock.

782 {
783  int32 key1 = PG_GETARG_INT32(0);
784  int32 key2 = PG_GETARG_INT32(1);
785  LOCKTAG tag;
786 
788  SET_LOCKTAG_INT32(tag, key1, key2);
789 
790  (void) LockAcquire(&tag, ShareLock, true, false);
791 
792  PG_RETURN_VOID();
793 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_VOID()
Definition: fmgr.h:301
#define ShareLock
Definition: lockdefs.h:41
Datum pg_advisory_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 587 of file lockfuncs.c.

References LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT64, and ShareLock.

588 {
589  int64 key = PG_GETARG_INT64(0);
590  LOCKTAG tag;
591 
593  SET_LOCKTAG_INT64(tag, key);
594 
595  (void) LockAcquire(&tag, ShareLock, true, false);
596 
597  PG_RETURN_VOID();
598 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_VOID()
Definition: fmgr.h:301
#define ShareLock
Definition: lockdefs.h:41
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
Datum pg_advisory_unlock_all ( PG_FUNCTION_ARGS  )

Definition at line 946 of file lockfuncs.c.

References LockReleaseSession(), PG_RETURN_VOID, and USER_LOCKMETHOD.

947 {
949 
950  PG_RETURN_VOID();
951 }
#define USER_LOCKMETHOD
Definition: lock.h:130
#define PG_RETURN_VOID()
Definition: fmgr.h:301
void LockReleaseSession(LOCKMETHODID lockmethodid)
Definition: lock.c:2288
Datum pg_advisory_unlock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 906 of file lockfuncs.c.

References ExclusiveLock, LockRelease(), PG_GETARG_INT32, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT32.

907 {
908  int32 key1 = PG_GETARG_INT32(0);
909  int32 key2 = PG_GETARG_INT32(1);
910  LOCKTAG tag;
911  bool res;
912 
914  SET_LOCKTAG_INT32(tag, key1, key2);
915 
916  res = LockRelease(&tag, ExclusiveLock, true);
917 
918  PG_RETURN_BOOL(res);
919 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
Datum pg_advisory_unlock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 706 of file lockfuncs.c.

References ExclusiveLock, LockRelease(), PG_GETARG_INT64, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT64.

707 {
708  int64 key = PG_GETARG_INT64(0);
709  LOCKTAG tag;
710  bool res;
711 
713  SET_LOCKTAG_INT64(tag, key);
714 
715  res = LockRelease(&tag, ExclusiveLock, true);
716 
717  PG_RETURN_BOOL(res);
718 }
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
Datum pg_advisory_unlock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 927 of file lockfuncs.c.

References LockRelease(), PG_GETARG_INT32, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT32, and ShareLock.

928 {
929  int32 key1 = PG_GETARG_INT32(0);
930  int32 key2 = PG_GETARG_INT32(1);
931  LOCKTAG tag;
932  bool res;
933 
935  SET_LOCKTAG_INT32(tag, key1, key2);
936 
937  res = LockRelease(&tag, ShareLock, true);
938 
939  PG_RETURN_BOOL(res);
940 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
#define ShareLock
Definition: lockdefs.h:41
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
Datum pg_advisory_unlock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 726 of file lockfuncs.c.

References LockRelease(), PG_GETARG_INT64, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT64, and ShareLock.

727 {
728  int64 key = PG_GETARG_INT64(0);
729  LOCKTAG tag;
730  bool res;
731 
733  SET_LOCKTAG_INT64(tag, key);
734 
735  res = LockRelease(&tag, ShareLock, true);
736 
737  PG_RETURN_BOOL(res);
738 }
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
#define ShareLock
Definition: lockdefs.h:41
bool LockRelease(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock)
Definition: lock.c:1818
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
Datum pg_advisory_xact_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 763 of file lockfuncs.c.

References ExclusiveLock, LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT32.

764 {
765  int32 key1 = PG_GETARG_INT32(0);
766  int32 key2 = PG_GETARG_INT32(1);
767  LOCKTAG tag;
768 
770  SET_LOCKTAG_INT32(tag, key1, key2);
771 
772  (void) LockAcquire(&tag, ExclusiveLock, false, false);
773 
774  PG_RETURN_VOID();
775 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_VOID()
Definition: fmgr.h:301
Datum pg_advisory_xact_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 570 of file lockfuncs.c.

References ExclusiveLock, LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT64.

571 {
572  int64 key = PG_GETARG_INT64(0);
573  LOCKTAG tag;
574 
576  SET_LOCKTAG_INT64(tag, key);
577 
578  (void) LockAcquire(&tag, ExclusiveLock, false, false);
579 
580  PG_RETURN_VOID();
581 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_VOID()
Definition: fmgr.h:301
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
Datum pg_advisory_xact_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 800 of file lockfuncs.c.

References LockAcquire(), PG_GETARG_INT32, PG_RETURN_VOID, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT32, and ShareLock.

801 {
802  int32 key1 = PG_GETARG_INT32(0);
803  int32 key2 = PG_GETARG_INT32(1);
804  LOCKTAG tag;
805 
807  SET_LOCKTAG_INT32(tag, key1, key2);
808 
809  (void) LockAcquire(&tag, ShareLock, false, false);
810 
811  PG_RETURN_VOID();
812 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_VOID()
Definition: fmgr.h:301
#define ShareLock
Definition: lockdefs.h:41
Datum pg_advisory_xact_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 605 of file lockfuncs.c.

References LockAcquire(), PG_GETARG_INT64, PG_RETURN_VOID, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT64, and ShareLock.

606 {
607  int64 key = PG_GETARG_INT64(0);
608  LOCKTAG tag;
609 
611  SET_LOCKTAG_INT64(tag, key);
612 
613  (void) LockAcquire(&tag, ShareLock, false, false);
614 
615  PG_RETURN_VOID();
616 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_VOID()
Definition: fmgr.h:301
#define ShareLock
Definition: lockdefs.h:41
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
Datum pg_blocking_pids ( PG_FUNCTION_ARGS  )

Definition at line 418 of file lockfuncs.c.

References Assert, LockMethodData::conflictTab, construct_array(), BlockedProcData::first_lock, BlockedProcData::first_waiter, GetBlockerStatusData(), GetLockTagsMethodTable(), LockInstanceData::holdMask, i, Int32GetDatum, INT4OID, LockInstanceData::leaderPid, LOCKBIT_ON, BlockedProcsData::locks, LockInstanceData::locktag, BlockedProcsData::nlocks, NoLock, BlockedProcsData::nprocs, NULL, BlockedProcData::num_locks, BlockedProcData::num_waiters, palloc(), PG_GETARG_INT32, PG_RETURN_ARRAYTYPE_P, LockInstanceData::pid, BlockedProcData::pid, BlockedProcsData::procs, BlockedProcsData::waiter_pids, and LockInstanceData::waitLockMode.

419 {
420  int blocked_pid = PG_GETARG_INT32(0);
421  Datum *arrayelems;
422  int narrayelems;
423  BlockedProcsData *lockData; /* state data from lmgr */
424  int i,
425  j;
426 
427  /* Collect a snapshot of lock manager state */
428  lockData = GetBlockerStatusData(blocked_pid);
429 
430  /* We can't need more output entries than there are reported PROCLOCKs */
431  arrayelems = (Datum *) palloc(lockData->nlocks * sizeof(Datum));
432  narrayelems = 0;
433 
434  /* For each blocked proc in the lock group ... */
435  for (i = 0; i < lockData->nprocs; i++)
436  {
437  BlockedProcData *bproc = &lockData->procs[i];
438  LockInstanceData *instances = &lockData->locks[bproc->first_lock];
439  int *preceding_waiters = &lockData->waiter_pids[bproc->first_waiter];
440  LockInstanceData *blocked_instance;
441  LockMethod lockMethodTable;
442  int conflictMask;
443 
444  /*
445  * Locate the blocked proc's own entry in the LockInstanceData array.
446  * There should be exactly one matching entry.
447  */
448  blocked_instance = NULL;
449  for (j = 0; j < bproc->num_locks; j++)
450  {
451  LockInstanceData *instance = &(instances[j]);
452 
453  if (instance->pid == bproc->pid)
454  {
455  Assert(blocked_instance == NULL);
456  blocked_instance = instance;
457  }
458  }
459  Assert(blocked_instance != NULL);
460 
461  lockMethodTable = GetLockTagsMethodTable(&(blocked_instance->locktag));
462  conflictMask = lockMethodTable->conflictTab[blocked_instance->waitLockMode];
463 
464  /* Now scan the PROCLOCK data for conflicting procs */
465  for (j = 0; j < bproc->num_locks; j++)
466  {
467  LockInstanceData *instance = &(instances[j]);
468 
469  /* A proc never blocks itself, so ignore that entry */
470  if (instance == blocked_instance)
471  continue;
472  /* Members of same lock group never block each other, either */
473  if (instance->leaderPid == blocked_instance->leaderPid)
474  continue;
475 
476  if (conflictMask & instance->holdMask)
477  {
478  /* hard block: blocked by lock already held by this entry */
479  }
480  else if (instance->waitLockMode != NoLock &&
481  (conflictMask & LOCKBIT_ON(instance->waitLockMode)))
482  {
483  /* conflict in lock requests; who's in front in wait queue? */
484  bool ahead = false;
485  int k;
486 
487  for (k = 0; k < bproc->num_waiters; k++)
488  {
489  if (preceding_waiters[k] == instance->pid)
490  {
491  /* soft block: this entry is ahead of blocked proc */
492  ahead = true;
493  break;
494  }
495  }
496  if (!ahead)
497  continue; /* not blocked by this entry */
498  }
499  else
500  {
501  /* not blocked by this entry */
502  continue;
503  }
504 
505  /* blocked by this entry, so emit a record */
506  arrayelems[narrayelems++] = Int32GetDatum(instance->leaderPid);
507  }
508  }
509 
510  /* Assert we didn't overrun arrayelems[] */
511  Assert(narrayelems <= lockData->nlocks);
512 
513  /* Construct array, using hardwired knowledge about int4 type */
514  PG_RETURN_ARRAYTYPE_P(construct_array(arrayelems, narrayelems,
515  INT4OID,
516  sizeof(int32), true, 'i'));
517 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
int * waiter_pids
Definition: lock.h:461
BlockedProcsData * GetBlockerStatusData(int blocked_pid)
Definition: lock.c:3582
int first_lock
Definition: lock.h:449
int num_waiters
Definition: lock.h:454
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Definition: arrayfuncs.c:3306
#define INT4OID
Definition: pg_type.h:316
const LOCKMASK * conflictTab
Definition: lock.h:115
BlockedProcData * procs
Definition: lock.h:459
LOCKTAG locktag
Definition: lock.h:428
LOCKMODE waitLockMode
Definition: lock.h:430
int num_locks
Definition: lock.h:450
signed int int32
Definition: c.h:256
int leaderPid
Definition: lock.h:434
#define NoLock
Definition: lockdefs.h:34
#define PG_RETURN_ARRAYTYPE_P(x)
Definition: array.h:246
LockInstanceData * locks
Definition: lock.h:460
uintptr_t Datum
Definition: postgres.h:372
LockMethod GetLockTagsMethodTable(const LOCKTAG *locktag)
Definition: lock.c:472
int first_waiter
Definition: lock.h:453
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
LOCKMASK holdMask
Definition: lock.h:429
#define LOCKBIT_ON(lockmode)
Definition: lock.h:88
#define Int32GetDatum(X)
Definition: postgres.h:485
void * palloc(Size size)
Definition: mcxt.c:849
int i
Datum pg_lock_status ( PG_FUNCTION_ARGS  )

Definition at line 82 of file lockfuncs.c.

References LockInstanceData::backend, VirtualTransactionId::backendId, BlessTupleDesc(), BoolGetDatum, BOOLOID, CreateTemplateTupleDesc(), CStringGetTextDatum, PG_Lock_Status::currIdx, LockInstanceData::fastpath, GET_PREDICATELOCKTARGETTAG_DB, GET_PREDICATELOCKTARGETTAG_OFFSET, GET_PREDICATELOCKTARGETTAG_PAGE, GET_PREDICATELOCKTARGETTAG_RELATION, GET_PREDICATELOCKTARGETTAG_TYPE, GetLockmodeName(), GetLockStatusData(), GetPredicateLockStatusData(), heap_form_tuple(), HeapTupleGetDatum, LockInstanceData::holdMask, Int16GetDatum, INT2OID, Int32GetDatum, INT4OID, VirtualTransactionId::localTransactionId, LOCKBIT_OFF, LOCKBIT_ON, PG_Lock_Status::lockData, LockData::locks, LockInstanceData::locktag, LOCKTAG_ADVISORY, LOCKTAG::locktag_field1, LOCKTAG::locktag_field2, LOCKTAG::locktag_field3, LOCKTAG::locktag_field4, LOCKTAG_LAST_TYPE, LOCKTAG::locktag_lockmethodid, LOCKTAG_OBJECT, LOCKTAG_PAGE, LOCKTAG_RELATION, LOCKTAG_RELATION_EXTEND, LOCKTAG_TRANSACTION, LOCKTAG_TUPLE, LOCKTAG::locktag_type, LOCKTAG_USERLOCK, LOCKTAG_VIRTUALTRANSACTION, PredicateLockData::locktags, LockTagTypeNames, LockInstanceData::lxid, MAX_LOCKMODES, MemoryContextSwitchTo(), MemSet, FuncCallContext::multi_call_memory_ctx, PredicateLockData::nelements, LockData::nelements, NoLock, NUM_LOCK_STATUS_COLUMNS, ObjectIdGetDatum, OIDOID, palloc(), SERIALIZABLEXACT::pid, LockInstanceData::pid, PredicateLockTagTypeNames, PG_Lock_Status::predLockData, PG_Lock_Status::predLockIdx, PREDLOCKTAG_PAGE, PREDLOCKTAG_TUPLE, snprintf(), SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, TEXTOID, TransactionIdGetDatum, FuncCallContext::tuple_desc, TupleDescInitEntry(), UInt16GetDatum, UInt32GetDatum, FuncCallContext::user_fctx, values, SERIALIZABLEXACT::vxid, VXIDGetDatum(), LockInstanceData::waitLockMode, PredicateLockData::xacts, and XIDOID.

83 {
84  FuncCallContext *funcctx;
85  PG_Lock_Status *mystatus;
86  LockData *lockData;
87  PredicateLockData *predLockData;
88 
89  if (SRF_IS_FIRSTCALL())
90  {
91  TupleDesc tupdesc;
92  MemoryContext oldcontext;
93 
94  /* create a function context for cross-call persistence */
95  funcctx = SRF_FIRSTCALL_INIT();
96 
97  /*
98  * switch to memory context appropriate for multiple function calls
99  */
100  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
101 
102  /* build tupdesc for result tuples */
103  /* this had better match function's declaration in pg_proc.h */
105  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "locktype",
106  TEXTOID, -1, 0);
107  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "database",
108  OIDOID, -1, 0);
109  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "relation",
110  OIDOID, -1, 0);
111  TupleDescInitEntry(tupdesc, (AttrNumber) 4, "page",
112  INT4OID, -1, 0);
113  TupleDescInitEntry(tupdesc, (AttrNumber) 5, "tuple",
114  INT2OID, -1, 0);
115  TupleDescInitEntry(tupdesc, (AttrNumber) 6, "virtualxid",
116  TEXTOID, -1, 0);
117  TupleDescInitEntry(tupdesc, (AttrNumber) 7, "transactionid",
118  XIDOID, -1, 0);
119  TupleDescInitEntry(tupdesc, (AttrNumber) 8, "classid",
120  OIDOID, -1, 0);
121  TupleDescInitEntry(tupdesc, (AttrNumber) 9, "objid",
122  OIDOID, -1, 0);
123  TupleDescInitEntry(tupdesc, (AttrNumber) 10, "objsubid",
124  INT2OID, -1, 0);
125  TupleDescInitEntry(tupdesc, (AttrNumber) 11, "virtualtransaction",
126  TEXTOID, -1, 0);
127  TupleDescInitEntry(tupdesc, (AttrNumber) 12, "pid",
128  INT4OID, -1, 0);
129  TupleDescInitEntry(tupdesc, (AttrNumber) 13, "mode",
130  TEXTOID, -1, 0);
131  TupleDescInitEntry(tupdesc, (AttrNumber) 14, "granted",
132  BOOLOID, -1, 0);
133  TupleDescInitEntry(tupdesc, (AttrNumber) 15, "fastpath",
134  BOOLOID, -1, 0);
135 
136  funcctx->tuple_desc = BlessTupleDesc(tupdesc);
137 
138  /*
139  * Collect all the locking information that we will format and send
140  * out as a result set.
141  */
142  mystatus = (PG_Lock_Status *) palloc(sizeof(PG_Lock_Status));
143  funcctx->user_fctx = (void *) mystatus;
144 
145  mystatus->lockData = GetLockStatusData();
146  mystatus->currIdx = 0;
148  mystatus->predLockIdx = 0;
149 
150  MemoryContextSwitchTo(oldcontext);
151  }
152 
153  funcctx = SRF_PERCALL_SETUP();
154  mystatus = (PG_Lock_Status *) funcctx->user_fctx;
155  lockData = mystatus->lockData;
156 
157  while (mystatus->currIdx < lockData->nelements)
158  {
159  bool granted;
160  LOCKMODE mode = 0;
161  const char *locktypename;
162  char tnbuf[32];
164  bool nulls[NUM_LOCK_STATUS_COLUMNS];
165  HeapTuple tuple;
166  Datum result;
167  LockInstanceData *instance;
168 
169  instance = &(lockData->locks[mystatus->currIdx]);
170 
171  /*
172  * Look to see if there are any held lock modes in this PROCLOCK. If
173  * so, report, and destructively modify lockData so we don't report
174  * again.
175  */
176  granted = false;
177  if (instance->holdMask)
178  {
179  for (mode = 0; mode < MAX_LOCKMODES; mode++)
180  {
181  if (instance->holdMask & LOCKBIT_ON(mode))
182  {
183  granted = true;
184  instance->holdMask &= LOCKBIT_OFF(mode);
185  break;
186  }
187  }
188  }
189 
190  /*
191  * If no (more) held modes to report, see if PROC is waiting for a
192  * lock on this lock.
193  */
194  if (!granted)
195  {
196  if (instance->waitLockMode != NoLock)
197  {
198  /* Yes, so report it with proper mode */
199  mode = instance->waitLockMode;
200 
201  /*
202  * We are now done with this PROCLOCK, so advance pointer to
203  * continue with next one on next call.
204  */
205  mystatus->currIdx++;
206  }
207  else
208  {
209  /*
210  * Okay, we've displayed all the locks associated with this
211  * PROCLOCK, proceed to the next one.
212  */
213  mystatus->currIdx++;
214  continue;
215  }
216  }
217 
218  /*
219  * Form tuple with appropriate data.
220  */
221  MemSet(values, 0, sizeof(values));
222  MemSet(nulls, false, sizeof(nulls));
223 
224  if (instance->locktag.locktag_type <= LOCKTAG_LAST_TYPE)
225  locktypename = LockTagTypeNames[instance->locktag.locktag_type];
226  else
227  {
228  snprintf(tnbuf, sizeof(tnbuf), "unknown %d",
229  (int) instance->locktag.locktag_type);
230  locktypename = tnbuf;
231  }
232  values[0] = CStringGetTextDatum(locktypename);
233 
234  switch ((LockTagType) instance->locktag.locktag_type)
235  {
236  case LOCKTAG_RELATION:
238  values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
239  values[2] = ObjectIdGetDatum(instance->locktag.locktag_field2);
240  nulls[3] = true;
241  nulls[4] = true;
242  nulls[5] = true;
243  nulls[6] = true;
244  nulls[7] = true;
245  nulls[8] = true;
246  nulls[9] = true;
247  break;
248  case LOCKTAG_PAGE:
249  values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
250  values[2] = ObjectIdGetDatum(instance->locktag.locktag_field2);
251  values[3] = UInt32GetDatum(instance->locktag.locktag_field3);
252  nulls[4] = true;
253  nulls[5] = true;
254  nulls[6] = true;
255  nulls[7] = true;
256  nulls[8] = true;
257  nulls[9] = true;
258  break;
259  case LOCKTAG_TUPLE:
260  values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
261  values[2] = ObjectIdGetDatum(instance->locktag.locktag_field2);
262  values[3] = UInt32GetDatum(instance->locktag.locktag_field3);
263  values[4] = UInt16GetDatum(instance->locktag.locktag_field4);
264  nulls[5] = true;
265  nulls[6] = true;
266  nulls[7] = true;
267  nulls[8] = true;
268  nulls[9] = true;
269  break;
270  case LOCKTAG_TRANSACTION:
271  values[6] =
273  nulls[1] = true;
274  nulls[2] = true;
275  nulls[3] = true;
276  nulls[4] = true;
277  nulls[5] = true;
278  nulls[7] = true;
279  nulls[8] = true;
280  nulls[9] = true;
281  break;
283  values[5] = VXIDGetDatum(instance->locktag.locktag_field1,
284  instance->locktag.locktag_field2);
285  nulls[1] = true;
286  nulls[2] = true;
287  nulls[3] = true;
288  nulls[4] = true;
289  nulls[6] = true;
290  nulls[7] = true;
291  nulls[8] = true;
292  nulls[9] = true;
293  break;
294  case LOCKTAG_OBJECT:
295  case LOCKTAG_USERLOCK:
296  case LOCKTAG_ADVISORY:
297  default: /* treat unknown locktags like OBJECT */
298  values[1] = ObjectIdGetDatum(instance->locktag.locktag_field1);
299  values[7] = ObjectIdGetDatum(instance->locktag.locktag_field2);
300  values[8] = ObjectIdGetDatum(instance->locktag.locktag_field3);
301  values[9] = Int16GetDatum(instance->locktag.locktag_field4);
302  nulls[2] = true;
303  nulls[3] = true;
304  nulls[4] = true;
305  nulls[5] = true;
306  nulls[6] = true;
307  break;
308  }
309 
310  values[10] = VXIDGetDatum(instance->backend, instance->lxid);
311  if (instance->pid != 0)
312  values[11] = Int32GetDatum(instance->pid);
313  else
314  nulls[11] = true;
315  values[12] = CStringGetTextDatum(GetLockmodeName(instance->locktag.locktag_lockmethodid, mode));
316  values[13] = BoolGetDatum(granted);
317  values[14] = BoolGetDatum(instance->fastpath);
318 
319  tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
320  result = HeapTupleGetDatum(tuple);
321  SRF_RETURN_NEXT(funcctx, result);
322  }
323 
324  /*
325  * Have returned all regular locks. Now start on the SIREAD predicate
326  * locks.
327  */
328  predLockData = mystatus->predLockData;
329  if (mystatus->predLockIdx < predLockData->nelements)
330  {
331  PredicateLockTargetType lockType;
332 
333  PREDICATELOCKTARGETTAG *predTag = &(predLockData->locktags[mystatus->predLockIdx]);
334  SERIALIZABLEXACT *xact = &(predLockData->xacts[mystatus->predLockIdx]);
336  bool nulls[NUM_LOCK_STATUS_COLUMNS];
337  HeapTuple tuple;
338  Datum result;
339 
340  mystatus->predLockIdx++;
341 
342  /*
343  * Form tuple with appropriate data.
344  */
345  MemSet(values, 0, sizeof(values));
346  MemSet(nulls, false, sizeof(nulls));
347 
348  /* lock type */
349  lockType = GET_PREDICATELOCKTARGETTAG_TYPE(*predTag);
350 
351  values[0] = CStringGetTextDatum(PredicateLockTagTypeNames[lockType]);
352 
353  /* lock target */
354  values[1] = GET_PREDICATELOCKTARGETTAG_DB(*predTag);
355  values[2] = GET_PREDICATELOCKTARGETTAG_RELATION(*predTag);
356  if (lockType == PREDLOCKTAG_TUPLE)
357  values[4] = GET_PREDICATELOCKTARGETTAG_OFFSET(*predTag);
358  else
359  nulls[4] = true;
360  if ((lockType == PREDLOCKTAG_TUPLE) ||
361  (lockType == PREDLOCKTAG_PAGE))
362  values[3] = GET_PREDICATELOCKTARGETTAG_PAGE(*predTag);
363  else
364  nulls[3] = true;
365 
366  /* these fields are targets for other types of locks */
367  nulls[5] = true; /* virtualxid */
368  nulls[6] = true; /* transactionid */
369  nulls[7] = true; /* classid */
370  nulls[8] = true; /* objid */
371  nulls[9] = true; /* objsubid */
372 
373  /* lock holder */
374  values[10] = VXIDGetDatum(xact->vxid.backendId,
375  xact->vxid.localTransactionId);
376  if (xact->pid != 0)
377  values[11] = Int32GetDatum(xact->pid);
378  else
379  nulls[11] = true;
380 
381  /*
382  * Lock mode. Currently all predicate locks are SIReadLocks, which are
383  * always held (never waiting) and have no fast path
384  */
385  values[12] = CStringGetTextDatum("SIReadLock");
386  values[13] = BoolGetDatum(true);
387  values[14] = BoolGetDatum(false);
388 
389  tuple = heap_form_tuple(funcctx->tuple_desc, values, nulls);
390  result = HeapTupleGetDatum(tuple);
391  SRF_RETURN_NEXT(funcctx, result);
392  }
393 
394  SRF_RETURN_DONE(funcctx);
395 }
#define GET_PREDICATELOCKTARGETTAG_RELATION(locktag)
#define GET_PREDICATELOCKTARGETTAG_PAGE(locktag)
const char * GetLockmodeName(LOCKMETHODID lockmethodid, LOCKMODE mode)
Definition: lock.c:3845
PredicateLockTargetType
LockInstanceData * locks
Definition: lock.h:441
int LOCKMODE
Definition: lockdefs.h:26
#define OIDOID
Definition: pg_type.h:328
#define TEXTOID
Definition: pg_type.h:324
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:285
bool fastpath
Definition: lock.h:435
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define Int16GetDatum(X)
Definition: postgres.h:457
#define INT4OID
Definition: pg_type.h:316
#define MemSet(start, val, len)
Definition: c.h:857
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
SERIALIZABLEXACT * xacts
#define XIDOID
Definition: pg_type.h:336
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:692
Definition: lock.h:438
LocalTransactionId localTransactionId
Definition: lock.h:66
#define NUM_LOCK_STATUS_COLUMNS
Definition: lockfuncs.c:56
LOCKTAG locktag
Definition: lock.h:428
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:289
LOCKMODE waitLockMode
Definition: lock.h:430
PredicateLockData * GetPredicateLockStatusData(void)
Definition: predicate.c:1376
TupleDesc tuple_desc
Definition: funcapi.h:120
uint16 locktag_field4
Definition: lock.h:184
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:291
#define LOCKBIT_OFF(lockmode)
Definition: lock.h:89
#define GET_PREDICATELOCKTARGETTAG_OFFSET(locktag)
#define ObjectIdGetDatum(X)
Definition: postgres.h:513
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:1031
#define INT2OID
Definition: pg_type.h:308
LockData * GetLockStatusData(void)
Definition: lock.c:3398
VirtualTransactionId vxid
#define NoLock
Definition: lockdefs.h:34
#define GET_PREDICATELOCKTARGETTAG_TYPE(locktag)
uint32 locktag_field2
Definition: lock.h:182
#define GET_PREDICATELOCKTARGETTAG_DB(locktag)
#define UInt32GetDatum(X)
Definition: postgres.h:499
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:493
PREDICATELOCKTARGETTAG * locktags
static const char *const PredicateLockTagTypeNames[]
Definition: lockfuncs.c:40
int nelements
Definition: lock.h:440
#define TransactionIdGetDatum(X)
Definition: postgres.h:527
#define MAX_LOCKMODES
Definition: lock.h:86
uintptr_t Datum
Definition: postgres.h:372
BackendId backend
Definition: lock.h:431
#define BoolGetDatum(X)
Definition: postgres.h:408
#define LOCKTAG_LAST_TYPE
Definition: lock.h:167
uint8 locktag_type
Definition: lock.h:185
LocalTransactionId lxid
Definition: lock.h:432
BackendId backendId
Definition: lock.h:65
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:109
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:222
#define BOOLOID
Definition: pg_type.h:288
TupleDesc CreateTemplateTupleDesc(int natts, bool hasoid)
Definition: tupdesc.c:41
LOCKMASK holdMask
Definition: lock.h:429
uint8 locktag_lockmethodid
Definition: lock.h:186
#define LOCKBIT_ON(lockmode)
Definition: lock.h:88
static Datum values[MAXATTR]
Definition: bootstrap.c:162
PredicateLockData * predLockData
Definition: lockfuncs.c:51
#define Int32GetDatum(X)
Definition: postgres.h:485
void * user_fctx
Definition: funcapi.h:90
void * palloc(Size size)
Definition: mcxt.c:849
LockData * lockData
Definition: lockfuncs.c:49
#define CStringGetTextDatum(s)
Definition: builtins.h:91
const char *const LockTagTypeNames[]
Definition: lockfuncs.c:26
LockTagType
Definition: lock.h:139
uint32 locktag_field1
Definition: lock.h:181
#define UInt16GetDatum(X)
Definition: postgres.h:471
int16 AttrNumber
Definition: attnum.h:21
uint32 locktag_field3
Definition: lock.h:183
static Datum VXIDGetDatum(BackendId bid, LocalTransactionId lxid)
Definition: lockfuncs.c:64
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:309
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:287
Datum pg_try_advisory_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 820 of file lockfuncs.c.

References ExclusiveLock, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT32.

821 {
822  int32 key1 = PG_GETARG_INT32(0);
823  int32 key2 = PG_GETARG_INT32(1);
824  LOCKTAG tag;
825  LockAcquireResult res;
826 
828  SET_LOCKTAG_INT32(tag, key1, key2);
829 
830  res = LockAcquire(&tag, ExclusiveLock, true, true);
831 
833 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
LockAcquireResult
Definition: lock.h:472
Datum pg_try_advisory_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 624 of file lockfuncs.c.

References ExclusiveLock, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT64.

625 {
626  int64 key = PG_GETARG_INT64(0);
627  LOCKTAG tag;
628  LockAcquireResult res;
629 
631  SET_LOCKTAG_INT64(tag, key);
632 
633  res = LockAcquire(&tag, ExclusiveLock, true, true);
634 
636 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
LockAcquireResult
Definition: lock.h:472
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
Datum pg_try_advisory_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 863 of file lockfuncs.c.

References LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT32, and ShareLock.

864 {
865  int32 key1 = PG_GETARG_INT32(0);
866  int32 key2 = PG_GETARG_INT32(1);
867  LOCKTAG tag;
868  LockAcquireResult res;
869 
871  SET_LOCKTAG_INT32(tag, key1, key2);
872 
873  res = LockAcquire(&tag, ShareLock, true, true);
874 
876 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
LockAcquireResult
Definition: lock.h:472
#define ShareLock
Definition: lockdefs.h:41
Datum pg_try_advisory_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 665 of file lockfuncs.c.

References LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT64, and ShareLock.

666 {
667  int64 key = PG_GETARG_INT64(0);
668  LOCKTAG tag;
669  LockAcquireResult res;
670 
672  SET_LOCKTAG_INT64(tag, key);
673 
674  res = LockAcquire(&tag, ShareLock, true, true);
675 
677 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
LockAcquireResult
Definition: lock.h:472
#define ShareLock
Definition: lockdefs.h:41
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
Datum pg_try_advisory_xact_lock_int4 ( PG_FUNCTION_ARGS  )

Definition at line 842 of file lockfuncs.c.

References ExclusiveLock, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT32.

843 {
844  int32 key1 = PG_GETARG_INT32(0);
845  int32 key2 = PG_GETARG_INT32(1);
846  LOCKTAG tag;
847  LockAcquireResult res;
848 
850  SET_LOCKTAG_INT32(tag, key1, key2);
851 
852  res = LockAcquire(&tag, ExclusiveLock, false, true);
853 
855 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
LockAcquireResult
Definition: lock.h:472
Datum pg_try_advisory_xact_lock_int8 ( PG_FUNCTION_ARGS  )

Definition at line 645 of file lockfuncs.c.

References ExclusiveLock, LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), and SET_LOCKTAG_INT64.

646 {
647  int64 key = PG_GETARG_INT64(0);
648  LOCKTAG tag;
649  LockAcquireResult res;
650 
652  SET_LOCKTAG_INT64(tag, key);
653 
654  res = LockAcquire(&tag, ExclusiveLock, false, true);
655 
657 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define ExclusiveLock
Definition: lockdefs.h:44
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
LockAcquireResult
Definition: lock.h:472
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
Datum pg_try_advisory_xact_lock_shared_int4 ( PG_FUNCTION_ARGS  )

Definition at line 885 of file lockfuncs.c.

References LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT32, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT32, and ShareLock.

886 {
887  int32 key1 = PG_GETARG_INT32(0);
888  int32 key2 = PG_GETARG_INT32(1);
889  LOCKTAG tag;
890  LockAcquireResult res;
891 
893  SET_LOCKTAG_INT32(tag, key1, key2);
894 
895  res = LockAcquire(&tag, ShareLock, false, true);
896 
898 }
#define PG_GETARG_INT32(n)
Definition: fmgr.h:226
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
#define SET_LOCKTAG_INT32(tag, key1, key2)
Definition: lockfuncs.c:536
Definition: lock.h:179
signed int int32
Definition: c.h:256
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
LockAcquireResult
Definition: lock.h:472
#define ShareLock
Definition: lockdefs.h:41
Datum pg_try_advisory_xact_lock_shared_int8 ( PG_FUNCTION_ARGS  )

Definition at line 686 of file lockfuncs.c.

References LockAcquire(), LOCKACQUIRE_NOT_AVAIL, PG_GETARG_INT64, PG_RETURN_BOOL, PreventAdvisoryLocksInParallelMode(), SET_LOCKTAG_INT64, and ShareLock.

687 {
688  int64 key = PG_GETARG_INT64(0);
689  LOCKTAG tag;
690  LockAcquireResult res;
691 
693  SET_LOCKTAG_INT64(tag, key);
694 
695  res = LockAcquire(&tag, ShareLock, false, true);
696 
698 }
LockAcquireResult LockAcquire(const LOCKTAG *locktag, LOCKMODE lockmode, bool sessionLock, bool dontWait)
Definition: lock.c:683
Definition: lock.h:179
static void PreventAdvisoryLocksInParallelMode(void)
Definition: lockfuncs.c:540
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:311
LockAcquireResult
Definition: lock.h:472
#define ShareLock
Definition: lockdefs.h:41
#define SET_LOCKTAG_INT64(tag, key64)
Definition: lockfuncs.c:530
#define PG_GETARG_INT64(n)
Definition: fmgr.h:239
static Datum VXIDGetDatum ( BackendId  bid,
LocalTransactionId  lxid 
)
static

Definition at line 64 of file lockfuncs.c.

References CStringGetTextDatum, and snprintf().

Referenced by pg_lock_status().

65 {
66  /*
67  * The representation is "<bid>/<lxid>", decimal and unsigned decimal
68  * respectively. Note that elog.c also knows how to format a vxid.
69  */
70  char vxidstr[32];
71 
72  snprintf(vxidstr, sizeof(vxidstr), "%d/%u", bid, lxid);
73 
74  return CStringGetTextDatum(vxidstr);
75 }
int snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3
#define CStringGetTextDatum(s)
Definition: builtins.h:91

Variable Documentation

const char* const LockTagTypeNames[]
Initial value:
= {
"relation",
"extend",
"page",
"tuple",
"transactionid",
"virtualxid",
"speculative token",
"object",
"userlock",
"advisory"
}

Definition at line 26 of file lockfuncs.c.

Referenced by GetLockNameFromTagType(), and pg_lock_status().

const char* const PredicateLockTagTypeNames[]
static
Initial value:
= {
"relation",
"page",
"tuple"
}

Definition at line 40 of file lockfuncs.c.

Referenced by pg_lock_status().