Commit 6162432d authored by Tom Lane's avatar Tom Lane

Add more critical-section calls: all code sections that hold spinlocks

are now critical sections, so as to ensure die() won't interrupt us while
we are munging shared-memory data structures.  Avoid insecure intermediate
states in some code that proc_exit will call, like palloc/pfree.  Rename
START/END_CRIT_CODE to START/END_CRIT_SECTION, since that seems to be
what people tend to call them anyway, and make them be called with () like
a function call, in hopes of not confusing pg_indent.
I doubt that this is sufficient to make SIGTERM safe anywhere; there's
just too much code that could get invoked during proc_exit().
parent be8477bc
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.106 2001/01/07 22:14:31 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/heap/heapam.c,v 1.107 2001/01/12 21:53:54 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -1359,7 +1359,7 @@ heap_insert(Relation relation, HeapTuple tup) ...@@ -1359,7 +1359,7 @@ heap_insert(Relation relation, HeapTuple tup)
buffer = RelationGetBufferForTuple(relation, tup->t_len); buffer = RelationGetBufferForTuple(relation, tup->t_len);
/* NO ELOG(ERROR) from here till changes are logged */ /* NO ELOG(ERROR) from here till changes are logged */
START_CRIT_CODE; START_CRIT_SECTION();
RelationPutHeapTuple(relation, buffer, tup); RelationPutHeapTuple(relation, buffer, tup);
/* XLOG stuff */ /* XLOG stuff */
...@@ -1405,7 +1405,7 @@ heap_insert(Relation relation, HeapTuple tup) ...@@ -1405,7 +1405,7 @@ heap_insert(Relation relation, HeapTuple tup)
PageSetLSN(page, recptr); PageSetLSN(page, recptr);
PageSetSUI(page, ThisStartUpID); PageSetSUI(page, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
LockBuffer(buffer, BUFFER_LOCK_UNLOCK); LockBuffer(buffer, BUFFER_LOCK_UNLOCK);
WriteBuffer(buffer); WriteBuffer(buffer);
...@@ -1503,7 +1503,7 @@ l1: ...@@ -1503,7 +1503,7 @@ l1:
return result; return result;
} }
START_CRIT_CODE; START_CRIT_SECTION();
/* store transaction information of xact deleting the tuple */ /* store transaction information of xact deleting the tuple */
TransactionIdStore(GetCurrentTransactionId(), &(tp.t_data->t_xmax)); TransactionIdStore(GetCurrentTransactionId(), &(tp.t_data->t_xmax));
tp.t_data->t_cmax = GetCurrentCommandId(); tp.t_data->t_cmax = GetCurrentCommandId();
...@@ -1532,7 +1532,7 @@ l1: ...@@ -1532,7 +1532,7 @@ l1:
PageSetLSN(dp, recptr); PageSetLSN(dp, recptr);
PageSetSUI(dp, ThisStartUpID); PageSetSUI(dp, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
#ifdef TUPLE_TOASTER_ACTIVE #ifdef TUPLE_TOASTER_ACTIVE
/* ---------- /* ----------
...@@ -1702,7 +1702,7 @@ l2: ...@@ -1702,7 +1702,7 @@ l2:
} }
/* NO ELOG(ERROR) from here till changes are logged */ /* NO ELOG(ERROR) from here till changes are logged */
START_CRIT_CODE; START_CRIT_SECTION();
RelationPutHeapTuple(relation, newbuf, newtup); /* insert new tuple */ RelationPutHeapTuple(relation, newbuf, newtup); /* insert new tuple */
if (buffer == newbuf) if (buffer == newbuf)
...@@ -1734,7 +1734,7 @@ l2: ...@@ -1734,7 +1734,7 @@ l2:
PageSetLSN(BufferGetPage(buffer), recptr); PageSetLSN(BufferGetPage(buffer), recptr);
PageSetSUI(BufferGetPage(buffer), ThisStartUpID); PageSetSUI(BufferGetPage(buffer), ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
if (newbuf != buffer) if (newbuf != buffer)
LockBuffer(newbuf, BUFFER_LOCK_UNLOCK); LockBuffer(newbuf, BUFFER_LOCK_UNLOCK);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.72 2000/12/29 20:47:16 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtinsert.c,v 1.73 2001/01/12 21:53:55 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -518,7 +518,7 @@ _bt_insertonpg(Relation rel, ...@@ -518,7 +518,7 @@ _bt_insertonpg(Relation rel,
} }
else else
{ {
START_CRIT_CODE; START_CRIT_SECTION();
_bt_pgaddtup(rel, page, itemsz, btitem, newitemoff, "page"); _bt_pgaddtup(rel, page, itemsz, btitem, newitemoff, "page");
itup_off = newitemoff; itup_off = newitemoff;
itup_blkno = BufferGetBlockNumber(buf); itup_blkno = BufferGetBlockNumber(buf);
...@@ -563,7 +563,7 @@ _bt_insertonpg(Relation rel, ...@@ -563,7 +563,7 @@ _bt_insertonpg(Relation rel,
PageSetSUI(page, ThisStartUpID); PageSetSUI(page, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
/* Write out the updated page and release pin/lock */ /* Write out the updated page and release pin/lock */
_bt_wrtbuf(rel, buf); _bt_wrtbuf(rel, buf);
} }
...@@ -774,7 +774,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright, ...@@ -774,7 +774,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
* NO ELOG(ERROR) till right sibling is updated. * NO ELOG(ERROR) till right sibling is updated.
* *
*/ */
START_CRIT_CODE; START_CRIT_SECTION();
{ {
xl_btree_split xlrec; xl_btree_split xlrec;
int flag = (newitemonleft) ? int flag = (newitemonleft) ?
...@@ -863,7 +863,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright, ...@@ -863,7 +863,7 @@ _bt_split(Relation rel, Buffer buf, OffsetNumber firstright,
/* write and release the old right sibling */ /* write and release the old right sibling */
if (!P_RIGHTMOST(ropaque)) if (!P_RIGHTMOST(ropaque))
_bt_wrtbuf(rel, sbuf); _bt_wrtbuf(rel, sbuf);
END_CRIT_CODE; END_CRIT_SECTION();
/* split's done */ /* split's done */
return rbuf; return rbuf;
...@@ -1160,7 +1160,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf) ...@@ -1160,7 +1160,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
metad = BTPageGetMeta(metapg); metad = BTPageGetMeta(metapg);
/* NO ELOG(ERROR) from here till newroot op is logged */ /* NO ELOG(ERROR) from here till newroot op is logged */
START_CRIT_CODE; START_CRIT_SECTION();
/* set btree special data */ /* set btree special data */
rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage); rootopaque = (BTPageOpaque) PageGetSpecialPointer(rootpage);
...@@ -1253,7 +1253,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf) ...@@ -1253,7 +1253,7 @@ _bt_newroot(Relation rel, Buffer lbuf, Buffer rbuf)
PageSetSUI(metapg, ThisStartUpID); PageSetSUI(metapg, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
/* write and let go of the new root buffer */ /* write and let go of the new root buffer */
_bt_wrtbuf(rel, rootbuf); _bt_wrtbuf(rel, rootbuf);
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.45 2000/12/29 20:47:17 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/nbtree/nbtpage.c,v 1.46 2001/01/12 21:53:55 tgl Exp $
* *
* NOTES * NOTES
* Postgres btree pages look like ordinary relation pages. The opaque * Postgres btree pages look like ordinary relation pages. The opaque
...@@ -165,7 +165,7 @@ _bt_getroot(Relation rel, int access) ...@@ -165,7 +165,7 @@ _bt_getroot(Relation rel, int access)
rootpage = BufferGetPage(rootbuf); rootpage = BufferGetPage(rootbuf);
/* NO ELOG(ERROR) till meta is updated */ /* NO ELOG(ERROR) till meta is updated */
START_CRIT_CODE; START_CRIT_SECTION();
metad->btm_root = rootblkno; metad->btm_root = rootblkno;
metad->btm_level = 1; metad->btm_level = 1;
...@@ -197,7 +197,7 @@ _bt_getroot(Relation rel, int access) ...@@ -197,7 +197,7 @@ _bt_getroot(Relation rel, int access)
PageSetSUI(metapg, ThisStartUpID); PageSetSUI(metapg, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
_bt_wrtnorelbuf(rel, rootbuf); _bt_wrtnorelbuf(rel, rootbuf);
...@@ -410,7 +410,7 @@ _bt_pagedel(Relation rel, ItemPointer tid) ...@@ -410,7 +410,7 @@ _bt_pagedel(Relation rel, ItemPointer tid)
buf = _bt_getbuf(rel, blkno, BT_WRITE); buf = _bt_getbuf(rel, blkno, BT_WRITE);
page = BufferGetPage(buf); page = BufferGetPage(buf);
START_CRIT_CODE; START_CRIT_SECTION();
PageIndexTupleDelete(page, offno); PageIndexTupleDelete(page, offno);
/* XLOG stuff */ /* XLOG stuff */
{ {
...@@ -435,7 +435,7 @@ _bt_pagedel(Relation rel, ItemPointer tid) ...@@ -435,7 +435,7 @@ _bt_pagedel(Relation rel, ItemPointer tid)
PageSetLSN(page, recptr); PageSetLSN(page, recptr);
PageSetSUI(page, ThisStartUpID); PageSetSUI(page, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
/* write the buffer and release the lock */ /* write the buffer and release the lock */
_bt_wrtbuf(rel, buf); _bt_wrtbuf(rel, buf);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.91 2000/12/28 13:00:08 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xact.c,v 1.92 2001/01/12 21:53:56 tgl Exp $
* *
* NOTES * NOTES
* Transaction aborts can now occur two ways: * Transaction aborts can now occur two ways:
...@@ -678,7 +678,7 @@ RecordTransactionCommit() ...@@ -678,7 +678,7 @@ RecordTransactionCommit()
rdata.len = SizeOfXactCommit; rdata.len = SizeOfXactCommit;
rdata.next = NULL; rdata.next = NULL;
START_CRIT_CODE; START_CRIT_SECTION();
/* /*
* SHOULD SAVE ARRAY OF RELFILENODE-s TO DROP * SHOULD SAVE ARRAY OF RELFILENODE-s TO DROP
*/ */
...@@ -697,7 +697,7 @@ RecordTransactionCommit() ...@@ -697,7 +697,7 @@ RecordTransactionCommit()
TransactionIdCommit(xid); TransactionIdCommit(xid);
MyProc->logRec.xrecoff = 0; MyProc->logRec.xrecoff = 0;
END_CRIT_CODE; END_CRIT_SECTION();
} }
if (leak) if (leak)
...@@ -800,12 +800,12 @@ RecordTransactionAbort(void) ...@@ -800,12 +800,12 @@ RecordTransactionAbort(void)
rdata.len = SizeOfXactAbort; rdata.len = SizeOfXactAbort;
rdata.next = NULL; rdata.next = NULL;
START_CRIT_CODE; START_CRIT_SECTION();
recptr = XLogInsert(RM_XACT_ID, XLOG_XACT_ABORT, &rdata); recptr = XLogInsert(RM_XACT_ID, XLOG_XACT_ABORT, &rdata);
TransactionIdAbort(xid); TransactionIdAbort(xid);
MyProc->logRec.xrecoff = 0; MyProc->logRec.xrecoff = 0;
END_CRIT_CODE; END_CRIT_SECTION();
} }
/* /*
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.48 2001/01/09 06:24:32 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.49 2001/01/12 21:53:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
int XLOGbuffers = 8; int XLOGbuffers = 8;
int XLOGfiles = 0; /* how many files to pre-allocate */ int XLOGfiles = 0; /* how many files to pre-allocate */
XLogRecPtr MyLastRecPtr = {0, 0}; XLogRecPtr MyLastRecPtr = {0, 0};
uint32 CritSectionCount = 0; volatile uint32 CritSectionCount = 0;
bool InRecovery = false; bool InRecovery = false;
StartUpID ThisStartUpID = 0; StartUpID ThisStartUpID = 0;
XLogRecPtr RedoRecPtr; XLogRecPtr RedoRecPtr;
...@@ -382,7 +382,7 @@ begin:; ...@@ -382,7 +382,7 @@ begin:;
if (len == 0 || len > MAXLOGRECSZ) if (len == 0 || len > MAXLOGRECSZ)
elog(STOP, "XLogInsert: invalid record len %u", len); elog(STOP, "XLogInsert: invalid record len %u", len);
START_CRIT_CODE; START_CRIT_SECTION();
/* obtain xlog insert lock */ /* obtain xlog insert lock */
if (TAS(&(XLogCtl->insert_lck))) /* busy */ if (TAS(&(XLogCtl->insert_lck))) /* busy */
...@@ -447,7 +447,7 @@ begin:; ...@@ -447,7 +447,7 @@ begin:;
if (repeat) if (repeat)
{ {
S_UNLOCK(&(XLogCtl->insert_lck)); S_UNLOCK(&(XLogCtl->insert_lck));
END_CRIT_CODE; END_CRIT_SECTION();
goto begin; goto begin;
} }
...@@ -618,7 +618,7 @@ begin:; ...@@ -618,7 +618,7 @@ begin:;
S_UNLOCK(&(XLogCtl->info_lck)); S_UNLOCK(&(XLogCtl->info_lck));
} }
END_CRIT_CODE; END_CRIT_SECTION();
return (RecPtr); return (RecPtr);
} }
...@@ -647,7 +647,7 @@ XLogFlush(XLogRecPtr record) ...@@ -647,7 +647,7 @@ XLogFlush(XLogRecPtr record)
if (XLByteLE(record, LgwrResult.Flush)) if (XLByteLE(record, LgwrResult.Flush))
return; return;
START_CRIT_CODE; START_CRIT_SECTION();
WriteRqst = LgwrRqst.Write; WriteRqst = LgwrRqst.Write;
for (;;) for (;;)
...@@ -659,7 +659,7 @@ XLogFlush(XLogRecPtr record) ...@@ -659,7 +659,7 @@ XLogFlush(XLogRecPtr record)
if (XLByteLE(record, LgwrResult.Flush)) if (XLByteLE(record, LgwrResult.Flush))
{ {
S_UNLOCK(&(XLogCtl->info_lck)); S_UNLOCK(&(XLogCtl->info_lck));
END_CRIT_CODE; END_CRIT_SECTION();
return; return;
} }
if (XLByteLT(XLogCtl->LgwrRqst.Flush, record)) if (XLByteLT(XLogCtl->LgwrRqst.Flush, record))
...@@ -705,7 +705,7 @@ XLogFlush(XLogRecPtr record) ...@@ -705,7 +705,7 @@ XLogFlush(XLogRecPtr record)
if (XLByteLE(record, LgwrResult.Flush)) if (XLByteLE(record, LgwrResult.Flush))
{ {
S_UNLOCK(&(XLogCtl->lgwr_lck)); S_UNLOCK(&(XLogCtl->lgwr_lck));
END_CRIT_CODE; END_CRIT_SECTION();
return; return;
} }
if (XLByteLT(LgwrResult.Write, WriteRqst)) if (XLByteLT(LgwrResult.Write, WriteRqst))
...@@ -715,7 +715,7 @@ XLogFlush(XLogRecPtr record) ...@@ -715,7 +715,7 @@ XLogFlush(XLogRecPtr record)
S_UNLOCK(&(XLogCtl->lgwr_lck)); S_UNLOCK(&(XLogCtl->lgwr_lck));
if (XLByteLT(LgwrResult.Flush, record)) if (XLByteLT(LgwrResult.Flush, record))
elog(STOP, "XLogFlush: request is not satisfied"); elog(STOP, "XLogFlush: request is not satisfied");
END_CRIT_CODE; END_CRIT_SECTION();
return; return;
} }
break; break;
...@@ -756,7 +756,7 @@ XLogFlush(XLogRecPtr record) ...@@ -756,7 +756,7 @@ XLogFlush(XLogRecPtr record)
S_UNLOCK(&(XLogCtl->lgwr_lck)); S_UNLOCK(&(XLogCtl->lgwr_lck));
END_CRIT_CODE; END_CRIT_SECTION();
return; return;
} }
...@@ -2081,7 +2081,7 @@ CreateCheckPoint(bool shutdown) ...@@ -2081,7 +2081,7 @@ CreateCheckPoint(bool shutdown)
if (MyLastRecPtr.xrecoff != 0) if (MyLastRecPtr.xrecoff != 0)
elog(ERROR, "CreateCheckPoint: cannot be called inside transaction block"); elog(ERROR, "CreateCheckPoint: cannot be called inside transaction block");
START_CRIT_CODE; START_CRIT_SECTION();
/* Grab lock, using larger than normal sleep between tries (1 sec) */ /* Grab lock, using larger than normal sleep between tries (1 sec) */
while (TAS(&(XLogCtl->chkp_lck))) while (TAS(&(XLogCtl->chkp_lck)))
...@@ -2230,7 +2230,7 @@ CreateCheckPoint(bool shutdown) ...@@ -2230,7 +2230,7 @@ CreateCheckPoint(bool shutdown)
S_UNLOCK(&(XLogCtl->chkp_lck)); S_UNLOCK(&(XLogCtl->chkp_lck));
MyLastRecPtr.xrecoff = 0; /* to avoid commit record */ MyLastRecPtr.xrecoff = 0; /* to avoid commit record */
END_CRIT_CODE; END_CRIT_SECTION();
return; return;
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.47 2000/12/28 13:00:17 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.48 2001/01/12 21:53:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -301,7 +301,7 @@ nextval(PG_FUNCTION_ARGS) ...@@ -301,7 +301,7 @@ nextval(PG_FUNCTION_ARGS)
elm->last = result; /* last returned number */ elm->last = result; /* last returned number */
elm->cached = last; /* last fetched number */ elm->cached = last; /* last fetched number */
START_CRIT_CODE; START_CRIT_SECTION();
if (logit) if (logit)
{ {
xl_seq_rec xlrec; xl_seq_rec xlrec;
...@@ -338,7 +338,7 @@ nextval(PG_FUNCTION_ARGS) ...@@ -338,7 +338,7 @@ nextval(PG_FUNCTION_ARGS)
seq->is_called = 't'; seq->is_called = 't';
Assert(log >= 0); Assert(log >= 0);
seq->log_cnt = log; /* how much is logged */ seq->log_cnt = log; /* how much is logged */
END_CRIT_CODE; END_CRIT_SECTION();
LockBuffer(buf, BUFFER_LOCK_UNLOCK); LockBuffer(buf, BUFFER_LOCK_UNLOCK);
...@@ -398,7 +398,7 @@ do_setval(char *seqname, int32 next, bool iscalled) ...@@ -398,7 +398,7 @@ do_setval(char *seqname, int32 next, bool iscalled)
elm->last = next; /* last returned number */ elm->last = next; /* last returned number */
elm->cached = next; /* last cached number (forget cached values) */ elm->cached = next; /* last cached number (forget cached values) */
START_CRIT_CODE; START_CRIT_SECTION();
{ {
xl_seq_rec xlrec; xl_seq_rec xlrec;
XLogRecPtr recptr; XLogRecPtr recptr;
...@@ -429,7 +429,7 @@ do_setval(char *seqname, int32 next, bool iscalled) ...@@ -429,7 +429,7 @@ do_setval(char *seqname, int32 next, bool iscalled)
seq->last_value = next; /* last fetched number */ seq->last_value = next; /* last fetched number */
seq->is_called = iscalled ? 't' : 'f'; seq->is_called = iscalled ? 't' : 'f';
seq->log_cnt = (iscalled) ? 0 : 1; seq->log_cnt = (iscalled) ? 0 : 1;
END_CRIT_CODE; END_CRIT_SECTION();
LockBuffer(buf, BUFFER_LOCK_UNLOCK); LockBuffer(buf, BUFFER_LOCK_UNLOCK);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.181 2000/12/30 15:19:55 vadim Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.182 2001/01/12 21:53:56 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1427,7 +1427,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, ...@@ -1427,7 +1427,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
Cpage = BufferGetPage(Cbuf); Cpage = BufferGetPage(Cbuf);
/* NO ELOG(ERROR) TILL CHANGES ARE LOGGED */ /* NO ELOG(ERROR) TILL CHANGES ARE LOGGED */
START_CRIT_CODE; START_CRIT_SECTION();
Citemid = PageGetItemId(Cpage, Citemid = PageGetItemId(Cpage,
ItemPointerGetOffsetNumber(&(tuple.t_self))); ItemPointerGetOffsetNumber(&(tuple.t_self)));
...@@ -1512,7 +1512,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, ...@@ -1512,7 +1512,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
PageSetLSN(ToPage, recptr); PageSetLSN(ToPage, recptr);
PageSetSUI(ToPage, ThisStartUpID); PageSetSUI(ToPage, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
if (((int) destvacpage->blkno) > last_move_dest_block) if (((int) destvacpage->blkno) > last_move_dest_block)
last_move_dest_block = destvacpage->blkno; last_move_dest_block = destvacpage->blkno;
...@@ -1637,7 +1637,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel, ...@@ -1637,7 +1637,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
newtup.t_data->t_infomask |= HEAP_MOVED_IN; newtup.t_data->t_infomask |= HEAP_MOVED_IN;
/* NO ELOG(ERROR) TILL CHANGES ARE LOGGED */ /* NO ELOG(ERROR) TILL CHANGES ARE LOGGED */
START_CRIT_CODE; START_CRIT_SECTION();
/* add tuple to the page */ /* add tuple to the page */
newoff = PageAddItem(ToPage, (Item) newtup.t_data, tuple_len, newoff = PageAddItem(ToPage, (Item) newtup.t_data, tuple_len,
...@@ -1675,7 +1675,7 @@ failed to add item with len = %lu to page %u (free space %lu, nusd %u, noff %u)" ...@@ -1675,7 +1675,7 @@ failed to add item with len = %lu to page %u (free space %lu, nusd %u, noff %u)"
PageSetLSN(ToPage, recptr); PageSetLSN(ToPage, recptr);
PageSetSUI(ToPage, ThisStartUpID); PageSetSUI(ToPage, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
cur_page->offsets_used++; cur_page->offsets_used++;
num_moved++; num_moved++;
...@@ -1905,7 +1905,7 @@ failed to add item with len = %lu to page %u (free space %lu, nusd %u, noff %u)" ...@@ -1905,7 +1905,7 @@ failed to add item with len = %lu to page %u (free space %lu, nusd %u, noff %u)"
buf = ReadBuffer(onerel, vacpage->blkno); buf = ReadBuffer(onerel, vacpage->blkno);
LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE); LockBuffer(buf, BUFFER_LOCK_EXCLUSIVE);
START_CRIT_CODE; START_CRIT_SECTION();
page = BufferGetPage(buf); page = BufferGetPage(buf);
num_tuples = 0; num_tuples = 0;
for (offnum = FirstOffsetNumber; for (offnum = FirstOffsetNumber;
...@@ -1941,7 +1941,7 @@ failed to add item with len = %lu to page %u (free space %lu, nusd %u, noff %u)" ...@@ -1941,7 +1941,7 @@ failed to add item with len = %lu to page %u (free space %lu, nusd %u, noff %u)"
PageSetLSN(page, recptr); PageSetLSN(page, recptr);
PageSetSUI(page, ThisStartUpID); PageSetSUI(page, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
LockBuffer(buf, BUFFER_LOCK_UNLOCK); LockBuffer(buf, BUFFER_LOCK_UNLOCK);
WriteBuffer(buf); WriteBuffer(buf);
} }
...@@ -2056,7 +2056,7 @@ vacuum_page(Relation onerel, Buffer buffer, VacPage vacpage) ...@@ -2056,7 +2056,7 @@ vacuum_page(Relation onerel, Buffer buffer, VacPage vacpage)
/* There shouldn't be any tuples moved onto the page yet! */ /* There shouldn't be any tuples moved onto the page yet! */
Assert(vacpage->offsets_used == 0); Assert(vacpage->offsets_used == 0);
START_CRIT_CODE; START_CRIT_SECTION();
for (i = 0; i < vacpage->offsets_free; i++) for (i = 0; i < vacpage->offsets_free; i++)
{ {
itemid = &(((PageHeader) page)->pd_linp[vacpage->offsets[i] - 1]); itemid = &(((PageHeader) page)->pd_linp[vacpage->offsets[i] - 1]);
...@@ -2070,7 +2070,7 @@ vacuum_page(Relation onerel, Buffer buffer, VacPage vacpage) ...@@ -2070,7 +2070,7 @@ vacuum_page(Relation onerel, Buffer buffer, VacPage vacpage)
PageSetLSN(page, recptr); PageSetLSN(page, recptr);
PageSetSUI(page, ThisStartUpID); PageSetSUI(page, ThisStartUpID);
} }
END_CRIT_CODE; END_CRIT_SECTION();
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.102 2001/01/08 18:31:49 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/buffer/bufmgr.c,v 1.103 2001/01/12 21:53:57 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -404,8 +404,7 @@ BufferAlloc(Relation reln, ...@@ -404,8 +404,7 @@ BufferAlloc(Relation reln,
*/ */
if ((buf->flags & BM_IO_ERROR) != 0) if ((buf->flags & BM_IO_ERROR) != 0)
{ {
PrivateRefCount[BufferDescriptorGetBuffer(buf) - 1] = 0; UnpinBuffer(buf);
buf->refcount--;
buf = (BufferDesc *) NULL; buf = (BufferDesc *) NULL;
continue; continue;
} }
...@@ -869,8 +868,10 @@ WaitIO(BufferDesc *buf, SPINLOCK spinlock) ...@@ -869,8 +868,10 @@ WaitIO(BufferDesc *buf, SPINLOCK spinlock)
while ((buf->flags & BM_IO_IN_PROGRESS) != 0) while ((buf->flags & BM_IO_IN_PROGRESS) != 0)
{ {
SpinRelease(spinlock); SpinRelease(spinlock);
START_CRIT_SECTION(); /* don't want to die() holding the lock... */
S_LOCK(&(buf->io_in_progress_lock)); S_LOCK(&(buf->io_in_progress_lock));
S_UNLOCK(&(buf->io_in_progress_lock)); S_UNLOCK(&(buf->io_in_progress_lock));
END_CRIT_SECTION();
SpinAcquire(spinlock); SpinAcquire(spinlock);
} }
} }
...@@ -921,14 +922,11 @@ ResetBufferUsage() ...@@ -921,14 +922,11 @@ ResetBufferUsage()
* ResetBufferPool * ResetBufferPool
* *
* This routine is supposed to be called when a transaction aborts. * This routine is supposed to be called when a transaction aborts.
* it will release all the buffer pins held by the transaction. * It will release all the buffer pins held by the transaction.
* Currently, we also call it during commit if BufferPoolCheckLeak * Currently, we also call it during commit if BufferPoolCheckLeak
* detected a problem --- in that case, isCommit is TRUE, and we * detected a problem --- in that case, isCommit is TRUE, and we
* only clean up buffer pin counts. * only clean up buffer pin counts.
* *
* During abort, we also forget any pending fsync requests. Dirtied buffers
* will still get written, eventually, but there will be no fsync for them.
*
* ---------------------------------------------- * ----------------------------------------------
*/ */
void void
...@@ -943,6 +941,7 @@ ResetBufferPool(bool isCommit) ...@@ -943,6 +941,7 @@ ResetBufferPool(bool isCommit)
BufferDesc *buf = &BufferDescriptors[i]; BufferDesc *buf = &BufferDescriptors[i];
SpinAcquire(BufMgrLock); SpinAcquire(BufMgrLock);
PrivateRefCount[i] = 0;
Assert(buf->refcount > 0); Assert(buf->refcount > 0);
buf->refcount--; buf->refcount--;
if (buf->refcount == 0) if (buf->refcount == 0)
...@@ -952,7 +951,6 @@ ResetBufferPool(bool isCommit) ...@@ -952,7 +951,6 @@ ResetBufferPool(bool isCommit)
} }
SpinRelease(BufMgrLock); SpinRelease(BufMgrLock);
} }
PrivateRefCount[i] = 0;
} }
ResetLocalBufferPool(); ResetLocalBufferPool();
...@@ -1900,7 +1898,7 @@ SetBufferCommitInfoNeedsSave(Buffer buffer) ...@@ -1900,7 +1898,7 @@ SetBufferCommitInfoNeedsSave(Buffer buffer)
} }
void void
UnlockBuffers() UnlockBuffers(void)
{ {
BufferDesc *buf; BufferDesc *buf;
int i; int i;
...@@ -1913,6 +1911,8 @@ UnlockBuffers() ...@@ -1913,6 +1911,8 @@ UnlockBuffers()
Assert(BufferIsValid(i + 1)); Assert(BufferIsValid(i + 1));
buf = &(BufferDescriptors[i]); buf = &(BufferDescriptors[i]);
START_CRIT_SECTION(); /* don't want to die() holding the lock... */
S_LOCK(&(buf->cntx_lock)); S_LOCK(&(buf->cntx_lock));
if (BufferLocks[i] & BL_R_LOCK) if (BufferLocks[i] & BL_R_LOCK)
...@@ -1940,6 +1940,8 @@ UnlockBuffers() ...@@ -1940,6 +1940,8 @@ UnlockBuffers()
S_UNLOCK(&(buf->cntx_lock)); S_UNLOCK(&(buf->cntx_lock));
BufferLocks[i] = 0; BufferLocks[i] = 0;
END_CRIT_SECTION();
} }
} }
...@@ -1956,6 +1958,8 @@ LockBuffer(Buffer buffer, int mode) ...@@ -1956,6 +1958,8 @@ LockBuffer(Buffer buffer, int mode)
buf = &(BufferDescriptors[buffer - 1]); buf = &(BufferDescriptors[buffer - 1]);
buflock = &(BufferLocks[buffer - 1]); buflock = &(BufferLocks[buffer - 1]);
START_CRIT_SECTION(); /* don't want to die() holding the lock... */
S_LOCK(&(buf->cntx_lock)); S_LOCK(&(buf->cntx_lock));
if (mode == BUFFER_LOCK_UNLOCK) if (mode == BUFFER_LOCK_UNLOCK)
...@@ -1979,6 +1983,7 @@ LockBuffer(Buffer buffer, int mode) ...@@ -1979,6 +1983,7 @@ LockBuffer(Buffer buffer, int mode)
else else
{ {
S_UNLOCK(&(buf->cntx_lock)); S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
elog(ERROR, "UNLockBuffer: buffer %lu is not locked", buffer); elog(ERROR, "UNLockBuffer: buffer %lu is not locked", buffer);
} }
} }
...@@ -1990,7 +1995,9 @@ LockBuffer(Buffer buffer, int mode) ...@@ -1990,7 +1995,9 @@ LockBuffer(Buffer buffer, int mode)
while (buf->ri_lock || buf->w_lock) while (buf->ri_lock || buf->w_lock)
{ {
S_UNLOCK(&(buf->cntx_lock)); S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
S_LOCK_SLEEP(&(buf->cntx_lock), i++); S_LOCK_SLEEP(&(buf->cntx_lock), i++);
START_CRIT_SECTION();
S_LOCK(&(buf->cntx_lock)); S_LOCK(&(buf->cntx_lock));
} }
(buf->r_locks)++; (buf->r_locks)++;
...@@ -2016,7 +2023,9 @@ LockBuffer(Buffer buffer, int mode) ...@@ -2016,7 +2023,9 @@ LockBuffer(Buffer buffer, int mode)
buf->ri_lock = true; buf->ri_lock = true;
} }
S_UNLOCK(&(buf->cntx_lock)); S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
S_LOCK_SLEEP(&(buf->cntx_lock), i++); S_LOCK_SLEEP(&(buf->cntx_lock), i++);
START_CRIT_SECTION();
S_LOCK(&(buf->cntx_lock)); S_LOCK(&(buf->cntx_lock));
} }
buf->w_lock = true; buf->w_lock = true;
...@@ -2038,10 +2047,12 @@ LockBuffer(Buffer buffer, int mode) ...@@ -2038,10 +2047,12 @@ LockBuffer(Buffer buffer, int mode)
else else
{ {
S_UNLOCK(&(buf->cntx_lock)); S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
elog(ERROR, "LockBuffer: unknown lock mode %d", mode); elog(ERROR, "LockBuffer: unknown lock mode %d", mode);
} }
S_UNLOCK(&(buf->cntx_lock)); S_UNLOCK(&(buf->cntx_lock));
END_CRIT_SECTION();
} }
/* /*
...@@ -2062,7 +2073,9 @@ static bool IsForInput; ...@@ -2062,7 +2073,9 @@ static bool IsForInput;
* BM_IO_IN_PROGRESS mask is not set for the buffer * BM_IO_IN_PROGRESS mask is not set for the buffer
* The buffer is Pinned * The buffer is Pinned
* *
*/ * Because BufMgrLock is held, we are already in a CRIT_SECTION here,
* and do not need another.
*/
static void static void
StartBufferIO(BufferDesc *buf, bool forInput) StartBufferIO(BufferDesc *buf, bool forInput)
{ {
...@@ -2094,7 +2107,9 @@ StartBufferIO(BufferDesc *buf, bool forInput) ...@@ -2094,7 +2107,9 @@ StartBufferIO(BufferDesc *buf, bool forInput)
* BufMgrLock is held * BufMgrLock is held
* The buffer is Pinned * The buffer is Pinned
* *
*/ * Because BufMgrLock is held, we are already in a CRIT_SECTION here,
* and do not need another.
*/
static void static void
TerminateBufferIO(BufferDesc *buf) TerminateBufferIO(BufferDesc *buf)
{ {
...@@ -2110,7 +2125,9 @@ TerminateBufferIO(BufferDesc *buf) ...@@ -2110,7 +2125,9 @@ TerminateBufferIO(BufferDesc *buf)
* BufMgrLock is held * BufMgrLock is held
* The buffer is Pinned * The buffer is Pinned
* *
*/ * Because BufMgrLock is held, we are already in a CRIT_SECTION here,
* and do not need another.
*/
static void static void
ContinueBufferIO(BufferDesc *buf, bool forInput) ContinueBufferIO(BufferDesc *buf, bool forInput)
{ {
...@@ -2132,7 +2149,7 @@ InitBufferIO(void) ...@@ -2132,7 +2149,7 @@ InitBufferIO(void)
* This function is called from ProcReleaseSpins(). * This function is called from ProcReleaseSpins().
* BufMgrLock isn't held when this function is called. * BufMgrLock isn't held when this function is called.
* *
* If I/O was in progress, BM_IO_ERROR is always set. * If I/O was in progress, we always set BM_IO_ERROR.
*/ */
void void
AbortBufferIO(void) AbortBufferIO(void)
...@@ -2141,8 +2158,8 @@ AbortBufferIO(void) ...@@ -2141,8 +2158,8 @@ AbortBufferIO(void)
if (buf) if (buf)
{ {
Assert(buf->flags & BM_IO_IN_PROGRESS);
SpinAcquire(BufMgrLock); SpinAcquire(BufMgrLock);
Assert(buf->flags & BM_IO_IN_PROGRESS);
if (IsForInput) if (IsForInput)
Assert(!(buf->flags & BM_DIRTY) && !(buf->cntxDirty)); Assert(!(buf->flags & BM_DIRTY) && !(buf->cntxDirty));
else else
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.69 2000/12/08 22:21:32 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/file/fd.c,v 1.70 2001/01/12 21:53:58 tgl Exp $
* *
* NOTES: * NOTES:
* *
...@@ -770,7 +770,11 @@ FileClose(File file) ...@@ -770,7 +770,11 @@ FileClose(File file)
* Delete the file if it was temporary * Delete the file if it was temporary
*/ */
if (VfdCache[file].fdstate & FD_TEMPORARY) if (VfdCache[file].fdstate & FD_TEMPORARY)
{
/* reset flag so that die() interrupt won't cause problems */
VfdCache[file].fdstate &= ~FD_TEMPORARY;
unlink(VfdCache[file].fileName); unlink(VfdCache[file].fileName);
}
/* /*
* Return the Vfd slot to the free list * Return the Vfd slot to the free list
...@@ -1049,7 +1053,8 @@ AllocateFile(char *name, char *mode) ...@@ -1049,7 +1053,8 @@ AllocateFile(char *name, char *mode)
TryAgain: TryAgain:
if ((file = fopen(name, mode)) != NULL) if ((file = fopen(name, mode)) != NULL)
{ {
allocatedFiles[numAllocatedFiles++] = file; allocatedFiles[numAllocatedFiles] = file;
numAllocatedFiles++;
return file; return file;
} }
...@@ -1080,7 +1085,8 @@ FreeFile(FILE *file) ...@@ -1080,7 +1085,8 @@ FreeFile(FILE *file)
{ {
if (allocatedFiles[i] == file) if (allocatedFiles[i] == file)
{ {
allocatedFiles[i] = allocatedFiles[--numAllocatedFiles]; numAllocatedFiles--;
allocatedFiles[i] = allocatedFiles[numAllocatedFiles];
break; break;
} }
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.27 2000/12/11 00:49:52 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/ipc/Attic/spin.c,v 1.28 2001/01/12 21:53:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -144,8 +144,21 @@ SpinAcquire(SPINLOCK lockid) ...@@ -144,8 +144,21 @@ SpinAcquire(SPINLOCK lockid)
SLock *slckP = &(SLockArray[lockid]); SLock *slckP = &(SLockArray[lockid]);
PRINT_SLDEBUG("SpinAcquire", lockid, slckP); PRINT_SLDEBUG("SpinAcquire", lockid, slckP);
/*
* Lock out die() until we exit the critical section protected by the
* spinlock. This ensures that die() will not interrupt manipulations
* of data structures in shared memory. We don't want die() to
* interrupt this routine between S_LOCK and PROC_INCR_SLOCK, either,
* so must do it before acquiring the lock, not after.
*/
START_CRIT_SECTION();
/*
* Acquire the lock, then record that we have done so (for recovery
* in case of elog(ERROR) during the critical section).
*/
S_LOCK(&(slckP->shlock)); S_LOCK(&(slckP->shlock));
PROC_INCR_SLOCK(lockid); PROC_INCR_SLOCK(lockid);
PRINT_SLDEBUG("SpinAcquire/done", lockid, slckP); PRINT_SLDEBUG("SpinAcquire/done", lockid, slckP);
} }
...@@ -154,15 +167,22 @@ SpinRelease(SPINLOCK lockid) ...@@ -154,15 +167,22 @@ SpinRelease(SPINLOCK lockid)
{ {
SLock *slckP = &(SLockArray[lockid]); SLock *slckP = &(SLockArray[lockid]);
PRINT_SLDEBUG("SpinRelease", lockid, slckP);
/* /*
* Check that we are actually holding the lock we are releasing. This * Check that we are actually holding the lock we are releasing. This
* can be done only after MyProc has been initialized. * can be done only after MyProc has been initialized.
*/ */
Assert(!MyProc || MyProc->sLocks[lockid] > 0); Assert(!MyProc || MyProc->sLocks[lockid] > 0);
/*
* Record that we no longer hold the spinlock, and release it.
*/
PROC_DECR_SLOCK(lockid); PROC_DECR_SLOCK(lockid);
PRINT_SLDEBUG("SpinRelease", lockid, slckP);
S_UNLOCK(&(slckP->shlock)); S_UNLOCK(&(slckP->shlock));
/*
* Exit the critical section entered in SpinAcquire().
*/
END_CRIT_SECTION();
PRINT_SLDEBUG("SpinRelease/done", lockid, slckP); PRINT_SLDEBUG("SpinRelease/done", lockid, slckP);
} }
...@@ -187,7 +207,7 @@ SpinRelease(SPINLOCK lockid) ...@@ -187,7 +207,7 @@ SpinRelease(SPINLOCK lockid)
* *
* Note that the SpinLockIds array is not in shared memory; it is filled * Note that the SpinLockIds array is not in shared memory; it is filled
* by the postmaster and then inherited through fork() by backends. This * by the postmaster and then inherited through fork() by backends. This
* is OK because its contents do not change after system startup. * is OK because its contents do not change after shmem initialization.
*/ */
#define SPINLOCKS_PER_SET PROC_NSEMS_PER_SET #define SPINLOCKS_PER_SET PROC_NSEMS_PER_SET
...@@ -285,6 +305,8 @@ SpinFreeAllSemaphores(void) ...@@ -285,6 +305,8 @@ SpinFreeAllSemaphores(void)
if (SpinLockIds[i] >= 0) if (SpinLockIds[i] >= 0)
IpcSemaphoreKill(SpinLockIds[i]); IpcSemaphoreKill(SpinLockIds[i]);
} }
free(SpinLockIds);
SpinLockIds = NULL;
} }
/* /*
...@@ -295,6 +317,8 @@ SpinFreeAllSemaphores(void) ...@@ -295,6 +317,8 @@ SpinFreeAllSemaphores(void)
void void
SpinAcquire(SPINLOCK lock) SpinAcquire(SPINLOCK lock)
{ {
/* See the TAS() version of this routine for commentary */
START_CRIT_SECTION();
IpcSemaphoreLock(SpinLockIds[0], lock); IpcSemaphoreLock(SpinLockIds[0], lock);
PROC_INCR_SLOCK(lock); PROC_INCR_SLOCK(lock);
} }
...@@ -307,15 +331,18 @@ SpinAcquire(SPINLOCK lock) ...@@ -307,15 +331,18 @@ SpinAcquire(SPINLOCK lock)
void void
SpinRelease(SPINLOCK lock) SpinRelease(SPINLOCK lock)
{ {
/* See the TAS() version of this routine for commentary */
#ifdef USE_ASSERT_CHECKING #ifdef USE_ASSERT_CHECKING
/* Check it's locked */ /* Check it's locked */
int semval; int semval;
semval = IpcSemaphoreGetValue(SpinLockIds[0], lock); semval = IpcSemaphoreGetValue(SpinLockIds[0], lock);
Assert(semval < 1); Assert(semval < 1);
Assert(!MyProc || MyProc->sLocks[lockid] > 0);
#endif #endif
PROC_DECR_SLOCK(lock); PROC_DECR_SLOCK(lock);
IpcSemaphoreUnlock(SpinLockIds[0], lock); IpcSemaphoreUnlock(SpinLockIds[0], lock);
END_CRIT_SECTION();
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.90 2001/01/09 09:38:57 inoue Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.91 2001/01/12 21:53:59 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
* This is so that we can support more backends. (system-wide semaphore * This is so that we can support more backends. (system-wide semaphore
* sets run out pretty fast.) -ay 4/95 * sets run out pretty fast.) -ay 4/95
* *
* $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.90 2001/01/09 09:38:57 inoue Exp $ * $Header: /cvsroot/pgsql/src/backend/storage/lmgr/proc.c,v 1.91 2001/01/12 21:53:59 tgl Exp $
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -241,7 +241,6 @@ InitProcess(void) ...@@ -241,7 +241,6 @@ InitProcess(void)
MemSet(MyProc->sLocks, 0, sizeof(MyProc->sLocks)); MemSet(MyProc->sLocks, 0, sizeof(MyProc->sLocks));
MyProc->sLocks[ProcStructLock] = 1; MyProc->sLocks[ProcStructLock] = 1;
if (IsUnderPostmaster) if (IsUnderPostmaster)
{ {
IpcSemaphoreId semId; IpcSemaphoreId semId;
...@@ -264,23 +263,16 @@ InitProcess(void) ...@@ -264,23 +263,16 @@ InitProcess(void)
else else
MyProc->sem.semId = -1; MyProc->sem.semId = -1;
/* ----------------------
* Release the lock.
* ----------------------
*/
SpinRelease(ProcStructLock);
MyProc->pid = MyProcPid; MyProc->pid = MyProcPid;
MyProc->databaseId = MyDatabaseId; MyProc->databaseId = MyDatabaseId;
MyProc->xid = InvalidTransactionId; MyProc->xid = InvalidTransactionId;
MyProc->xmin = InvalidTransactionId; MyProc->xmin = InvalidTransactionId;
/* ---------------- /* ----------------------
* Start keeping spin lock stats from here on. Any botch before * Release the lock.
* this initialization is forever botched * ----------------------
* ----------------
*/ */
MemSet(MyProc->sLocks, 0, MAX_SPINS * sizeof(*MyProc->sLocks)); SpinRelease(ProcStructLock);
/* ------------------------- /* -------------------------
* Install ourselves in the shmem index table. The name to * Install ourselves in the shmem index table. The name to
...@@ -412,15 +404,6 @@ ProcKill(int exitStatus, Datum pid) ...@@ -412,15 +404,6 @@ ProcKill(int exitStatus, Datum pid)
{ {
PROC *proc; PROC *proc;
/* --------------------
* If this is a FATAL exit the postmaster will have to kill all the
* existing backends and reinitialize shared memory. So we don't
* need to do anything here.
* --------------------
*/
if (exitStatus != 0)
return;
if ((int) pid == MyProcPid) if ((int) pid == MyProcPid)
{ {
proc = MyProc; proc = MyProc;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.199 2001/01/07 04:17:29 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.200 2001/01/12 21:53:59 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -982,7 +982,7 @@ die(SIGNAL_ARGS) ...@@ -982,7 +982,7 @@ die(SIGNAL_ARGS)
/* /*
* This is split out of die() so that it can be invoked later from * This is split out of die() so that it can be invoked later from
* END_CRIT_CODE. * END_CRIT_SECTION().
*/ */
void void
ForceProcDie(void) ForceProcDie(void)
...@@ -1683,7 +1683,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha ...@@ -1683,7 +1683,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[], const cha
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.199 $ $Date: 2001/01/07 04:17:29 $\n"); puts("$Revision: 1.200 $ $Date: 2001/01/12 21:53:59 $\n");
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.32 2000/12/22 23:12:07 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/cache/Attic/temprel.c,v 1.33 2001/01/12 21:54:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -263,8 +263,6 @@ AtEOXact_temp_relations(bool isCommit) ...@@ -263,8 +263,6 @@ AtEOXact_temp_relations(bool isCommit)
temp_rel->created_in_cur_xact) temp_rel->created_in_cur_xact)
{ {
/* This entry must be removed */ /* This entry must be removed */
pfree(temp_rel);
/* remove from linked list */
if (prev != NIL) if (prev != NIL)
{ {
lnext(prev) = lnext(l); lnext(prev) = lnext(l);
...@@ -277,6 +275,7 @@ AtEOXact_temp_relations(bool isCommit) ...@@ -277,6 +275,7 @@ AtEOXact_temp_relations(bool isCommit)
pfree(l); pfree(l);
l = temp_rels; l = temp_rels;
} }
pfree(temp_rel);
} }
else else
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.76 2000/12/18 00:44:48 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.77 2001/01/12 21:54:00 tgl Exp $
* *
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
...@@ -395,11 +395,12 @@ ShutdownPostgres(void) ...@@ -395,11 +395,12 @@ ShutdownPostgres(void)
* We don't want to do any inessential cleanup, since that just raises * We don't want to do any inessential cleanup, since that just raises
* the odds of failure --- but there's some stuff we need to do. * the odds of failure --- but there's some stuff we need to do.
* *
* Release any spinlocks that we may hold. This is a kluge to improve * Release any spinlocks or buffer context locks we might be holding.
* the odds that we won't get into a self-made stuck spinlock scenario * This is a kluge to improve the odds that we won't get into a self-made
* while trying to shut down. * stuck-spinlock scenario while trying to shut down.
*/ */
ProcReleaseSpins(NULL); ProcReleaseSpins(NULL);
UnlockBuffers();
/* /*
* In case a transaction is open, delete any files it created. This * In case a transaction is open, delete any files it created. This
* has to happen before bufmgr shutdown, so having smgr register a * has to happen before bufmgr shutdown, so having smgr register a
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.36 2001/01/06 21:59:39 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/mmgr/aset.c,v 1.37 2001/01/12 21:54:01 tgl Exp $
* *
* NOTE: * NOTE:
* This is a new (Feb. 05, 1999) implementation of the allocation set * This is a new (Feb. 05, 1999) implementation of the allocation set
...@@ -384,6 +384,11 @@ AllocSetReset(MemoryContext context) ...@@ -384,6 +384,11 @@ AllocSetReset(MemoryContext context)
AllocSetCheck(context); AllocSetCheck(context);
#endif #endif
/* Clear chunk freelists */
MemSet(set->freelist, 0, sizeof(set->freelist));
/* New blocks list is either empty or just the keeper block */
set->blocks = set->keeper;
while (block != NULL) while (block != NULL)
{ {
AllocBlock next = block->next; AllocBlock next = block->next;
...@@ -411,11 +416,6 @@ AllocSetReset(MemoryContext context) ...@@ -411,11 +416,6 @@ AllocSetReset(MemoryContext context)
} }
block = next; block = next;
} }
/* Now blocks list is either empty or just the keeper block */
set->blocks = set->keeper;
/* Clear chunk freelists in any case */
MemSet(set->freelist, 0, sizeof(set->freelist));
} }
/* /*
...@@ -439,6 +439,11 @@ AllocSetDelete(MemoryContext context) ...@@ -439,6 +439,11 @@ AllocSetDelete(MemoryContext context)
AllocSetCheck(context); AllocSetCheck(context);
#endif #endif
/* Make it look empty, just in case... */
MemSet(set->freelist, 0, sizeof(set->freelist));
set->blocks = NULL;
set->keeper = NULL;
while (block != NULL) while (block != NULL)
{ {
AllocBlock next = block->next; AllocBlock next = block->next;
...@@ -450,11 +455,6 @@ AllocSetDelete(MemoryContext context) ...@@ -450,11 +455,6 @@ AllocSetDelete(MemoryContext context)
free(block); free(block);
block = next; block = next;
} }
/* Make it look empty, just in case... */
set->blocks = NULL;
MemSet(set->freelist, 0, sizeof(set->freelist));
set->keeper = NULL;
} }
/* /*
...@@ -605,15 +605,16 @@ AllocSetAlloc(MemoryContext context, Size size) ...@@ -605,15 +605,16 @@ AllocSetAlloc(MemoryContext context, Size size)
} }
chunk = (AllocChunk) (block->freeptr); chunk = (AllocChunk) (block->freeptr);
block->freeptr += (availchunk + ALLOC_CHUNKHDRSZ);
availspace -= (availchunk + ALLOC_CHUNKHDRSZ);
chunk->size = availchunk; chunk->size = availchunk;
#ifdef MEMORY_CONTEXT_CHECKING #ifdef MEMORY_CONTEXT_CHECKING
chunk->requested_size = 0; /* mark it free */ chunk->requested_size = 0; /* mark it free */
#endif #endif
chunk->aset = (void *) set->freelist[a_fidx]; chunk->aset = (void *) set->freelist[a_fidx];
set->freelist[a_fidx] = chunk; set->freelist[a_fidx] = chunk;
block->freeptr += (availchunk + ALLOC_CHUNKHDRSZ);
availspace -= (availchunk + ALLOC_CHUNKHDRSZ);
} }
/* Mark that we need to create a new block */ /* Mark that we need to create a new block */
...@@ -696,6 +697,10 @@ AllocSetAlloc(MemoryContext context, Size size) ...@@ -696,6 +697,10 @@ AllocSetAlloc(MemoryContext context, Size size)
* OK, do the allocation * OK, do the allocation
*/ */
chunk = (AllocChunk) (block->freeptr); chunk = (AllocChunk) (block->freeptr);
block->freeptr += (chunk_size + ALLOC_CHUNKHDRSZ);
Assert(block->freeptr <= block->endptr);
chunk->aset = (void *) set; chunk->aset = (void *) set;
chunk->size = chunk_size; chunk->size = chunk_size;
#ifdef MEMORY_CONTEXT_CHECKING #ifdef MEMORY_CONTEXT_CHECKING
...@@ -705,9 +710,6 @@ AllocSetAlloc(MemoryContext context, Size size) ...@@ -705,9 +710,6 @@ AllocSetAlloc(MemoryContext context, Size size)
((char *) AllocChunkGetPointer(chunk))[size] = 0x7E; ((char *) AllocChunkGetPointer(chunk))[size] = 0x7E;
#endif #endif
block->freeptr += (chunk_size + ALLOC_CHUNKHDRSZ);
Assert(block->freeptr <= block->endptr);
AllocAllocInfo(set, chunk); AllocAllocInfo(set, chunk);
return AllocChunkGetPointer(chunk); return AllocChunkGetPointer(chunk);
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* PostgreSQL transaction log manager * PostgreSQL transaction log manager
* *
* $Header: /cvsroot/pgsql/src/include/access/xlog.h,v 1.15 2000/12/28 13:00:25 vadim Exp $ * $Header: /cvsroot/pgsql/src/include/access/xlog.h,v 1.16 2001/01/12 21:54:01 tgl Exp $
*/ */
#ifndef XLOG_H #ifndef XLOG_H
#define XLOG_H #define XLOG_H
...@@ -101,7 +101,7 @@ typedef XLogPageHeaderData *XLogPageHeader; ...@@ -101,7 +101,7 @@ typedef XLogPageHeaderData *XLogPageHeader;
extern StartUpID ThisStartUpID; /* current SUI */ extern StartUpID ThisStartUpID; /* current SUI */
extern bool InRecovery; extern bool InRecovery;
extern XLogRecPtr MyLastRecPtr; extern XLogRecPtr MyLastRecPtr;
extern uint32 CritSectionCount; extern volatile uint32 CritSectionCount;
typedef struct RmgrData typedef struct RmgrData
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: elog.h,v 1.22 2001/01/07 04:17:28 tgl Exp $ * $Id: elog.h,v 1.23 2001/01/12 21:54:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,16 +34,15 @@ extern int Use_syslog; ...@@ -34,16 +34,15 @@ extern int Use_syslog;
* ProcDiePending will be honored at critical section exit, * ProcDiePending will be honored at critical section exit,
* but QueryCancel is only checked at specified points. * but QueryCancel is only checked at specified points.
*/ */
extern uint32 CritSectionCount; /* duplicates access/xlog.h */ extern volatile uint32 CritSectionCount; /* duplicates access/xlog.h */
extern volatile bool ProcDiePending; extern volatile bool ProcDiePending;
extern void ForceProcDie(void); /* in postgres.c */ extern void ForceProcDie(void); /* in postgres.c */
#define START_CRIT_CODE (CritSectionCount++) #define START_CRIT_SECTION() (CritSectionCount++)
#define END_CRIT_CODE \ #define END_CRIT_SECTION() \
do { \ do { \
if (CritSectionCount == 0) \ Assert(CritSectionCount > 0); \
elog(STOP, "Not in critical section"); \
CritSectionCount--; \ CritSectionCount--; \
if (CritSectionCount == 0 && ProcDiePending) \ if (CritSectionCount == 0 && ProcDiePending) \
ForceProcDie(); \ ForceProcDie(); \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment