1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-16 15:02:33 +03:00

Add support for loadable modules to allocated shared memory and

lightweight locks.

Marc Munro
This commit is contained in:
Bruce Momjian
2006-08-01 19:03:11 +00:00
parent c61607bd52
commit 2c6d96cef6
6 changed files with 261 additions and 13 deletions

View File

@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.42 2006/07/24 16:32:45 petere Exp $
* $PostgreSQL: pgsql/src/backend/storage/lmgr/lwlock.c,v 1.43 2006/08/01 19:03:11 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -29,6 +29,10 @@
#include "storage/spin.h"
static int NumAddinLWLocks(void);
static void AssignAddinLWLocks(void);
/* We use the ShmemLock spinlock to protect LWLockAssign */
extern slock_t *ShmemLock;
@@ -90,6 +94,62 @@ static int *ex_acquire_counts;
static int *block_counts;
#endif
/*
* Structures and globals to allow add-ins to register for their own
* lwlocks from the preload-libraries hook.
*/
typedef struct LWLockNode
{
LWLockId *lock;
struct LWLockNode *next;
} LWLockNode;
static LWLockNode *addin_locks = NULL;
static int num_addin_locks = 0;
/*
* RegisterAddinLWLock() --- Allow an andd-in to request a LWLock
* from the preload-libraries hook.
*/
void
RegisterAddinLWLock(LWLockId *lock)
{
LWLockNode *locknode = malloc(sizeof(LWLockNode));
locknode->next = addin_locks;
locknode->lock = lock;
addin_locks = locknode;
num_addin_locks++;
}
/*
* NumAddinLWLocks() --- Return the number of LWLocks requested by add-ins.
*/
int
NumAddinLWLocks()
{
return num_addin_locks;
}
/*
* AssignAddinLWLocks() --- Assign LWLocks previously requested by add-ins.
*/
void
AssignAddinLWLocks()
{
LWLockNode *node = addin_locks;
while (node)
{
*(node->lock) = LWLockAssign();
node = node->next;
}
}
#ifdef LOCK_DEBUG
bool Trace_lwlocks = false;
@@ -174,6 +234,9 @@ NumLWLocks(void)
/* Leave a few extra for use by user-defined modules. */
numLocks += NUM_USER_DEFINED_LWLOCKS;
/* Add the number that have been explicitly requested by add-ins. */
numLocks += NumAddinLWLocks();
return numLocks;
}
@@ -241,6 +304,12 @@ CreateLWLocks(void)
LWLockCounter = (int *) ((char *) LWLockArray - 2 * sizeof(int));
LWLockCounter[0] = (int) NumFixedLWLocks;
LWLockCounter[1] = numLocks;
/*
* Allocate LWLocks for those add-ins that have explicitly requested
* them.
*/
AssignAddinLWLocks();
}