mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +03:00
Change the way that LWLocks for extensions are allocated.
The previous RequestAddinLWLocks() method had several disadvantages. First, the locks would be in the main tranche; we've recently decided that it's useful for LWLocks used for separate purposes to have separate tranche IDs. Second, there wasn't any correlation between what code called RequestAddinLWLocks() and what code called LWLockAssign(); when multiple modules are in use, it could become quite difficult to troubleshoot problems where LWLockAssign() ran out of locks. To fix, create a concept of named LWLock tranches which can be used either by extension or by core code. Amit Kapila and Robert Haas
This commit is contained in:
@ -3335,9 +3335,12 @@ void RequestAddinShmemSpace(int size)
|
||||
<para>
|
||||
LWLocks are reserved by calling:
|
||||
<programlisting>
|
||||
void RequestAddinLWLocks(int n)
|
||||
void RequestNamedLWLockTranche(const char *tranche_name, int num_lwlocks)
|
||||
</programlisting>
|
||||
from <function>_PG_init</>.
|
||||
from <function>_PG_init</>. This will ensure that an array of
|
||||
<literal>num_lwlocks</> LWLocks is available under the name
|
||||
<literal>tranche_name</>. Use <function>GetNamedLWLockTranche</>
|
||||
to get a pointer to this array.
|
||||
</para>
|
||||
<para>
|
||||
To avoid possible race-conditions, each backend should use the LWLock
|
||||
@ -3356,7 +3359,7 @@ if (!ptr)
|
||||
{
|
||||
initialize contents of shmem area;
|
||||
acquire any requested LWLocks using:
|
||||
ptr->mylockid = LWLockAssign();
|
||||
ptr->locks = GetNamedLWLockTranche("my tranche name");
|
||||
}
|
||||
LWLockRelease(AddinShmemInitLock);
|
||||
}
|
||||
|
Reference in New Issue
Block a user