Skip to content

Commit 0e8ac82

Browse files
committed
Fix a variety of locking problems like newer lock waiters getting
lock before older waiters, and having readlock people not share locks if a writer is waiting for a lock, and waiting writers not getting priority over waiting readers.
1 parent 1de8926 commit 0e8ac82

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/backend/storage/lmgr/lock.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.19 1998/01/23 06:01:03 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/lock.c,v 1.20 1998/01/23 22:16:46 momjian Exp $
1111
*
1212
* NOTES
1313
* Outside modules can create a lock table and acquire/release
@@ -708,6 +708,20 @@ LockResolveConflicts(LOCKTAB *ltable,
708708
result->nHolding = 0;
709709
}
710710

711+
{
712+
/* ------------------------
713+
* If someone with a greater priority is waiting for the lock,
714+
* do not continue and share the lock, even if we can. bjm
715+
* ------------------------
716+
*/
717+
int myprio = ltable->ctl->prio[lockt];
718+
PROC_QUEUE *waitQueue = &(lock->waitProcs);
719+
PROC *topproc = (PROC *) MAKE_PTR(waitQueue->links.prev);
720+
721+
if (waitQueue->size && topproc->prio > myprio)
722+
return STATUS_FOUND;
723+
}
724+
711725
/* ----------------------------
712726
* first check for global conflicts: If no locks conflict
713727
* with mine, then I get the lock.

src/backend/storage/lmgr/proc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.26 1998/01/23 06:01:05 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.27 1998/01/23 22:16:48 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -46,7 +46,7 @@
4646
* This is so that we can support more backends. (system-wide semaphore
4747
* sets run out pretty fast.) -ay 4/95
4848
*
49-
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.26 1998/01/23 06:01:05 momjian Exp $
49+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.27 1998/01/23 22:16:48 momjian Exp $
5050
*/
5151
#include <sys/time.h>
5252
#include <unistd.h>
@@ -469,7 +469,7 @@ ProcSleep(PROC_QUEUE *queue,
469469
proc = (PROC *) MAKE_PTR(queue->links.prev);
470470
for (i = 0; i < queue->size; i++)
471471
{
472-
if (proc->prio < prio)
472+
if (proc->prio >= prio)
473473
proc = (PROC *) MAKE_PTR(proc->links.prev);
474474
else
475475
break;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy