diff options
Diffstat (limited to 'src/backend/storage/lmgr')
-rw-r--r-- | src/backend/storage/lmgr/lmgr.c | 6 | ||||
-rw-r--r-- | src/backend/storage/lmgr/lock.c | 111 | ||||
-rw-r--r-- | src/backend/storage/lmgr/lwlock.c | 4 | ||||
-rw-r--r-- | src/backend/storage/lmgr/proc.c | 25 | ||||
-rw-r--r-- | src/backend/storage/lmgr/s_lock.c | 12 |
5 files changed, 82 insertions, 76 deletions
diff --git a/src/backend/storage/lmgr/lmgr.c b/src/backend/storage/lmgr/lmgr.c index 603d48b5aaa..240509416b4 100644 --- a/src/backend/storage/lmgr/lmgr.c +++ b/src/backend/storage/lmgr/lmgr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.68 2004/08/29 04:12:48 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lmgr.c,v 1.69 2004/08/29 05:06:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -66,7 +66,7 @@ static LOCKMASK LockConflicts[] = { }; -static LOCKMETHODID LockTableId = INVALID_LOCKMETHOD; +static LOCKMETHODID LockTableId = INVALID_LOCKMETHOD; /* * Create the lock table described by LockConflicts @@ -74,7 +74,7 @@ static LOCKMETHODID LockTableId = INVALID_LOCKMETHOD; void InitLockTable(int maxBackends) { - LOCKMETHODID LongTermTableId; + LOCKMETHODID LongTermTableId; /* there's no zero-th table */ NumLockMethods = 1; diff --git a/src/backend/storage/lmgr/lock.c b/src/backend/storage/lmgr/lock.c index db2046ced33..55fba035a91 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.138 2004/08/29 04:12:48 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lock.c,v 1.139 2004/08/29 05:06:48 momjian Exp $ * * NOTES * Outside modules can create a lock table and acquire/release @@ -51,12 +51,12 @@ int max_locks_per_xact; /* set by guc.c */ * map from lock method id to the lock table data structures */ static LockMethod LockMethods[MAX_LOCK_METHODS]; -static HTAB *LockMethodLockHash[MAX_LOCK_METHODS]; -static HTAB *LockMethodProcLockHash[MAX_LOCK_METHODS]; -static HTAB *LockMethodLocalHash[MAX_LOCK_METHODS]; +static HTAB *LockMethodLockHash[MAX_LOCK_METHODS]; +static HTAB *LockMethodProcLockHash[MAX_LOCK_METHODS]; +static HTAB *LockMethodLocalHash[MAX_LOCK_METHODS]; /* exported so lmgr.c can initialize it */ -int NumLockMethods; +int NumLockMethods; /* private state for GrantAwaitedLock */ @@ -64,7 +64,7 @@ static LOCALLOCK *awaitedLock; static ResourceOwner awaitedOwner; -static const char * const lock_mode_names[] = +static const char *const lock_mode_names[] = { "INVALID", "AccessShareLock", @@ -146,7 +146,7 @@ PROCLOCK_PRINT(const char *where, const PROCLOCK *proclockP) || (Trace_lock_table && (((LOCK *) MAKE_PTR(proclockP->tag.lock))->tag.relId == Trace_lock_table)) ) elog(LOG, - "%s: proclock(%lx) lock(%lx) tbl(%d) proc(%lx) xid(%u) hold(%x)", + "%s: proclock(%lx) lock(%lx) tbl(%d) proc(%lx) xid(%u) hold(%x)", where, MAKE_OFFSET(proclockP), proclockP->tag.lock, PROCLOCK_LOCKMETHOD(*(proclockP)), proclockP->tag.proc, proclockP->tag.xid, @@ -157,14 +157,13 @@ PROCLOCK_PRINT(const char *where, const PROCLOCK *proclockP) #define LOCK_PRINT(where, lock, type) #define PROCLOCK_PRINT(where, proclockP) - #endif /* not LOCK_DEBUG */ static void RemoveLocalLock(LOCALLOCK *locallock); static void GrantLockLocal(LOCALLOCK *locallock, ResourceOwner owner); static int WaitOnLock(LOCKMETHODID lockmethodid, LOCALLOCK *locallock, - ResourceOwner owner); + ResourceOwner owner); static void LockCountMyLocks(SHMEM_OFFSET lockOffset, PGPROC *proc, int *myHolding); @@ -186,7 +185,7 @@ InitLocks(void) LockMethod GetLocksMethodTable(LOCK *lock) { - LOCKMETHODID lockmethodid = LOCK_LOCKMETHOD(*lock); + LOCKMETHODID lockmethodid = LOCK_LOCKMETHOD(*lock); Assert(0 < lockmethodid && lockmethodid < NumLockMethods); return LockMethods[lockmethodid]; @@ -238,7 +237,7 @@ LockMethodTableInit(const char *tabName, if (numModes >= MAX_LOCKMODES) elog(ERROR, "too many lock types %d (limit is %d)", - numModes, MAX_LOCKMODES-1); + numModes, MAX_LOCKMODES - 1); /* Compute init/max size to request for lock hashtables */ max_table_size = NLOCKENTS(maxBackends); @@ -285,10 +284,10 @@ LockMethodTableInit(const char *tabName, sprintf(shmemName, "%s (lock hash)", tabName); LockMethodLockHash[lockmethodid] = ShmemInitHash(shmemName, - init_table_size, - max_table_size, - &info, - hash_flags); + init_table_size, + max_table_size, + &info, + hash_flags); if (!LockMethodLockHash[lockmethodid]) elog(FATAL, "could not initialize lock table \"%s\"", tabName); @@ -304,22 +303,23 @@ LockMethodTableInit(const char *tabName, sprintf(shmemName, "%s (proclock hash)", tabName); LockMethodProcLockHash[lockmethodid] = ShmemInitHash(shmemName, - init_table_size, - max_table_size, - &info, - hash_flags); + init_table_size, + max_table_size, + &info, + hash_flags); if (!LockMethodProcLockHash[lockmethodid]) elog(FATAL, "could not initialize lock table \"%s\"", tabName); /* - * allocate a non-shared hash table for LOCALLOCK structs. This is used - * to store lock counts and resource owner information. + * allocate a non-shared hash table for LOCALLOCK structs. This is + * used to store lock counts and resource owner information. * * The non-shared table could already exist in this process (this occurs - * when the postmaster is recreating shared memory after a backend crash). - * If so, delete and recreate it. (We could simply leave it, since it - * ought to be empty in the postmaster, but for safety let's zap it.) + * when the postmaster is recreating shared memory after a backend + * crash). If so, delete and recreate it. (We could simply leave it, + * since it ought to be empty in the postmaster, but for safety let's + * zap it.) */ if (LockMethodLocalHash[lockmethodid]) hash_destroy(LockMethodLocalHash[lockmethodid]); @@ -359,7 +359,7 @@ LockMethodTableInit(const char *tabName, LOCKMETHODID LockMethodTableRename(LOCKMETHODID lockmethodid) { - LOCKMETHODID newLockMethodId; + LOCKMETHODID newLockMethodId; if (NumLockMethods >= MAX_LOCK_METHODS) return INVALID_LOCKMETHOD; @@ -483,7 +483,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, /* * Find or create a LOCALLOCK entry for this lock and lockmode */ - MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */ + MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */ localtag.lock = *locktag; localtag.xid = xid; localtag.mode = lockmode; @@ -509,14 +509,14 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, locallock->lockOwners = NULL; locallock->lockOwners = (LOCALLOCKOWNER *) MemoryContextAlloc(TopMemoryContext, - locallock->maxLockOwners * sizeof(LOCALLOCKOWNER)); + locallock->maxLockOwners * sizeof(LOCALLOCKOWNER)); } else { /* Make sure there will be room to remember the lock */ if (locallock->numLockOwners >= locallock->maxLockOwners) { - int newsize = locallock->maxLockOwners * 2; + int newsize = locallock->maxLockOwners * 2; locallock->lockOwners = (LOCALLOCKOWNER *) repalloc(locallock->lockOwners, @@ -526,7 +526,8 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, } /* - * If we already hold the lock, we can just increase the count locally. + * If we already hold the lock, we can just increase the count + * locally. */ if (locallock->nLocks > 0) { @@ -558,7 +559,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of shared memory"), - errhint("You may need to increase max_locks_per_transaction."))); + errhint("You may need to increase max_locks_per_transaction."))); } locallock->lock = lock; @@ -588,7 +589,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, /* * Create the hash key for the proclock table. */ - MemSet(&proclocktag, 0, sizeof(PROCLOCKTAG)); /* must clear padding */ + MemSet(&proclocktag, 0, sizeof(PROCLOCKTAG)); /* must clear padding */ proclocktag.lock = MAKE_OFFSET(lock); proclocktag.proc = MAKE_OFFSET(MyProc); TransactionIdStore(xid, &proclocktag.xid); @@ -605,7 +606,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of shared memory"), - errhint("You may need to increase max_locks_per_transaction."))); + errhint("You may need to increase max_locks_per_transaction."))); } locallock->proclock = proclock; @@ -668,8 +669,8 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, Assert((lock->nRequested > 0) && (lock->requested[lockmode] > 0)); /* - * If this process (under any XID) is a holder of the lock, just - * grant myself another one without blocking. + * If this process (under any XID) is a holder of the lock, just grant + * myself another one without blocking. */ LockCountMyLocks(proclock->tag.lock, MyProc, myHolding); if (myHolding[lockmode] > 0) @@ -715,7 +716,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, SHMQueueDelete(&proclock->lockLink); SHMQueueDelete(&proclock->procLink); proclock = (PROCLOCK *) hash_search(LockMethodProcLockHash[lockmethodid], - (void *) &(proclock->tag), + (void *) &(proclock->tag), HASH_REMOVE, NULL); if (!proclock) elog(WARNING, "proclock table corrupted"); @@ -737,7 +738,7 @@ LockAcquire(LOCKMETHODID lockmethodid, LOCKTAG *locktag, * Construct bitmask of locks this process holds on this object. */ { - LOCKMASK heldLocks = 0; + LOCKMASK heldLocks = 0; for (i = 1; i <= lockMethodTable->numLockModes; i++) { @@ -954,7 +955,7 @@ static void GrantLockLocal(LOCALLOCK *locallock, ResourceOwner owner) { LOCALLOCKOWNER *lockOwners = locallock->lockOwners; - int i; + int i; Assert(locallock->numLockOwners < locallock->maxLockOwners); /* Count the total */ @@ -1153,7 +1154,7 @@ LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag, /* * Find the LOCALLOCK entry for this lock and lockmode */ - MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */ + MemSet(&localtag, 0, sizeof(localtag)); /* must clear padding */ localtag.lock = *locktag; localtag.xid = xid; localtag.mode = lockmode; @@ -1179,7 +1180,7 @@ LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag, { LOCALLOCKOWNER *lockOwners = locallock->lockOwners; ResourceOwner owner; - int i; + int i; /* Session locks and user locks are not transactional */ if (xid != InvalidTransactionId && @@ -1213,7 +1214,7 @@ LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag, } /* - * Decrease the total local count. If we're still holding the lock, + * Decrease the total local count. If we're still holding the lock, * we're done. */ locallock->nLocks--; @@ -1239,8 +1240,8 @@ LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag, PROCLOCK_PRINT("LockRelease: found", proclock); /* - * Double-check that we are actually holding a lock of the type we want to - * release. + * Double-check that we are actually holding a lock of the type we + * want to release. */ if (!(proclock->holdMask & LOCKBIT_ON(lockmode))) { @@ -1316,8 +1317,8 @@ LockRelease(LOCKMETHODID lockmethodid, LOCKTAG *locktag, if (lock->nRequested == 0) { /* - * We've just released the last lock, so garbage-collect the - * lock object. + * We've just released the last lock, so garbage-collect the lock + * object. */ Assert(SHMQueueEmpty(&(lock->procLocks))); lock = (LOCK *) hash_search(LockMethodLockHash[lockmethodid], @@ -1367,7 +1368,7 @@ LockReleaseAll(LOCKMETHODID lockmethodid, bool allxids) LockMethod lockMethodTable; int i, numLockModes; - LOCALLOCK *locallock; + LOCALLOCK *locallock; PROCLOCK *proclock; LOCK *lock; @@ -1390,9 +1391,9 @@ LockReleaseAll(LOCKMETHODID lockmethodid, bool allxids) /* * First we run through the locallock table and get rid of unwanted * entries, then we scan the process's proclocks and get rid of those. - * We do this separately because we may have multiple locallock entries - * pointing to the same proclock, and we daren't end up with any - * dangling pointers. + * We do this separately because we may have multiple locallock + * entries pointing to the same proclock, and we daren't end up with + * any dangling pointers. */ hash_seq_init(&status, LockMethodLocalHash[lockmethodid]); @@ -1413,7 +1414,10 @@ LockReleaseAll(LOCKMETHODID lockmethodid, bool allxids) if (LOCALLOCK_LOCKMETHOD(*locallock) != lockmethodid) continue; - /* Ignore locks with Xid=0 unless we are asked to release all locks */ + /* + * Ignore locks with Xid=0 unless we are asked to release all + * locks + */ if (TransactionIdEquals(locallock->tag.xid, InvalidTransactionId) && !allxids) continue; @@ -1443,7 +1447,10 @@ LockReleaseAll(LOCKMETHODID lockmethodid, bool allxids) if (LOCK_LOCKMETHOD(*lock) != lockmethodid) goto next_item; - /* Ignore locks with Xid=0 unless we are asked to release all locks */ + /* + * Ignore locks with Xid=0 unless we are asked to release all + * locks + */ if (TransactionIdEquals(proclock->tag.xid, InvalidTransactionId) && !allxids) goto next_item; @@ -1552,7 +1559,7 @@ void LockReleaseCurrentOwner(void) { HASH_SEQ_STATUS status; - LOCALLOCK *locallock; + LOCALLOCK *locallock; LOCALLOCKOWNER *lockOwners; int i; @@ -1613,7 +1620,7 @@ LockReassignCurrentOwner(void) { ResourceOwner parent = ResourceOwnerGetParent(CurrentResourceOwner); HASH_SEQ_STATUS status; - LOCALLOCK *locallock; + LOCALLOCK *locallock; LOCALLOCKOWNER *lockOwners; Assert(parent != NULL); diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c index 68573a9bbac..2760dbdf5b6 100644 --- a/src/backend/storage/lmgr/lwlock.c +++ b/src/backend/storage/lmgr/lwlock.c @@ -15,7 +15,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.23 2004/08/29 04:12:49 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.24 2004/08/29 05:06:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -533,7 +533,7 @@ LWLockReleaseAll(void) bool LWLockHeldByMe(LWLockId lockid) { - int i; + int i; for (i = 0; i < num_held_lwlocks; i++) { diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index 22f351691d0..8d05a293d2a 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.152 2004/08/29 04:12:49 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/proc.c,v 1.153 2004/08/29 05:06:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -122,7 +122,8 @@ ProcGlobalSemas(int maxBackends) void InitProcGlobal(int maxBackends) { - bool foundProcGlobal, foundDummy; + bool foundProcGlobal, + foundDummy; /* Create or attach to the ProcGlobal shared structure */ ProcGlobal = (PROC_HDR *) @@ -279,7 +280,7 @@ InitProcess(void) void InitDummyProcess(int proctype) { - PGPROC *dummyproc; + PGPROC *dummyproc; /* * ProcGlobal should be set by a previous call to InitProcGlobal (we @@ -365,9 +366,9 @@ LockWaitCancel(void) { /* * Somebody kicked us off the lock queue already. Perhaps they - * granted us the lock, or perhaps they detected a deadlock. - * If they did grant us the lock, we'd better remember it in - * our local lock table. + * granted us the lock, or perhaps they detected a deadlock. If + * they did grant us the lock, we'd better remember it in our + * local lock table. */ if (MyProc->waitStatus == STATUS_OK) GrantAwaitedLock(); @@ -480,8 +481,8 @@ ProcKill(int code, Datum arg) static void DummyProcKill(int code, Datum arg) { - int proctype = DatumGetInt32(arg); - PGPROC *dummyproc; + int proctype = DatumGetInt32(arg); + PGPROC *dummyproc; Assert(proctype >= 0 && proctype < NUM_DUMMY_PROCS); @@ -696,8 +697,8 @@ ProcSleep(LockMethod lockMethodTable, /* * Set timer so we can wake up after awhile and check for a deadlock. * If a deadlock is detected, the handler releases the process's - * semaphore and sets MyProc->waitStatus = STATUS_ERROR, allowing us to - * know that we must report failure rather than success. + * semaphore and sets MyProc->waitStatus = STATUS_ERROR, allowing us + * to know that we must report failure rather than success. * * By delaying the check until we've waited for a bit, we can avoid * running the rather expensive deadlock-check code in most cases. @@ -914,8 +915,8 @@ CheckDeadLock(void) RemoveFromWaitQueue(MyProc); /* - * Set MyProc->waitStatus to STATUS_ERROR so that ProcSleep will report - * an error after we return from the signal handler. + * Set MyProc->waitStatus to STATUS_ERROR so that ProcSleep will + * report an error after we return from the signal handler. */ MyProc->waitStatus = STATUS_ERROR; diff --git a/src/backend/storage/lmgr/s_lock.c b/src/backend/storage/lmgr/s_lock.c index b96104a7e09..8377e103ebc 100644 --- a/src/backend/storage/lmgr/s_lock.c +++ b/src/backend/storage/lmgr/s_lock.c @@ -9,7 +9,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.29 2004/08/29 04:12:49 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.30 2004/08/29 05:06:48 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -73,8 +73,8 @@ s_lock(volatile slock_t *lock, const char *file, int line) * (and thus the probability of unintended failure) than to fix the * total time spent. * - * The pg_usleep() delays are measured in centiseconds (0.01 sec) because 10 - * msec is a common resolution limit at the OS level. + * The pg_usleep() delays are measured in centiseconds (0.01 sec) because + * 10 msec is a common resolution limit at the OS level. */ #define SPINS_PER_DELAY 100 #define NUM_DELAYS 1000 @@ -125,7 +125,7 @@ s_lock(volatile slock_t *lock, const char *file, int line) */ -#ifdef HAVE_SPINLOCKS /* skip spinlocks if requested */ +#ifdef HAVE_SPINLOCKS /* skip spinlocks if requested */ #if defined(__GNUC__) @@ -238,10 +238,8 @@ tas_dummy() /* really means: extern int tas(slock_t } #endif /* __sparc || __sparc__ */ - #endif /* not __GNUC__ */ - -#endif /* HAVE_SPINLOCKS */ +#endif /* HAVE_SPINLOCKS */ |