diff options
author | Simon Riggs <simon@2ndQuadrant.com> | 2010-01-29 19:45:12 +0000 |
---|---|---|
committer | Simon Riggs <simon@2ndQuadrant.com> | 2010-01-29 19:45:12 +0000 |
commit | 29eedd312274a62dfc510be099873319762fdfcc (patch) | |
tree | 25f16b1ba9925cec380c20fc321a77cebb2258b0 /src | |
parent | 6d2bc0a6cf5c8d9a3241a0d7afaf5ca8bf1f11ec (diff) | |
download | postgresql-29eedd312274a62dfc510be099873319762fdfcc.tar.gz postgresql-29eedd312274a62dfc510be099873319762fdfcc.zip |
Adjust GetLockConflicts() so that it uses TopMemoryContext when
executed InHotStandby. Cleaner solution than using malloc or palloc
depending upon situation, as proposed by Tom.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/storage/lmgr/lock.c | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index 2c024f82993..cbc2070c37f 100644 --- a/src/backend/storage/lmgr/lock.c +++ b/src/backend/storage/lmgr/lock.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.192 2010/01/28 10:05:37 sriggs Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.193 2010/01/29 19:45:12 sriggs Exp $ * * NOTES * A lock table is a shared memory hash table. When @@ -1790,7 +1790,7 @@ LockReassignCurrentOwner(void) VirtualTransactionId * GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode) { - static VirtualTransactionId *vxids = NULL; + static VirtualTransactionId *vxids; LOCKMETHODID lockmethodid = locktag->locktag_lockmethodid; LockMethod lockMethodTable; LOCK *lock; @@ -1810,24 +1810,18 @@ GetLockConflicts(const LOCKTAG *locktag, LOCKMODE lockmode) /* * Allocate memory to store results, and fill with InvalidVXID. We only * need enough space for MaxBackends + a terminator, since prepared xacts - * don't count. + * don't count. InHotStandby allocate once in TopMemoryContext. */ - if (!InHotStandby) - vxids = (VirtualTransactionId *) - palloc0(sizeof(VirtualTransactionId) * (MaxBackends + 1)); - else + if (InHotStandby) { if (vxids == NULL) - { vxids = (VirtualTransactionId *) - malloc(sizeof(VirtualTransactionId) * (MaxBackends + 1)); - if (vxids == NULL) - ereport(ERROR, - (errcode(ERRCODE_OUT_OF_MEMORY), - errmsg("out of memory"))); - - } + MemoryContextAlloc(TopMemoryContext, + sizeof(VirtualTransactionId) * (MaxBackends + 1)); } + else + vxids = (VirtualTransactionId *) + palloc0(sizeof(VirtualTransactionId) * (MaxBackends + 1)); /* * Look up the lock object matching the tag. |