Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9540d97

Browse files
committed
FIFO lock wait queue, with readers grouped together.
1 parent9a55013 commit9540d97

File tree

1 file changed

+34
-12
lines changed
  • src/backend/storage/lmgr

1 file changed

+34
-12
lines changed

‎src/backend/storage/lmgr/proc.c

Lines changed: 34 additions & 12 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.30 1998/01/28 02:29:29 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.31 1998/02/19 15:04:45 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.30 1998/01/28 02:29:29 momjian Exp $
49+
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.31 1998/02/19 15:04:45 momjian Exp $
5050
*/
5151
#include<sys/time.h>
5252
#include<unistd.h>
@@ -451,19 +451,42 @@ ProcSleep(PROC_QUEUE *waitQueue,
451451
intprio,
452452
LOCK*lock)
453453
{
454-
inti;
454+
inti=0;
455455
PROC*proc;
456456
structitimervaltimeval,
457457
dummy;
458458

459+
/*
460+
*If the first entries in the waitQueue have a greater priority than
461+
*we have, we must be a reader, and they must be a writers, and we
462+
*must be here because the current holder is a writer or a
463+
*reader but we don't share shared locks if a writer is waiting.
464+
*We put ourselves after the writers. This way, we have a FIFO, but
465+
*keep the readers together to give them decent priority, and no one
466+
*starves. Because we group all readers together, a non-empty queue
467+
*only has a few possible configurations:
468+
*
469+
*[readers]
470+
*[writers]
471+
*[readers][writers]
472+
*[writers][readers]
473+
*[writers][readers][writers]
474+
*
475+
*In a full queue, we would have a reader holding a lock, then a
476+
*writer gets the lock, then a bunch of readers, made up of readers
477+
*who could not share the first readlock because a writer was waiting,
478+
*and new readers arriving while the writer had the lock.
479+
*
480+
*/
459481
proc= (PROC*)MAKE_PTR(waitQueue->links.prev);
460-
for (i=0;i<waitQueue->size;i++)
461-
{
462-
if (proc->prio >=prio)
463-
proc= (PROC*)MAKE_PTR(proc->links.prev);
464-
else
465-
break;
466-
}
482+
483+
/* If we are a reader, and they are writers, skip past them */
484+
while (i++<waitQueue->size&&proc->prio>prio)
485+
proc= (PROC*)MAKE_PTR(proc->links.prev);
486+
487+
/* The rest of the queue is FIFO, with readers first, writers last */
488+
while (i++<waitQueue->size&&proc->prio <=prio)
489+
proc= (PROC*)MAKE_PTR(proc->links.prev);
467490

468491
MyProc->prio=prio;
469492
MyProc->token=token;
@@ -596,8 +619,7 @@ ProcLockWakeup(PROC_QUEUE *queue, char *ltable, char *lock)
596619

597620
/*
598621
* ProcWakeup removes proc from the lock waiting process queue and
599-
* returns the next proc in chain.If a writer just dropped its
600-
* lock and there are several waiting readers, wake them all up.
622+
* returns the next proc in chain.
601623
*/
602624
proc=ProcWakeup(proc,NO_ERROR);
603625

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp