head 1.18; access; symbols release_4_2:1.18 aix_ok:1.18 Version_2_1:1.12; locks; strict; comment @ * @; 1.18 date 91.11.18.22.21.22; author mer; state Exp; branches; next 1.17; 1.17 date 91.07.16.13.32.52; author sp; state Exp; branches; next 1.16; 1.16 date 91.05.01.02.51.00; author cimarron; state Exp; branches; next 1.15; 1.15 date 91.04.10.16.13.58; author sp; state Exp; branches; next 1.14; 1.14 date 91.04.08.18.15.22; author sp; state Exp; branches; next 1.13; 1.13 date 91.03.23.01.45.57; author kemnitz; state Exp; branches; next 1.12; 1.12 date 91.02.24.19.59.16; author sp; state Exp; branches; next 1.11; 1.11 date 91.02.24.12.40.36; author sp; state Exp; branches; next 1.10; 1.10 date 91.02.09.16.21.15; author sp; state Exp; branches; next 1.9; 1.9 date 91.02.08.17.37.50; author sp; state Exp; branches; next 1.8; 1.8 date 91.01.17.19.05.57; author sp; state Exp; branches; next 1.7; 1.7 date 91.01.09.19.25.12; author sp; state Exp; branches; next 1.6; 1.6 date 90.11.10.18.04.47; author sp; state Exp; branches; next 1.5; 1.5 date 90.09.25.16.42.53; author kemnitz; state Exp; branches; next 1.4; 1.4 date 90.06.09.18.56.20; author kemnitz; state Exp; branches; next 1.3; 1.3 date 90.03.07.17.19.29; author sp; state Exp; branches; next 1.2; 1.2 date 90.01.31.03.52.27; author sp; state Exp; branches; next 1.1; 1.1 date 90.01.11.14.43.16; author sp; state Exp; branches; next ; desc @routines manipulating Prs2 rule locks @ 1.18 log @prototypes finale @ text @/*======================================================================= * * FILE: * prs2locks.c * * IDENTIFICATION: * $Header: /users/mer/postgres/src/rules/prs2/RCS/prs2locks.c,v 1.17 1991/07/16 13:32:52 sp Exp mer $ * * Routines to manipulate PRS2 locks... * (there are also some useful #define's in lib/H/prs2.h *======================================================================= */ #include #include "utils/log.h" #include "utils/palloc.h" #include "rules/prs2.h" #include "rules/rac.h" /*----------------------------------------------------------------------- * * prs2FreeLocks * *----------------------------------------------------------------------- */ void prs2FreeLocks(lock) RuleLock lock; { if (!RuleLockIsValid(lock)) elog(WARN,"prs2FreeLocks: Invalid rule lock"); #ifdef PRS2_DEBUG { /* * yes, yes, it might help discover a couple of these * tedious, stupid, mean, "carefull what you pfree" memory bugs... */ long i, size; size = prs2LockSize(lock->numberOfLocks); for (i=0; inumberOfLocks = 0; return(t); } /*----------------------------------------------------------------------- * * prs2AddLock * * Add a new lock (filled in with the given data) to a 'prs2Locks' * Note that this frees the space occupied by 'prs2Locks' and reallocates * some other. So this routine should be used with caution! *----------------------------------------------------------------------- */ RuleLock prs2AddLock(oldLocks, ruleId, lockType, attributeNumber, planNumber, partialindx, npartial) RuleLock oldLocks; ObjectId ruleId; Prs2LockType lockType; AttributeNumber attributeNumber; Prs2PlanNumber planNumber; int partialindx; int npartial; { long oldSize; long newSize; RuleLock newLocks; Prs2OneLock theNewLock; if (!RuleLockIsValid(oldLocks)) elog(WARN,"prs2AddLock: Invalid rule lock"); /* * allocate enough space to hold the old locks + the new one.. */ newSize = prs2LockSize(oldLocks->numberOfLocks + 1); newLocks = (RuleLock) palloc(newSize); if (newLocks == NULL) { elog(WARN,"prs2AddLock: palloc failed"); } /* * Now copy the old lock data to the new lock.. */ oldSize = prs2LockSize(oldLocks->numberOfLocks); bcopy(oldLocks, newLocks, oldSize); /* * update the information in newLocks.. */ newLocks->numberOfLocks = oldLocks->numberOfLocks + 1; theNewLock = prs2GetOneLockFromLocks(newLocks, newLocks->numberOfLocks-1); prs2OneLockSetRuleId(theNewLock, ruleId); prs2OneLockSetLockType(theNewLock, lockType); prs2OneLockSetAttributeNumber(theNewLock, attributeNumber); prs2OneLockSetPlanNumber(theNewLock, planNumber); prs2OneLockSetPartialIndx(theNewLock, partialindx); prs2OneLockSetNPartial(theNewLock, npartial); /* * Free the space occupied by oldLocks */ prs2FreeLocks(oldLocks); return(newLocks); } /*----------------------------------------------------------------------- * * prs2GetOneLockFromLocks * * Given a 'RuleLock' return a pointer to its Nth lock.. * (the first locks is lock number 0). *----------------------------------------------------------------------- */ Prs2OneLock prs2GetOneLockFromLocks(lock, n) RuleLock lock; int n; { Prs2OneLock t; if (!RuleLockIsValid(lock)) elog(WARN,"prs2GetOneLockFromLocks: Invalid rule lock"); if (n >= lock->numberOfLocks || n<0) { elog(WARN, "prs2GetOneLockFromLocks: lock # out of range (%d/%d)", n, lock->numberOfLocks); } else { t = & ((lock->locks)[n]); } return(t); } /*------------------------------------------------------------------ * prs2OneLocksAreTheSame * * return true iff the given two 'Prs2OneLock' are the same... *------------------------------------------------------------------ */ bool prs2OneLocksAreTheSame(l1, l2) Prs2OneLock l1; Prs2OneLock l2; { if (prs2OneLockGetRuleId(l1)==prs2OneLockGetRuleId(l2) && prs2OneLockGetLockType(l1)==prs2OneLockGetLockType(l2) && prs2OneLockGetAttributeNumber(l1)== prs2OneLockGetAttributeNumber(l2) && prs2OneLockGetPlanNumber(l1)==prs2OneLockGetPlanNumber(l2) && prs2OneLockGetPartialIndx(l1)==prs2OneLockGetPartialIndx(l2) && prs2OneLockGetNPartial(l1)==prs2OneLockGetNPartial(l2)) return(true); else return(false); } /*------------------------------------------------------------------ * prs2OneLockIsMemberOfLocks * * return true iff the given `oneLock' is one of the locks in `locks'. *------------------------------------------------------------------ */ bool prs2OneLockIsMemberOfLocks(oneLock, locks) Prs2OneLock oneLock; RuleLock locks; { int i, nlocks; Prs2OneLock l; nlocks = prs2GetNumberOfLocks(locks); for (i=0; i= 32 && type_int < 127) printf(" type='%c'", prs2OneLockGetLockType(oneLock)); else printf(" type=0x%x,", type_int); printf(" attrn=%d,", (int)prs2OneLockGetAttributeNumber(oneLock)); printf(" plano=%d,", (int)prs2OneLockGetPlanNumber(oneLock)); printf(" partial=%d/%ds)", (int)prs2OneLockGetPartialIndx(oneLock), (int)prs2OneLockGetNPartial(oneLock)); } printf(" }"); fflush(stdout); } /*------------------------------------------------------------------ * * prs2CopyLocks * * Make a copy of a prs2 lock.. *----------------------------------------------------------------------- */ RuleLock prs2CopyLocks(locks) RuleLock locks; { RuleLock newLocks; int numberOfLocks; Size size; if (!RuleLockIsValid(locks)) elog(WARN,"prs2CopyLocks: Invalid rule lock"); numberOfLocks = prs2GetNumberOfLocks(locks); size = prs2LockSize(numberOfLocks); newLocks = (RuleLock) palloc(size); if (newLocks == NULL) { elog(WARN,"prs2MakeLocks: palloc(%d) failed",size); } bcopy((char *)locks, (char *)newLocks, size); return(newLocks); } /*------------------------------------------------------------------ * * prs2RemoveOneLockInPlace * * This is a routine that removes one lock form a 'RuleLock'. * Note that the removal is done in place, i.e. no copy of the * original locks is made *----------------------------------------------------------------------- */ void prs2RemoveOneLockInPlace(locks, n) RuleLock locks; int n; { int i; Prs2OneLock lock1, lock2; if (!RuleLockIsValid(locks)) { elog(WARN, "prs2RemoveOneLockInPlace: called with NULL lock"); } if (n >= locks->numberOfLocks || n<0) { elog(WARN, "prs2RemoveOneLockInPlace: lock # out of range (%d/%d)", n, locks->numberOfLocks); } /* * Copy the last lock to the lock to be deleted */ lock1 = prs2GetOneLockFromLocks(locks, n); lock2 = prs2GetOneLockFromLocks(locks, prs2GetNumberOfLocks(locks)-1); prs2OneLockSetRuleId(lock1, prs2OneLockGetRuleId(lock2)); prs2OneLockSetLockType(lock1, prs2OneLockGetLockType(lock2)); prs2OneLockSetAttributeNumber(lock1, prs2OneLockGetAttributeNumber(lock2)); prs2OneLockSetPlanNumber(lock1, prs2OneLockGetPlanNumber(lock2)); prs2OneLockSetPartialIndx(lock1, prs2OneLockGetPartialIndx(lock2)); prs2OneLockSetNPartial(lock1, prs2OneLockGetNPartial(lock2)); /* * decrease the number of locks */ locks->numberOfLocks -= 1; } /*------------------------------------------------------------------ * prs2RemoveAllLocksOfRuleInPlace * * remove all the locks of the given rule, in place (i.e. no copies). * Return true if there were locks actually removed, or false * if no locks for this rule were found. *----------------------------------------------------------------------- */ bool prs2RemoveAllLocksOfRuleInPlace(locks, ruleId) RuleLock locks; ObjectId ruleId; { int i; Prs2OneLock onelock; bool result; result = false; i = 0; while (inumberOfLocks; i++) { lock1 = prs2GetOneLockFromLocks(locks, i-1); lock2 = prs2GetOneLockFromLocks(locks, i); prs2OneLockSetRuleId(lock1, prs2OneLockGetRuleId(lock2)); prs2OneLockSetLockType(lock1, prs2OneLockGetLockType(lock2)); prs2OneLockSetAttributeNumber(lock1, prs2OneLockGetAttributeNumber(lock2)); prs2OneLockSetPlanNumber(lock1, prs2OneLockGetPlanNumber(lock2)); } d318 9 d332 1 d334 31 d371 1 d421 1 d449 37 @ 1.9 log @Now 'prs2PutLocks' makes the update in place (i.e. it does NOT create a copy of the tuple). @ text @d7 1 a7 1 * $Header: RCS/prs2locks.c,v 1.8 91/01/17 19:05:57 sp Exp $ a44 1 printf("---> free 0x%x\n", lock); @ 1.8 log @'InvalidRuleLock' is NO longer a shorthand for an empty lock. @ text @d7 1 a7 1 * $Header: RCS/prs2locks.c,v 1.7 91/01/09 19:25:12 sp Exp $ d45 1 d187 1 a187 1 d192 1 a192 2 * given a tuple, create a copy of it and put the given locks in its * t_lock field... d194 2 d198 1 a198 1 HeapTuple a204 1 HeapTuple newTuple; d208 1 a208 2 newTuple = palloctup(tuple, buffer, relation); HeapTupleSetRuleLock(newTuple, InvalidBuffer, newLocks); a209 1 return(newTuple); @ 1.7 log @some more comments... @ text @d7 1 a7 1 * $Header: RCS/prs2locks.c,v 1.6 90/11/10 18:04:47 sp Exp $ d17 1 d28 3 d32 1 d37 5 a41 5 if (lock != NULL) { long i, size; size = prs2LockSize(lock->numberOfLocks); for (i=0; it_lock.l_lock = (RuleLock) NULL; } else { newTuple->t_lock.l_lock = newLocks; } @ 1.4 log @Fixed bug in function with no return value. @ text @d7 1 a7 1 * $Header: RCS/prs2locks.c,v 1.3 90/03/07 17:19:29 sp Exp Locker: kemnitz $ d14 3 a16 3 #include "log.h" #include "palloc.h" #include "prs2.h" d27 2 a28 1 pfree(lock); d75 4 d126 4 d242 3 a244 1 elog(WARN, "prs2PrintLocks: NULL argument!"); d278 3 d321 4 d362 4 @ 1.3 log @minor bug fixes + prs2FreeLocks is now a function and not a macro. @ text @d7 1 a7 1 * $Header: RCS/prs2locks.c,v 1.2 90/01/31 03:52:27 sp Exp $ d49 1 @ 1.2 log @Prs2Locks has been changed to RuleLock. @ text @d7 1 a7 1 * $Header: RCS/prs2locks.c,v 1.1 90/01/11 14:43:16 sp Exp Locker: sp $ d20 12 d152 1 d171 2 a172 1 size = prs2LockSize(prs2GetNumberOfLocks(t)); d210 1 a210 1 newTuple->t_lock.l_lock = (RuleLock) newLocks; d279 5 a283 5 prs2AddLock( newLocks, prs2OneLockGetRuleId(oneLock), prs2OneLockGetLockType(oneLock), prs2OneLockGetAttributeNumber(oneLock), prs2OneLockGetPlanNumber(oneLock)); @ 1.1 log @Initial revision @ text @d7 1 a7 1 * $Header: RCS/prs2locks.c,v 1.2 90/01/11 00:22:56 sp Exp Locker: sp $ d25 1 a25 1 Prs2Locks d28 1 a28 1 Prs2Locks t; d30 1 a30 1 t = (Prs2Locks) palloc(sizeof(Prs2LocksData)); d48 1 a48 1 Prs2Locks d50 1 a50 1 Prs2Locks oldLocks; d58 1 a58 1 Prs2Locks newLocks; d65 1 a65 1 newLocks = (Prs2Locks) palloc(newSize); d98 1 a98 1 * Given a 'Prs2Locks' return a pointer to its Nth lock.. d103 1 a103 1 Prs2Locks lock; d122 1 a122 1 * Extract the locks from a tuple. It returns a 'Prs2Locks', d124 1 a124 1 * locks in it, it will return a 'Prs2Locks' with 'numberOfLocks' d129 1 a129 1 Prs2Locks d138 2 a139 2 Prs2Locks locks; Prs2Locks t; d154 1 a154 1 t = (Prs2Locks) DatumGetPointer(lockDatum); d159 1 a159 1 locks = (Prs2Locks) palloc(size); d183 1 a183 1 Prs2Locks newLocks; d194 1 a194 1 newTuple->t_lock.l_lock = (Prs2Locks) NULL; d196 1 a196 1 newTuple->t_lock.l_lock = (Prs2Locks) newLocks; d211 1 a211 1 Prs2Locks locks; d243 1 a243 1 Prs2Locks d245 1 a245 1 Prs2Locks locks; d247 1 a247 1 Prs2Locks newLocks; d279 1 a279 1 * This is a routine that removes one lock form a 'Prs2Locks'. d285 1 a285 1 Prs2Locks locks; d316 1 a316 1 * the old `Prs2Locks' is destroyed and should never be d320 1 a320 1 Prs2Locks d322 1 a322 1 Prs2Locks oldLocks; d325 1 a325 1 Prs2Locks newLocks; d363 1 a363 1 Prs2Locks d365 2 a366 2 Prs2Locks lock1; Prs2Locks lock2; d368 1 a368 1 Prs2Locks result; @