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

Commitf39aecb

Browse files
robertmhaasAlexander Korotkov
authored and
Alexander Korotkov
committed
Provide a way to predefine LWLock tranche IDs.
It's a bit cumbersome to use LWLockNewTrancheId(), because the returnedvalue needs to be shared between backends so that each backend can callLWLockRegisterTranche() with the correct ID. So, for built-in tranches,use a hard-coded value instead.This is motivated by an upcoming patch adding further built-in tranches.Andres Freund and Robert Haas
1 parent0fd361a commitf39aecb

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

‎src/backend/access/transam/xlog.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,6 @@ typedef struct XLogCtlInsert
512512
*/
513513
WALInsertLockPadded*WALInsertLocks;
514514
LWLockTrancheWALInsertLockTranche;
515-
intWALInsertLockTrancheId;
516515
}XLogCtlInsert;
517516

518517
/*
@@ -4635,7 +4634,7 @@ XLOGShmemInit(void)
46354634

46364635
/* Initialize local copy of WALInsertLocks and register the tranche */
46374636
WALInsertLocks=XLogCtl->Insert.WALInsertLocks;
4638-
LWLockRegisterTranche(XLogCtl->Insert.WALInsertLockTrancheId,
4637+
LWLockRegisterTranche(LWTRANCHE_WAL_INSERT,
46394638
&XLogCtl->Insert.WALInsertLockTranche);
46404639
return;
46414640
}
@@ -4659,17 +4658,14 @@ XLOGShmemInit(void)
46594658
(WALInsertLockPadded*)allocptr;
46604659
allocptr+=sizeof(WALInsertLockPadded)*NUM_XLOGINSERT_LOCKS;
46614660

4662-
XLogCtl->Insert.WALInsertLockTrancheId=LWLockNewTrancheId();
4663-
46644661
XLogCtl->Insert.WALInsertLockTranche.name="WALInsertLocks";
46654662
XLogCtl->Insert.WALInsertLockTranche.array_base=WALInsertLocks;
46664663
XLogCtl->Insert.WALInsertLockTranche.array_stride=sizeof(WALInsertLockPadded);
46674664

4668-
LWLockRegisterTranche(XLogCtl->Insert.WALInsertLockTrancheId,&XLogCtl->Insert.WALInsertLockTranche);
4665+
LWLockRegisterTranche(LWTRANCHE_WAL_INSERT,&XLogCtl->Insert.WALInsertLockTranche);
46694666
for (i=0;i<NUM_XLOGINSERT_LOCKS;i++)
46704667
{
4671-
LWLockInitialize(&WALInsertLocks[i].l.lock,
4672-
XLogCtl->Insert.WALInsertLockTrancheId);
4668+
LWLockInitialize(&WALInsertLocks[i].l.lock,LWTRANCHE_WAL_INSERT);
46734669
WALInsertLocks[i].l.insertingAt=InvalidXLogRecPtr;
46744670
}
46754671

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ CreateLWLocks(void)
445445

446446
/* Initialize all LWLocks in main array */
447447
for (id=0,lock=MainLWLockArray;id<numLocks;id++,lock++)
448-
LWLockInitialize(&lock->lock,0);
448+
LWLockInitialize(&lock->lock,LWTRANCHE_MAIN);
449449

450450
/*
451451
* Initialize the dynamic-allocation counters, which are stored just
@@ -457,7 +457,7 @@ CreateLWLocks(void)
457457
LWLockCounter= (int*) ((char*)MainLWLockArray-3*sizeof(int));
458458
LWLockCounter[0]=NUM_FIXED_LWLOCKS;
459459
LWLockCounter[1]=numLocks;
460-
LWLockCounter[2]=1;/* 0 is the main array */
460+
LWLockCounter[2]=LWTRANCHE_FIRST_USER_DEFINED;
461461
}
462462

463463
if (LWLockTrancheArray==NULL)
@@ -466,12 +466,13 @@ CreateLWLocks(void)
466466
LWLockTrancheArray= (LWLockTranche**)
467467
MemoryContextAlloc(TopMemoryContext,
468468
LWLockTranchesAllocated*sizeof(LWLockTranche*));
469+
Assert(LWLockTranchesAllocated >=LWTRANCHE_FIRST_USER_DEFINED);
469470
}
470471

471472
MainLWLockTranche.name="main";
472473
MainLWLockTranche.array_base=MainLWLockArray;
473474
MainLWLockTranche.array_stride=sizeof(LWLockPadded);
474-
LWLockRegisterTranche(0,&MainLWLockTranche);
475+
LWLockRegisterTranche(LWTRANCHE_MAIN,&MainLWLockTranche);
475476
}
476477

477478
/*

‎src/include/storage/lwlock.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@ extern intLWLockNewTrancheId(void);
172172
externvoidLWLockRegisterTranche(inttranche_id,LWLockTranche*tranche);
173173
externvoidLWLockInitialize(LWLock*lock,inttranche_id);
174174

175+
/*
176+
* We reserve a few predefined tranche IDs. A call to LWLockNewTrancheId
177+
* will never return a value less than LWTRANCHE_FIRST_USER_DEFINED.
178+
*/
179+
typedefenumBuiltinTrancheIds
180+
{
181+
LWTRANCHE_MAIN,
182+
LWTRANCHE_WAL_INSERT,
183+
LWTRANCHE_FIRST_USER_DEFINED
184+
}BuiltinTrancheIds;
185+
175186
/*
176187
* Prior to PostgreSQL 9.4, we used an enum type called LWLockId to refer
177188
* to LWLocks. New code should instead use LWLock *. However, for the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp