77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.17 1999/09/04 18:36:45 tgl Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/sinval.c,v 1.18 1999/09/06 19:37:38 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
2121#include "storage/sinval.h"
2222#include "storage/sinvaladt.h"
2323
24- extern SISeg * shmInvalBuffer ;/* the shared buffer segment, set by
25- * SISegmentAttach()
26- */
27- extern BackendId MyBackendId ;
28- extern BackendTag MyBackendTag ;
29-
3024SPINLOCK SInvalLock = (SPINLOCK )NULL ;
3125
3226/****************************************************************************/
@@ -39,11 +33,6 @@ CreateSharedInvalidationState(IPCKey key, int maxBackends)
3933{
4034int status ;
4135
42- /*
43- * REMOVED SISyncKill(IPCKeyGetSIBufferMemorySemaphoreKey(key));
44- * SISyncInit(IPCKeyGetSIBufferMemorySemaphoreKey(key));
45- */
46-
4736/* SInvalLock gets set in spin.c, during spinlock init */
4837status = SISegmentInit (true,IPCKeyGetSIBufferMemoryBlock (key ),
4938maxBackends );
@@ -53,9 +42,9 @@ CreateSharedInvalidationState(IPCKey key, int maxBackends)
5342}
5443
5544/****************************************************************************/
56- /*AttachSharedInvalidationState(key) Attacha buffer segment */
45+ /*AttachSharedInvalidationState(key) Attachto existing buffer segment*/
5746/**/
58- /*should be calledonly bythe POSTMASTER */
47+ /*should be called byeach backend during startup */
5948/****************************************************************************/
6049void
6150AttachSharedInvalidationState (IPCKey key )
@@ -74,6 +63,11 @@ AttachSharedInvalidationState(IPCKey key)
7463elog (FATAL ,"AttachSharedInvalidationState: failed segment init" );
7564}
7665
66+ /*
67+ * InitSharedInvalidationState
68+ *Initialize new backend's state info in buffer segment.
69+ *Must be called after AttachSharedInvalidationState().
70+ */
7771void
7872InitSharedInvalidationState (void )
7973{
@@ -88,24 +82,19 @@ InitSharedInvalidationState(void)
8882
8983/*
9084 * RegisterSharedInvalid
91- *Returns anew local cache invalidationstate containing a new entry .
85+ *Add ashared- cache- invalidationmessage to the global SI message queue .
9286 *
9387 * Note:
9488 *Assumes hash index is valid.
9589 *Assumes item pointer is valid.
9690 */
97- /****************************************************************************/
98- /*RegisterSharedInvalid(cacheId, hashIndex, pointer)*/
99- /**/
100- /*register a message in the buffer*/
101- /*should be called by a backend*/
102- /****************************************************************************/
10391void
10492RegisterSharedInvalid (int cacheId ,/* XXX */
10593Index hashIndex ,
10694ItemPointer pointer )
10795{
108- SharedInvalidData newInvalid ;
96+ SharedInvalidData newInvalid ;
97+ bool insertOK ;
10998
11099/*
111100 * This code has been hacked to accept two types of messages. This
@@ -127,34 +116,16 @@ RegisterSharedInvalid(int cacheId,/* XXX */
127116ItemPointerSetInvalid (& newInvalid .pointerData );
128117
129118SpinAcquire (SInvalLock );
130- while (!SISetDataEntry (shmInvalBuffer ,& newInvalid ))
131- {
132- /* buffer full */
133- /* release a message, mark process cache states to be invalid */
134- SISetProcStateInvalid (shmInvalBuffer );
135-
136- if (!SIDelDataEntries (shmInvalBuffer ,1 ))
137- {
138- /* inconsistent buffer state -- shd never happen */
139- SpinRelease (SInvalLock );
140- elog (FATAL ,"RegisterSharedInvalid: inconsistent buffer state" );
141- }
142-
143- /* loop around to try write again */
144- }
119+ insertOK = SIInsertDataEntry (shmInvalBuffer ,& newInvalid );
145120SpinRelease (SInvalLock );
121+ if (!insertOK )
122+ elog (NOTICE ,"RegisterSharedInvalid: SI buffer overflow" );
146123}
147124
148125/*
149126 * InvalidateSharedInvalid
150- *Processes all entries in a shared cache invalidation state.
127+ *Process shared-cache-invalidation messages waiting for this backend
151128 */
152- /****************************************************************************/
153- /*InvalidateSharedInvalid(invalFunction, resetFunction)*/
154- /**/
155- /*invalidate a message in the buffer (read and clean up)*/
156- /*should be called by a backend*/
157- /****************************************************************************/
158129void
159130InvalidateSharedInvalid (void (* invalFunction ) (),
160131void (* resetFunction ) ())