summaryrefslogtreecommitdiff
path: root/src/backend/storage/ipc
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/storage/ipc')
-rw-r--r--src/backend/storage/ipc/ipc.c39
-rw-r--r--src/backend/storage/ipc/ipci.c17
-rw-r--r--src/backend/storage/ipc/shmem.c5
-rw-r--r--src/backend/storage/ipc/spin.c91
4 files changed, 41 insertions, 111 deletions
diff --git a/src/backend/storage/ipc/ipc.c b/src/backend/storage/ipc/ipc.c
index 59c991bd0a7..ff326becf1e 100644
--- a/src/backend/storage/ipc/ipc.c
+++ b/src/backend/storage/ipc/ipc.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.38 1999/07/17 20:17:43 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipc.c,v 1.39 1999/10/06 21:58:06 vadim Exp $
*
* NOTES
*
@@ -284,18 +284,6 @@ IPCPrivateMemoryKill(int status,
}
}
-
-/****************************************************************************/
-/* IpcSemaphoreCreate(semKey, semNum, permission, semStartValue) */
-/* */
-/* - returns a semaphore identifier: */
-/* */
-/* if key doesn't exist: return a new id, status:= IpcSemIdNotExist */
-/* if key exists: return the old id, status:= IpcSemIdExist */
-/* if semNum > MAX : return # of argument, status:=IpcInvalidArgument */
-/* */
-/****************************************************************************/
-
/*
* Note:
* XXX This should be split into two different calls. One should
@@ -312,8 +300,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
int semNum,
int permission,
int semStartValue,
- int removeOnExit,
- int *status)
+ int removeOnExit)
{
int i;
int errStatus;
@@ -321,20 +308,14 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
u_short array[IPC_NMAXSEM];
union semun semun;
- /* get a semaphore if non-existent */
/* check arguments */
if (semNum > IPC_NMAXSEM || semNum <= 0)
- {
- *status = IpcInvalidArgument;
- return 2; /* returns the number of the invalid
- * argument */
- }
+ return(-1);
semId = semget(semKey, 0, 0);
if (semId == -1)
{
- *status = IpcSemIdNotExist; /* there doesn't exist a semaphore */
#ifdef DEBUG_IPC
EPRINTF("calling semget with %d, %d , %d\n",
semKey,
@@ -348,7 +329,7 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
EPRINTF("IpcSemaphoreCreate: semget failed (%s) "
"key=%d, num=%d, permission=%o",
strerror(errno), semKey, semNum, permission);
- proc_exit(3);
+ return(-1);
}
for (i = 0; i < semNum; i++)
array[i] = semStartValue;
@@ -358,22 +339,16 @@ IpcSemaphoreCreate(IpcSemaphoreKey semKey,
{
EPRINTF("IpcSemaphoreCreate: semctl failed (%s) id=%d",
strerror(errno), semId);
+ semctl(semId, 0, IPC_RMID, semun);
+ return(-1);
}
if (removeOnExit)
on_shmem_exit(IPCPrivateSemaphoreKill, (caddr_t) semId);
-
- }
- else
- {
- /* there is a semaphore id for this key */
- *status = IpcSemIdExist;
}
#ifdef DEBUG_IPC
- EPRINTF("\nIpcSemaphoreCreate, status %d, returns %d\n",
- *status,
- semId);
+ EPRINTF("\nIpcSemaphoreCreate, returns %d\n", semId);
fflush(stdout);
fflush(stderr);
#endif
diff --git a/src/backend/storage/ipc/ipci.c b/src/backend/storage/ipc/ipci.c
index 16c5266c6cd..259a1f532c9 100644
--- a/src/backend/storage/ipc/ipci.c
+++ b/src/backend/storage/ipc/ipci.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.30 1999/07/17 20:17:44 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/ipci.c,v 1.31 1999/10/06 21:58:06 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -54,17 +54,17 @@ void
CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends)
{
int size;
+ extern int XLOGShmemSize(void);
+ extern void XLOGShmemInit(void);
#ifdef HAS_TEST_AND_SET
- /* ---------------
- * create shared memory for slocks
- * --------------
+ /*
+ * Create shared memory for slocks
*/
CreateAndInitSLockMemory(IPCKeyGetSLockSharedMemoryKey(key));
#endif
- /* ----------------
- * kill and create the buffer manager buffer pool (and semaphore)
- * ----------------
+ /*
+ * Kill and create the buffer manager buffer pool (and semaphore)
*/
CreateSpinlocks(IPCKeyGetSpinLockSemaphoreKey(key));
@@ -73,7 +73,7 @@ CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends)
* moderately-accurate estimates for the big hogs, plus 100K for the
* stuff that's too small to bother with estimating.
*/
- size = BufferShmemSize() + LockShmemSize(maxBackends);
+ size = BufferShmemSize() + LockShmemSize(maxBackends) + XLOGShmemSize();
#ifdef STABLE_MEMORY_STORAGE
size += MMShmemSize();
#endif
@@ -89,6 +89,7 @@ CreateSharedMemoryAndSemaphores(IPCKey key, int maxBackends)
ShmemCreate(IPCKeyGetBufferMemoryKey(key), size);
ShmemIndexReset();
InitShmem(key, size);
+ XLOGShmemInit();
InitBufferPool(key);
/* ----------------
diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c
index c23952c1910..e76829ec7c9 100644
--- a/src/backend/storage/ipc/shmem.c
+++ b/src/backend/storage/ipc/shmem.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.46 1999/09/24 00:24:35 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/shmem.c,v 1.47 1999/10/06 21:58:06 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -187,8 +187,7 @@ InitShmem(unsigned int key, unsigned int size)
* bootstrap initialize spin locks so we can start to use the
* allocator and shmem index.
*/
- if (!InitSpinLocks(ShmemBootstrap, IPCKeyGetSpinLockSemaphoreKey(key)))
- return FALSE;
+ InitSpinLocks();
/*
* We have just allocated additional space for two spinlocks. Now
diff --git a/src/backend/storage/ipc/spin.c b/src/backend/storage/ipc/spin.c
index 4d9bd3f71b4..700f5bfaf6d 100644
--- a/src/backend/storage/ipc/spin.c
+++ b/src/backend/storage/ipc/spin.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.20 1999/07/16 04:59:44 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.21 1999/10/06 21:58:06 vadim Exp $
*
*-------------------------------------------------------------------------
*/
@@ -40,15 +40,15 @@ IpcSemaphoreId SpinLockId;
#ifdef HAS_TEST_AND_SET
/* real spin lock implementations */
-bool
+void
CreateSpinlocks(IPCKey key)
{
/* the spin lock shared memory must have been created by now */
- return TRUE;
+ return;
}
-bool
-InitSpinLocks(int init, IPCKey key)
+void
+InitSpinLocks(void)
{
extern SPINLOCK ShmemLock;
extern SPINLOCK ShmemIndexLock;
@@ -57,7 +57,8 @@ InitSpinLocks(int init, IPCKey key)
extern SPINLOCK ProcStructLock;
extern SPINLOCK SInvalLock;
extern SPINLOCK OidGenLockId;
-
+ extern SPINLOCK XidGenLockId;
+ extern SPINLOCK ControlFileLockId;
#ifdef STABLE_MEMORY_STORAGE
extern SPINLOCK MMCacheLock;
@@ -71,12 +72,14 @@ InitSpinLocks(int init, IPCKey key)
ProcStructLock = (SPINLOCK) PROCSTRUCTLOCKID;
SInvalLock = (SPINLOCK) SINVALLOCKID;
OidGenLockId = (SPINLOCK) OIDGENLOCKID;
+ XidGenLockId = (SPINLOCK) XIDGENLOCKID;
+ ControlFileLockId = (SPINLOCK) CNTLFILELOCKID;
#ifdef STABLE_MEMORY_STORAGE
MMCacheLock = (SPINLOCK) MMCACHELOCKID;
#endif
- return TRUE;
+ return;
}
#ifdef LOCKDEBUG
@@ -224,55 +227,17 @@ SpinIsLocked(SPINLOCK lock)
* the spinlocks
*
*/
-bool
+void
CreateSpinlocks(IPCKey key)
{
- int status;
- IpcSemaphoreId semid;
-
- semid = IpcSemaphoreCreate(key, MAX_SPINS, IPCProtection,
- IpcSemaphoreDefaultStartValue, 1, &status);
- if (status == IpcSemIdExist)
- {
- IpcSemaphoreKill(key);
- elog(NOTICE, "Destroying old spinlock semaphore");
- semid = IpcSemaphoreCreate(key, MAX_SPINS, IPCProtection,
- IpcSemaphoreDefaultStartValue, 1, &status);
- }
+ SpinLockId = IpcSemaphoreCreate(key, MAX_SPINS, IPCProtection,
+ IpcSemaphoreDefaultStartValue, 1);
- if (semid >= 0)
- {
- SpinLockId = semid;
- return TRUE;
- }
- /* cannot create spinlocks */
- elog(FATAL, "CreateSpinlocks: cannot create spin locks");
- return FALSE;
-}
-
-/*
- * Attach to existing spinlock set
- */
-static bool
-AttachSpinLocks(IPCKey key)
-{
- IpcSemaphoreId id;
+ if (SpinLockId <= 0)
+ elog(STOP, "CreateSpinlocks: cannot create spin locks");
- id = semget(key, MAX_SPINS, 0);
- if (id < 0)
- {
- if (errno == EEXIST)
- {
- /* key is the name of someone else's semaphore */
- elog(FATAL, "AttachSpinlocks: SPIN_KEY belongs to someone else");
- }
- /* cannot create spinlocks */
- elog(FATAL, "AttachSpinlocks: cannot create spin locks");
- return FALSE;
- }
- SpinLockId = id;
- return TRUE;
+ return;
}
/*
@@ -287,8 +252,8 @@ AttachSpinLocks(IPCKey key)
* (SJCacheLock) for it. Same story for the main memory storage mgr.
*
*/
-bool
-InitSpinLocks(int init, IPCKey key)
+void
+InitSpinLocks(void)
{
extern SPINLOCK ShmemLock;
extern SPINLOCK ShmemIndexLock;
@@ -297,26 +262,14 @@ InitSpinLocks(int init, IPCKey key)
extern SPINLOCK ProcStructLock;
extern SPINLOCK SInvalLock;
extern SPINLOCK OidGenLockId;
+ extern SPINLOCK XidGenLockId;
+ extern SPINLOCK ControlFileLockId;
#ifdef STABLE_MEMORY_STORAGE
extern SPINLOCK MMCacheLock;
#endif
- if (!init || key != IPC_PRIVATE)
- {
-
- /*
- * if bootstrap and key is IPC_PRIVATE, it means that we are
- * running backend by itself. no need to attach spinlocks
- */
- if (!AttachSpinLocks(key))
- {
- elog(FATAL, "InitSpinLocks: couldnt attach spin locks");
- return FALSE;
- }
- }
-
/* These five (or six) spinlocks have fixed location is shmem */
ShmemLock = (SPINLOCK) SHMEMLOCKID;
ShmemIndexLock = (SPINLOCK) SHMEMINDEXLOCKID;
@@ -325,12 +278,14 @@ InitSpinLocks(int init, IPCKey key)
ProcStructLock = (SPINLOCK) PROCSTRUCTLOCKID;
SInvalLock = (SPINLOCK) SINVALLOCKID;
OidGenLockId = (SPINLOCK) OIDGENLOCKID;
+ XidGenLockId = (SPINLOCK) XIDGENLOCKID;
+ ControlFileLockId = (SPINLOCK) CNTLFILELOCKID;
#ifdef STABLE_MEMORY_STORAGE
MMCacheLock = (SPINLOCK) MMCACHELOCKID;
#endif
- return TRUE;
+ return;
}
#endif /* HAS_TEST_AND_SET */