]> granicus.if.org Git - postgresql/commitdiff
Centralize implementation of delay code by creating a pg_usleep()
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 10 Feb 2004 03:42:45 +0000 (03:42 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 10 Feb 2004 03:42:45 +0000 (03:42 +0000)
subroutine in src/port/pgsleep.c.  Remove platform dependencies from
miscadmin.h and put them in port.h where they belong.  Extend recent
vacuum cost-based-delay patch to apply to VACUUM FULL, ANALYZE, and
non-btree index vacuuming.

By the way, where is the documentation for the cost-based-delay patch?

16 files changed:
src/Makefile.global.in
src/backend/access/gist/gist.c
src/backend/access/hash/hash.c
src/backend/access/nbtree/nbtree.c
src/backend/access/rtree/rtree.c
src/backend/access/transam/xact.c
src/backend/commands/analyze.c
src/backend/commands/vacuum.c
src/backend/commands/vacuumlazy.c
src/backend/storage/buffer/bufmgr.c
src/backend/storage/lmgr/s_lock.c
src/backend/utils/init/globals.c
src/include/commands/vacuum.h
src/include/miscadmin.h
src/include/port.h
src/port/pgsleep.c [new file with mode: 0644]

index 0a1f3fa70d0bc23660c5746d6a72ec80d6be1c01..e0d0bbfaac0f7224a155a8e389b3192118e5b172 100644 (file)
@@ -1,5 +1,5 @@
 # -*-makefile-*-
-# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.174 2004/02/02 00:11:30 momjian Exp $
+# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.175 2004/02/10 03:42:42 tgl Exp $
 
 #------------------------------------------------------------------------------
 # All PostgreSQL makefiles include this file and use the variables it sets,
@@ -339,7 +339,7 @@ endif
 #
 # substitute implementations of the C library
 
-LIBOBJS = @LIBOBJS@ path.o sprompt.o thread.o
+LIBOBJS = @LIBOBJS@ path.o pgsleep.o sprompt.o thread.o
 
 ifneq (,$(LIBOBJS))
 LIBS += -lpgport
index 65a10490d1e763fcced351e57fc6f3fdea3f3ebf..b117b33f72de197c327271e6dd0db435b9f5511c 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.107 2004/01/07 18:56:23 neilc Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/gist/gist.c,v 1.108 2004/02/10 03:42:42 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -19,6 +19,7 @@
 #include "access/gistscan.h"
 #include "access/heapam.h"
 #include "catalog/index.h"
+#include "commands/vacuum.h"
 #include "miscadmin.h"
 
 
@@ -1614,6 +1615,8 @@ gistbulkdelete(PG_FUNCTION_ARGS)
 
        while (index_getnext_indexitem(iscan, ForwardScanDirection))
        {
+               vacuum_delay_point();
+
                if (callback(&iscan->xs_ctup.t_self, callback_state))
                {
                        ItemPointerData indextup = iscan->currentItemData;
index 5ada6b34d87b6f8e2ca27d4a332d7e4f6d0d0d47..c1c3cde6fc0b91d060fc9e3d4dd8786f10bd4888 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.70 2004/01/07 18:56:23 neilc Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/hash/hash.c,v 1.71 2004/02/10 03:42:43 tgl Exp $
  *
  * NOTES
  *       This file contains only the public interface routines.
@@ -23,6 +23,7 @@
 #include "access/heapam.h"
 #include "access/xlogutils.h"
 #include "catalog/index.h"
+#include "commands/vacuum.h"
 #include "executor/executor.h"
 #include "miscadmin.h"
 
@@ -514,6 +515,8 @@ loop_top:
                        OffsetNumber maxoffno;
                        bool            page_dirty = false;
 
+                       vacuum_delay_point();
+
                        buf = _hash_getbuf(rel, blkno, HASH_WRITE);
                        page = BufferGetPage(buf);
                        _hash_checkpage(rel, page, LH_BUCKET_PAGE | LH_OVERFLOW_PAGE);
index fa77318ea3fbf97dd1806d5cbfc0232617552e79..79a69a7043f913a4651d21ab628c0a1c1c373c5c 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.112 2004/02/10 01:55:24 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/nbtree/nbtree.c,v 1.113 2004/02/10 03:42:43 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -22,6 +22,7 @@
 #include "access/heapam.h"
 #include "access/nbtree.h"
 #include "catalog/index.h"
+#include "commands/vacuum.h"
 #include "miscadmin.h"
 #include "storage/freespace.h"
 #include "storage/smgr.h"
@@ -584,27 +585,7 @@ btbulkdelete(PG_FUNCTION_ARGS)
                                                maxoff;
                        BlockNumber nextpage;
 
-                       CHECK_FOR_INTERRUPTS();
-
-                       /*
-                        * If we're called by a cost based vacuum, do the
-                        * napping in case the balance exceeded the limit.
-                        */
-                       if (VacuumCostActive && !InterruptPending &&
-                                       VacuumCostBalance >= VacuumCostLimit)
-                       {
-                               int             msec;
-
-                               msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit;
-                               if (msec < VacuumCostNaptime * 4)
-                                       PG_MSLEEP(msec);
-                               else
-                                       PG_MSLEEP(VacuumCostNaptime * 4);
-
-                               VacuumCostBalance = 0;
-
-                               CHECK_FOR_INTERRUPTS();
-                       }
+                       vacuum_delay_point();
 
                        ndeletable = 0;
                        page = BufferGetPage(buf);
index 9414e3142898cbf7c8047908b446a1e49aafad45..f713a5e7f6b60d09dbacbf904e2e5207ed769794 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/rtree/rtree.c,v 1.82 2004/01/07 18:56:24 neilc Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/rtree/rtree.c,v 1.83 2004/02/10 03:42:43 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -20,6 +20,7 @@
 #include "access/rtree.h"
 #include "access/xlogutils.h"
 #include "catalog/index.h"
+#include "commands/vacuum.h"
 #include "executor/executor.h"
 #include "miscadmin.h"
 
@@ -1219,6 +1220,8 @@ rtbulkdelete(PG_FUNCTION_ARGS)
 
        while (index_getnext_indexitem(iscan, ForwardScanDirection))
        {
+               vacuum_delay_point();
+
                if (callback(&iscan->xs_ctup.t_self, callback_state))
                {
                        ItemPointerData indextup = iscan->currentItemData;
index 06e152d1bba55263a3385a338b3207deafe02014..5aeb70f2986d424940dad9c245368a09c680069c 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.162 2004/02/10 01:55:24 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.163 2004/02/10 03:42:43 tgl Exp $
  *
  * NOTES
  *             Transaction aborts can now occur two ways:
 #include "postgres.h"
 
 #include <unistd.h>
-#include <sys/time.h>
 
 #include "access/gistscan.h"
 #include "access/hash.h"
@@ -562,7 +561,7 @@ RecordTransactionCommit(void)
                         */
                        if (CommitDelay > 0 && enableFsync &&
                                CountActiveBackends() >= CommitSiblings)
-                               PG_USLEEP(CommitDelay);
+                               pg_usleep(CommitDelay);
 
                        XLogFlush(recptr);
                }
index 09269d9187c3922bd9ec0d6a112cbdedd1262ed7..0c713b3ca678cfba5877470d4731c999bf4cb0f2 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.66 2004/01/06 18:07:31 neilc Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.67 2004/02/10 03:42:43 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -529,7 +529,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
                rows[numrows++] = heap_copytuple(tuple);
                if (numrows >= targrows)
                        break;
-               CHECK_FOR_INTERRUPTS();
+               vacuum_delay_point();
        }
        heap_endscan(scan);
 
@@ -604,7 +604,7 @@ acquire_sample_rows(Relation onerel, HeapTuple *rows, int targrows,
                OffsetNumber targoffset,
                                        maxoffset;
 
-               CHECK_FOR_INTERRUPTS();
+               vacuum_delay_point();
 
                t = select_next_random_record(t, targrows, &rstate);
                /* Try to read the t'th record in the table */
@@ -912,7 +912,7 @@ compute_minimal_stats(VacAttrStats *stats,
                int                     firstcount1,
                                        j;
 
-               CHECK_FOR_INTERRUPTS();
+               vacuum_delay_point();
 
                value = heap_getattr(tuple, stats->attnum, tupDesc, &isnull);
 
@@ -1214,7 +1214,7 @@ compute_scalar_stats(VacAttrStats *stats,
                Datum           value;
                bool            isnull;
 
-               CHECK_FOR_INTERRUPTS();
+               vacuum_delay_point();
 
                value = heap_getattr(tuple, stats->attnum, tupDesc, &isnull);
 
index 29a2df1ef1d4aee68a01632f9f402d72672d2546..a0dd09df215e835c636ab1d4847ba963c2589169 100644 (file)
@@ -13,7 +13,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.272 2004/02/10 01:55:25 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/vacuum.c,v 1.273 2004/02/10 03:42:43 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -181,6 +181,10 @@ vacuum(VacuumStmt *vacstmt)
        if (vacstmt->vacuum)
                PreventTransactionChain((void *) vacstmt, stmttype);
 
+       /* Turn vacuum cost accounting on or off */
+       VacuumCostActive = (VacuumCostNaptime > 0);
+       VacuumCostBalance = 0;
+
        /*
         * Send info about dead objects to the statistics collector
         */
@@ -374,6 +378,9 @@ vacuum(VacuumStmt *vacstmt)
 
        if (anl_context)
                MemoryContextDelete(anl_context);
+
+       /* Turn off vacuum cost accounting */
+       VacuumCostActive = false;
 }
 
 /*
@@ -1082,7 +1089,7 @@ scan_heap(VRelStats *vacrelstats, Relation onerel,
                bool            do_reap,
                                        do_frag;
 
-               CHECK_FOR_INTERRUPTS();
+               vacuum_delay_point();
 
                buf = ReadBuffer(onerel, blkno);
                page = BufferGetPage(buf);
@@ -1528,7 +1535,7 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
                 blkno > last_move_dest_block;
                 blkno--)
        {
-               CHECK_FOR_INTERRUPTS();
+               vacuum_delay_point();
 
                /*
                 * Forget fraged_pages pages at or after this one; they're no
@@ -2311,7 +2318,8 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
                 i < vacuumed_pages;
                 i++, curpage++)
        {
-               CHECK_FOR_INTERRUPTS();
+               vacuum_delay_point();
+
                Assert((*curpage)->blkno < blkno);
                if ((*curpage)->offsets_used == 0)
                {
@@ -2342,7 +2350,8 @@ repair_frag(VRelStats *vacrelstats, Relation onerel,
                 i < num_fraged_pages;
                 i++, curpage++)
        {
-               CHECK_FOR_INTERRUPTS();
+               vacuum_delay_point();
+
                Assert((*curpage)->blkno < blkno);
                if ((*curpage)->blkno > last_move_dest_block)
                        break;                          /* no need to scan any further */
@@ -2553,7 +2562,8 @@ vacuum_heap(VRelStats *vacrelstats, Relation onerel, VacPageList vacuum_pages)
 
        for (i = 0, vacpage = vacuum_pages->pagedesc; i < nblocks; i++, vacpage++)
        {
-               CHECK_FOR_INTERRUPTS();
+               vacuum_delay_point();
+
                if ((*vacpage)->offsets_free > 0)
                {
                        buf = ReadBuffer(onerel, (*vacpage)->blkno);
@@ -3164,3 +3174,34 @@ vac_show_rusage(VacRUsage *ru0)
 
        return result;
 }
+
+/*
+ * vacuum_delay_point --- check for interrupts and cost-based delay.
+ *
+ * This should be called in each major loop of VACUUM processing,
+ * typically once per page processed.
+ */
+void
+vacuum_delay_point(void)
+{
+       /* Always check for interrupts */
+       CHECK_FOR_INTERRUPTS();
+
+       /* Nap if appropriate */
+       if (VacuumCostActive && !InterruptPending &&
+               VacuumCostBalance >= VacuumCostLimit)
+       {
+               int             msec;
+
+               msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit;
+               if (msec > VacuumCostNaptime * 4)
+                       msec = VacuumCostNaptime * 4;
+
+               pg_usleep(msec * 1000L);
+
+               VacuumCostBalance = 0;
+
+               /* Might have gotten an interrupt while sleeping */
+               CHECK_FOR_INTERRUPTS();
+       }
+}
index 17f91efef7065130b6cf8f573505bf695ea579a3..2d85b65293763e1d9827910d3a5f427ca073b322 100644 (file)
@@ -31,7 +31,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.36 2004/02/10 01:55:25 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.37 2004/02/10 03:42:44 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -148,10 +148,6 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
        vac_open_indexes(onerel, &nindexes, &Irel);
        hasindex = (nindexes > 0);
 
-       /* Turn vacuum cost accounting on or off */
-       VacuumCostActive = (VacuumCostNaptime > 0);
-       VacuumCostBalance = 0;
-
        /* Do the vacuuming */
        lazy_scan_heap(onerel, vacrelstats, Irel, nindexes);
 
@@ -172,9 +168,6 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt)
        /* Update shared free space map with final free space info */
        lazy_update_fsm(onerel, vacrelstats);
 
-       /* Turn off vacuum cost accounting */
-       VacuumCostActive = false;
-
        /* Update statistics in pg_class */
        vac_update_relstats(RelationGetRelid(onerel), vacrelstats->rel_pages,
                                                vacrelstats->rel_tuples, hasindex);
@@ -233,26 +226,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
                                        hastup;
                int                     prev_dead_count;
 
-               CHECK_FOR_INTERRUPTS();
-
-               /*
-                * Do the napping in a cost based vacuum.
-                */
-               if (VacuumCostActive && !InterruptPending &&
-                               VacuumCostBalance >= VacuumCostLimit)
-               {
-                       int             msec;
-
-                       msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit;
-                       if (msec < VacuumCostNaptime * 4)
-                               PG_MSLEEP(msec);
-                       else
-                               PG_MSLEEP(VacuumCostNaptime * 4);
-
-                       VacuumCostBalance = 0;
-
-                       CHECK_FOR_INTERRUPTS();
-               }
+               vacuum_delay_point();
 
                /*
                 * If we are close to overrunning the available space for
@@ -493,26 +467,7 @@ lazy_vacuum_heap(Relation onerel, LVRelStats *vacrelstats)
                Buffer          buf;
                Page            page;
 
-               CHECK_FOR_INTERRUPTS();
-
-               /*
-                * Do the napping in a cost based vacuum.
-                */
-               if (VacuumCostActive && !InterruptPending &&
-                               VacuumCostBalance >= VacuumCostLimit)
-               {
-                       int             msec;
-
-                       msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit;
-                       if (msec < VacuumCostNaptime * 4)
-                               PG_MSLEEP(msec);
-                       else
-                               PG_MSLEEP(VacuumCostNaptime * 4);
-
-                       VacuumCostBalance = 0;
-
-                       CHECK_FOR_INTERRUPTS();
-               }
+               vacuum_delay_point();
 
                tblk = ItemPointerGetBlockNumber(&vacrelstats->dead_tuples[tupindex]);
                buf = ReadBuffer(onerel, tblk);
@@ -845,26 +800,7 @@ count_nondeletable_pages(Relation onerel, LVRelStats *vacrelstats)
                                        tupgone,
                                        hastup;
 
-               CHECK_FOR_INTERRUPTS();
-
-               /*
-                * Do the napping in a cost based vacuum.
-                */
-               if (VacuumCostActive && !InterruptPending &&
-                               VacuumCostBalance >= VacuumCostLimit)
-               {
-                       int             msec;
-
-                       msec = VacuumCostNaptime * VacuumCostBalance / VacuumCostLimit;
-                       if (msec < VacuumCostNaptime * 4)
-                               PG_MSLEEP(msec);
-                       else
-                               PG_MSLEEP(VacuumCostNaptime * 4);
-
-                       VacuumCostBalance = 0;
-
-                       CHECK_FOR_INTERRUPTS();
-               }
+               vacuum_delay_point();
 
                blkno--;
 
index 203e03ab059b094aca730f3df3fa0d2c569c7952..0ad26ee4f0be2aeae73400caf908236dbde2a4de 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.157 2004/02/10 01:55:25 tgl Exp $
+ *       $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.158 2004/02/10 03:42:45 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -44,7 +44,6 @@
 #include <math.h>
 #include <signal.h>
 #include <sys/file.h>
-#include <sys/time.h>
 #include <unistd.h>
 
 #include "lib/stringinfo.h"
@@ -972,7 +971,7 @@ BufferBackgroundWriter(void)
                 * Nap for the configured time or sleep for 10 seconds if
                 * there was nothing to do at all.
                 */
-               PG_USLEEP((n > 0) ? BgWriterDelay * 1000 : 10000000);
+               pg_usleep((n > 0) ? BgWriterDelay * 1000L : 10000000L);
        }
 }
 
index 85d1a16516ac9c38635b27617ca5a8ea2f555100..dcbf210519b8a7fe76065bab8255b335a95a446e 100644 (file)
@@ -9,13 +9,12 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.24 2004/01/09 21:08:49 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.25 2004/02/10 03:42:45 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
 #include "postgres.h"
 
-#include <sys/time.h>
 #include <unistd.h>
 
 #include "storage/s_lock.h"
@@ -96,7 +95,7 @@ s_lock(volatile slock_t *lock, const char *file, int line)
                        if (++delays > NUM_DELAYS)
                                s_lock_stuck(lock, file, line);
 
-                       PG_USLEEP(cur_delay * 10000);
+                       pg_usleep(cur_delay * 10000L);
 
 #if defined(S_LOCK_TEST)
                        fprintf(stdout, "*");
index f916d013d1c129a0812bf0924395bcef96fd1a88..8bcf48b2f2780e95d966012e78b7742fd87cfd8a 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.83 2004/02/06 19:36:18 wieck Exp $
+ *       $PostgreSQL: pgsql/src/backend/utils/init/globals.c,v 1.84 2004/02/10 03:42:45 tgl Exp $
  *
  * NOTES
  *       Globals used all over the place should be declared here and not
@@ -82,10 +82,11 @@ int                 work_mem = 1024;
 int                    maintenance_work_mem = 16384;
 int                    NBuffers = 1000;
 
-int                    VacuumCostPageHit = 1;
+int                    VacuumCostPageHit = 1;                  /* GUC parameters for vacuum */
 int                    VacuumCostPageMiss = 10;
 int                    VacuumCostPageDirty = 20;
 int                    VacuumCostLimit = 200;
-int                    VacuumCostBalance = 0;
 int                    VacuumCostNaptime = 0;
+
+int                    VacuumCostBalance = 0;                  /* working state for vacuum */
 bool           VacuumCostActive = false;
index e93942fd2565d79d2a262aaa4a7f661c4b321a63..61985b0d395b53078b73aef5f5762d3ec5f77033 100644 (file)
@@ -7,7 +7,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.47 2003/11/29 22:40:59 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/commands/vacuum.h,v 1.48 2004/02/10 03:42:45 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -53,6 +53,7 @@ extern void vacuum_set_xid_limits(VacuumStmt *vacstmt, bool sharedRel,
 extern bool vac_is_partial_index(Relation indrel);
 extern void vac_init_rusage(VacRUsage *ru0);
 extern const char *vac_show_rusage(VacRUsage *ru0);
+extern void vacuum_delay_point(void);
 
 /* in commands/vacuumlazy.c */
 extern void lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt);
index 7e9a209331ecfe45689973e61b4a237e3b9dd3f0..b43d481c52aa372b739de3c1f466fda063090003 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.152 2004/02/08 22:28:57 neilc Exp $
+ * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.153 2004/02/10 03:42:45 tgl Exp $
  *
  * NOTES
  *       some of the information in this file should be moved to
@@ -24,7 +24,6 @@
 #define MISCADMIN_H
 
 
-
 /*****************************************************************************
  *       System interrupt and critical section handling
  *
@@ -83,10 +82,10 @@ do { \
 #else
 #define CHECK_FOR_INTERRUPTS() \
 do { \
-       WaitForSingleObjectEx(GetCurrentThread(),0,TRUE);       \
+       WaitForSingleObjectEx(GetCurrentThread(),0,TRUE); \
        if (InterruptPending) \
                ProcessInterrupts(); \
-} while (0)
+} while(0)
 #endif
 
 
@@ -106,34 +105,6 @@ do { \
        CritSectionCount--; \
 } while(0)
 
-#ifndef WIN32
-#define PG_USLEEP(_usec) \
-do { \
-       /* This will overflow on systems with 32-bit ints for > ~2000 secs */ \
-       struct timeval delay; \
-       \
-       delay.tv_sec = (_usec) / 1000000; \
-       delay.tv_usec = ((_usec) % 1000000); \
-       (void) select(0, NULL, NULL, NULL, &delay); \
-} while(0)
-#define PG_MSLEEP(_msec) \
-do { \
-       struct timeval _delay; \
-       _delay.tv_sec = (_msec) / 1000; \
-       _delay.tv_usec = ((_msec) % 1000) * 1000; \
-       (void) select (0, NULL, NULL, NULL, &_delay); \
-} while(0)
-#else
-#define PG_USLEEP(_usec) \
-do { \
-       SleepEx(((_usec) < 500 ? 1 : ((_usec) + 500) / 1000), TRUE); \
-} while(0)
-#define PG_MSLEEP(_msec) PG_USLEEP((_msec) * 1000)
-#endif
-
-#ifdef WIN32
-#define ftruncate(a,b) chsize(a,b)
-#endif
 
 /*****************************************************************************
  *       globals.h --                                                                                                                   *
@@ -227,14 +198,14 @@ extern bool enableFsync;
 extern bool allowSystemTableMods;
 extern DLLIMPORT int work_mem;
 extern DLLIMPORT int maintenance_work_mem;
-extern int     VacuumMem;
 
 extern int     VacuumCostPageHit;
 extern int     VacuumCostPageMiss;
 extern int     VacuumCostPageDirty;
 extern int     VacuumCostLimit;
-extern int     VacuumCostBalance;
 extern int     VacuumCostNaptime;
+
+extern int     VacuumCostBalance;
 extern bool    VacuumCostActive;
 
 /*
index a885e91424de546bfbf5d470d569c0c01e6506ef..40ccc8a6d22e48a1e7722847799c0a0418e5c31a 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/port.h,v 1.18 2004/02/02 22:20:33 momjian Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.19 2004/02/10 03:42:45 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -23,6 +23,10 @@ extern char *first_path_separator(const char *filename);
 extern char *last_path_separator(const char *filename);
 extern char *get_progname(char *argv0);
 
+/* Portable delay handling */
+extern void pg_usleep(long microsec);
+
+/* Portable prompt handling */
 extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
 
 #if defined(bsdi) || defined(netbsd)
@@ -138,6 +142,7 @@ extern int pqGethostbyname(const char *name,
 #ifdef WIN32
 #define fsync(a)       _commit(a)
 #define sync()         _flushall()
+#define ftruncate(a,b) chsize(a,b)
 #define WEXITSTATUS(w)  (((w) >> 8) & 0xff)
 #define WIFEXITED(w)    (((w) & 0xff) == 0)
 #define WIFSIGNALED(w)  (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
diff --git a/src/port/pgsleep.c b/src/port/pgsleep.c
new file mode 100644 (file)
index 0000000..52ea860
--- /dev/null
@@ -0,0 +1,42 @@
+/*-------------------------------------------------------------------------
+ *
+ * pgsleep.c
+ *        Portable delay handling.
+ *
+ *
+ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
+ *
+ * $PostgreSQL: pgsql/src/port/pgsleep.c,v 1.1 2004/02/10 03:42:45 tgl Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include <sys/time.h>
+
+
+/*
+ * pg_usleep --- delay the specified number of microseconds.
+ *
+ * NOTE: although the delay is specified in microseconds, the effective
+ * resolution is only 1/HZ, or 10 milliseconds, on most Unixen.  Expect
+ * the requested delay to be rounded up to the next resolution boundary.
+ *
+ * On machines where "long" is 32 bits, the maximum delay is ~2000 seconds.
+ */
+void
+pg_usleep(long microsec)
+{
+       if (microsec > 0)
+       {
+#ifndef WIN32
+               struct timeval delay;
+
+               delay.tv_sec = microsec / 1000000L;
+               delay.tv_usec = microsec % 1000000L;
+               (void) select(0, NULL, NULL, NULL, &delay);
+#else
+               SleepEx((microsec < 500 ? 1 : (microsec + 500) / 1000), TRUE);
+#endif
+       }
+}