Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
82fc51e0
Commit
82fc51e0
authored
Feb 22, 2001
by
Bruce Momjian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More comment improvements.
parent
4f6c49fe
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
102 additions
and
101 deletions
+102
-101
src/backend/storage/lmgr/lock.c
src/backend/storage/lmgr/lock.c
+89
-89
src/include/access/nbtree.h
src/include/access/nbtree.h
+4
-4
src/include/storage/lmgr.h
src/include/storage/lmgr.h
+7
-6
src/include/storage/lock.h
src/include/storage/lock.h
+2
-2
No files found.
src/backend/storage/lmgr/lock.c
View file @
82fc51e0
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.8
1 2001/01/25 03:31:16 tgl
Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.8
2 2001/02/22 23:02:33 momjian
Exp $
*
* NOTES
* Outside modules can create a lock table and acquire/release
...
...
@@ -157,24 +157,24 @@ SPINLOCK LockMgrLock; /* in Shmem or created in
static
LOCKMASK
BITS_OFF
[
MAX_LOCKMODES
];
static
LOCKMASK
BITS_ON
[
MAX_LOCKMODES
];
/*
-----------------
/*
* Disable flag
*
-----------------
*
*/
static
bool
LockingIsDisabled
;
/*
-------------------
/*
* map from lockmethod to the lock table structure
*
-------------------
*
*/
static
LOCKMETHODTABLE
*
LockMethodTable
[
MAX_LOCK_METHODS
];
static
int
NumLockMethods
;
/*
-------------------
/*
* InitLocks -- Init the lock module. Create a private data
* structure for constructing conflict masks.
*
-------------------
*
*/
void
InitLocks
(
void
)
...
...
@@ -190,9 +190,9 @@ InitLocks(void)
}
}
/*
-------------------
/*
* LockDisable -- sets LockingIsDisabled flag to TRUE or FALSE.
*
------------------
*
*/
void
LockDisable
(
bool
status
)
...
...
@@ -200,9 +200,9 @@ LockDisable(bool status)
LockingIsDisabled
=
status
;
}
/*
-----------------
/*
* Boolean function to determine current locking status
*
-----------------
*
*/
bool
LockingDisabled
(
void
)
...
...
@@ -295,16 +295,16 @@ LockMethodTableInit(char *tabName,
lockMethodTable
=
(
LOCKMETHODTABLE
*
)
MemoryContextAlloc
(
TopMemoryContext
,
sizeof
(
LOCKMETHODTABLE
));
/*
------------------------
/*
* find/acquire the spinlock for the table
*
------------------------
*
*/
SpinAcquire
(
LockMgrLock
);
/*
-----------------------
/*
* allocate a control structure from shared memory or attach to it
* if it already exists.
*
-----------------------
*
*/
sprintf
(
shmemName
,
"%s (ctl)"
,
tabName
);
lockMethodTable
->
ctl
=
(
LOCKMETHODCTL
*
)
...
...
@@ -313,15 +313,15 @@ LockMethodTableInit(char *tabName,
if
(
!
lockMethodTable
->
ctl
)
elog
(
FATAL
,
"LockMethodTableInit: couldn't initialize %s"
,
tabName
);
/*
-------------------
/*
* no zero-th table
*
-------------------
*
*/
NumLockMethods
=
1
;
/*
----------------
/*
* we're first - initialize
*
----------------
*
*/
if
(
!
found
)
{
...
...
@@ -330,18 +330,18 @@ LockMethodTableInit(char *tabName,
lockMethodTable
->
ctl
->
lockmethod
=
NumLockMethods
;
}
/*
--------------------
/*
* other modules refer to the lock table by a lockmethod ID
*
--------------------
*
*/
LockMethodTable
[
NumLockMethods
]
=
lockMethodTable
;
NumLockMethods
++
;
Assert
(
NumLockMethods
<=
MAX_LOCK_METHODS
);
/*
----------------------
/*
* allocate a hash table for LOCK structs. This is used
* to store per-locked-object information.
*
----------------------
*
*/
info
.
keysize
=
SHMEM_LOCKTAB_KEYSIZE
;
info
.
datasize
=
SHMEM_LOCKTAB_DATASIZE
;
...
...
@@ -359,10 +359,10 @@ LockMethodTableInit(char *tabName,
elog
(
FATAL
,
"LockMethodTableInit: couldn't initialize %s"
,
tabName
);
Assert
(
lockMethodTable
->
lockHash
->
hash
==
tag_hash
);
/*
-------------------------
/*
* allocate a hash table for HOLDER structs. This is used
* to store per-lock-holder information.
*
-------------------------
*
*/
info
.
keysize
=
SHMEM_HOLDERTAB_KEYSIZE
;
info
.
datasize
=
SHMEM_HOLDERTAB_DATASIZE
;
...
...
@@ -528,9 +528,9 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
return
FALSE
;
}
/*
--------------------
/*
* if it's a new lock object, initialize it
*
--------------------
*
*/
if
(
!
found
)
{
...
...
@@ -552,9 +552,9 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
Assert
(
lock
->
nGranted
<=
lock
->
nRequested
);
}
/*
------------------
/*
* Create the hash key for the holder table.
*
------------------
*
*/
MemSet
(
&
holdertag
,
0
,
sizeof
(
HOLDERTAG
));
/* must clear padding, needed */
holdertag
.
lock
=
MAKE_OFFSET
(
lock
);
...
...
@@ -623,20 +623,20 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
#endif
/* CHECK_DEADLOCK_RISK */
}
/*
----------------
/*
* lock->nRequested and lock->requested[] count the total number of
* requests, whether granted or waiting, so increment those immediately.
* The other counts don't increment till we get the lock.
*
----------------
*
*/
lock
->
nRequested
++
;
lock
->
requested
[
lockmode
]
++
;
Assert
((
lock
->
nRequested
>
0
)
&&
(
lock
->
requested
[
lockmode
]
>
0
));
/*
--------------------
/*
* If I already hold one or more locks of the requested type,
* just grant myself another one without blocking.
*
--------------------
*
*/
if
(
holder
->
holding
[
lockmode
]
>
0
)
{
...
...
@@ -646,10 +646,10 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
return
TRUE
;
}
/*
--------------------
/*
* If this process (under any XID) is a holder of the lock,
* also grant myself another one without blocking.
*
--------------------
*
*/
LockCountMyLocks
(
holder
->
tag
.
lock
,
MyProc
,
myHolding
);
if
(
myHolding
[
lockmode
]
>
0
)
...
...
@@ -660,11 +660,11 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
return
TRUE
;
}
/*
--------------------
/*
* If lock requested conflicts with locks requested by waiters,
* must join wait queue. Otherwise, check for conflict with
* already-held locks. (That's last because most complex check.)
*
--------------------
*
*/
if
(
lockMethodTable
->
ctl
->
conflictTab
[
lockmode
]
&
lock
->
waitMask
)
status
=
STATUS_FOUND
;
...
...
@@ -760,7 +760,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
return
status
==
STATUS_OK
;
}
/*
----------------------------
/*
* LockCheckConflicts -- test whether requested lock conflicts
* with those already granted
*
...
...
@@ -775,7 +775,7 @@ LockAcquire(LOCKMETHOD lockmethod, LOCKTAG *locktag,
*
* The caller can optionally pass the process's total holding counts, if
* known. If NULL is passed then these values will be computed internally.
*
----------------------------
*
*/
int
LockCheckConflicts
(
LOCKMETHODTABLE
*
lockMethodTable
,
...
...
@@ -792,7 +792,7 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
tmpMask
;
int
localHolding
[
MAX_LOCKMODES
];
/*
----------------------------
/*
* first check for global conflicts: If no locks conflict
* with my request, then I get the lock.
*
...
...
@@ -800,7 +800,7 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
* currently held locks. conflictTable[lockmode] has a bit
* set for each type of lock that conflicts with request. Bitwise
* compare tells if there is a conflict.
*
----------------------------
*
*/
if
(
!
(
lockctl
->
conflictTab
[
lockmode
]
&
lock
->
grantMask
))
{
...
...
@@ -808,12 +808,12 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
return
STATUS_OK
;
}
/*
------------------------
/*
* Rats. Something conflicts. But it could still be my own
* lock. We have to construct a conflict mask
* that does not reflect our own locks. Locks held by the current
* process under another XID also count as "our own locks".
*
------------------------
*
*/
if
(
myHolding
==
NULL
)
{
...
...
@@ -831,12 +831,12 @@ LockCheckConflicts(LOCKMETHODTABLE *lockMethodTable,
bitmask
|=
tmpMask
;
}
/*
------------------------
/*
* now check again for conflicts. 'bitmask' describes the types
* of locks held by other processes. If one of these
* conflicts with the kind of lock that I want, there is a
* conflict and I have to sleep.
*
------------------------
*
*/
if
(
!
(
lockctl
->
conflictTab
[
lockmode
]
&
bitmask
))
{
...
...
@@ -935,7 +935,7 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
strcat
(
new_status
,
" waiting"
);
set_ps_display
(
new_status
);
/*
-------------------
/*
* NOTE: Think not to put any lock state cleanup after the call to
* ProcSleep, in either the normal or failure path. The lock state
* must be fully set by the lock grantor, or by HandleDeadLock if we
...
...
@@ -944,7 +944,7 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
* after someone else grants us the lock, but before we've noticed it.
* Hence, after granting, the locktable state must fully reflect the
* fact that we own the lock; we can't do additional work on return.
*
-------------------
*
*/
if
(
ProcSleep
(
lockMethodTable
,
...
...
@@ -952,11 +952,11 @@ WaitOnLock(LOCKMETHOD lockmethod, LOCKMODE lockmode,
lock
,
holder
)
!=
STATUS_OK
)
{
/*
-------------------
/*
* We failed as a result of a deadlock, see HandleDeadLock().
* Quit now. Removal of the holder and lock objects, if no longer
* needed, will happen in xact cleanup (see above for motivation).
*
-------------------
*
*/
LOCK_PRINT
(
"WaitOnLock: aborting on lock"
,
lock
,
lockmode
);
SpinRelease
(
lockMethodTable
->
ctl
->
masterLock
);
...
...
@@ -1150,7 +1150,7 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
Assert
((
lock
->
nGranted
>=
0
)
&&
(
lock
->
granted
[
lockmode
]
>=
0
));
Assert
(
lock
->
nGranted
<=
lock
->
nRequested
);
/*
--------------------------
/*
* We need only run ProcLockWakeup if the released lock conflicts with
* at least one of the lock types requested by waiter(s). Otherwise
* whatever conflict made them wait must still exist. NOTE: before MVCC,
...
...
@@ -1158,18 +1158,18 @@ LockRelease(LOCKMETHOD lockmethod, LOCKTAG *locktag,
* But that's not true anymore, because the remaining granted locks might
* belong to some waiter, who could now be awakened because he doesn't
* conflict with his own locks.
*
--------------------------
*
*/
if
(
lockMethodTable
->
ctl
->
conflictTab
[
lockmode
]
&
lock
->
waitMask
)
wakeupNeeded
=
true
;
if
(
lock
->
nRequested
==
0
)
{
/*
------------------
/*
* if there's no one waiting in the queue,
* we just released the last lock on this object.
* Delete it from the lock table.
*
------------------
*
*/
Assert
(
lockMethodTable
->
lockHash
->
hash
==
tag_hash
);
lock
=
(
LOCK
*
)
hash_search
(
lockMethodTable
->
lockHash
,
...
...
@@ -1297,9 +1297,9 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
Assert
(
holder
->
nHolding
>=
0
);
Assert
(
holder
->
nHolding
<=
lock
->
nRequested
);
/*
------------------
/*
* fix the general lock stats
*
------------------
*
*/
if
(
lock
->
nRequested
!=
holder
->
nHolding
)
{
...
...
@@ -1328,10 +1328,10 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
}
else
{
/*
--------------
/*
* This holder accounts for all the requested locks on the object,
* so we can be lazy and just zero things out.
*
--------------
*
*/
lock
->
nRequested
=
0
;
lock
->
nGranted
=
0
;
...
...
@@ -1368,10 +1368,10 @@ LockReleaseAll(LOCKMETHOD lockmethod, PROC *proc,
if
(
lock
->
nRequested
==
0
)
{
/*
--------------------
/*
* We've just released the last lock, so garbage-collect the
* lock object.
*
--------------------
*
*/
LOCK_PRINT
(
"LockReleaseAll: deleting"
,
lock
,
0
);
Assert
(
lockMethodTable
->
lockHash
->
hash
==
tag_hash
);
...
...
src/include/access/nbtree.h
View file @
82fc51e0
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: nbtree.h,v 1.5
3 2001/02/22 21:48:49
momjian Exp $
* $Id: nbtree.h,v 1.5
4 2001/02/22 23:02:33
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
src/include/storage/lmgr.h
View file @
82fc51e0
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: lmgr.h,v 1.2
8 2001/01/24 19:43:27
momjian Exp $
* $Id: lmgr.h,v 1.2
9 2001/02/22 23:02:33
momjian Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -25,11 +25,12 @@
#define AccessShareLock 1
/* SELECT */
#define RowShareLock 2
/* SELECT FOR UPDATE */
#define RowExclusiveLock 3
/* INSERT, UPDATE, DELETE */
#define ShareLock 4
#define ShareRowExclusiveLock 5
#define ExclusiveLock 6
#define AccessExclusiveLock 7
#define ShareLock 4
/* CREATE INDEX */
#define ShareRowExclusiveLock 5
/* like EXCLUSIVE MODE, allows SHARE ROW */
#define ExclusiveLock 6
/* blocks ROW SHARE/SELECT...FOR UPDATE */
#define AccessExclusiveLock 7
/* ALTER TABLE, DROP TABLE, VACUUM, and
* unqualified LOCK TABLE
*/
extern
LOCKMETHOD
LockTableId
;
...
...
src/include/storage/lock.h
View file @
82fc51e0
...
...
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: lock.h,v 1.4
4 2001/01/25 03:31:16 tgl
Exp $
* $Id: lock.h,v 1.4
5 2001/02/22 23:02:33 momjian
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment