Skip to content

Commit 38081fd

Browse files
committed
Change PG_DELAY from msec to usec and use it consistenly rather than
select(). Add Win32 Sleep() for delay.
1 parent a76c86c commit 38081fd

File tree

4 files changed

+32
-37
lines changed

4 files changed

+32
-37
lines changed

src/backend/access/transam/xact.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.159 2004/01/07 18:56:24 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/transam/xact.c,v 1.160 2004/01/09 21:08:46 momjian Exp $
1212
*
1313
* NOTES
1414
* Transaction aborts can now occur two ways:
@@ -561,13 +561,7 @@ RecordTransactionCommit(void)
561561
*/
562562
if (CommitDelay > 0 && enableFsync &&
563563
CountActiveBackends() >= CommitSiblings)
564-
{
565-
struct timeval delay;
566-
567-
delay.tv_sec = 0;
568-
delay.tv_usec = CommitDelay;
569-
(void) select(0, NULL, NULL, NULL, &delay);
570-
}
564+
PG_USLEEP(CommitDelay);
571565

572566
XLogFlush(recptr);
573567
}

src/backend/storage/buffer/bufmgr.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.151 2004/01/07 18:56:27 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/buffer/bufmgr.c,v 1.152 2004/01/09 21:08:49 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1031,9 +1031,7 @@ BufferBackgroundWriter(void)
10311031
* there was nothing to do at all.
10321032
*/
10331033
if (n > 0)
1034-
{
1035-
PG_DELAY(BgWriterDelay);
1036-
}
1034+
PG_USLEEP(BgWriterDelay * 1000);
10371035
else
10381036
sleep(10);
10391037
}

src/backend/storage/lmgr/s_lock.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.23 2003/12/27 20:58:58 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/storage/lmgr/s_lock.c,v 1.24 2004/01/09 21:08:49 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -19,7 +19,7 @@
1919
#include <unistd.h>
2020

2121
#include "storage/s_lock.h"
22-
22+
#include "miscadmin.h"
2323

2424
/*
2525
* s_lock_stuck() - complain about a stuck spinlock
@@ -84,7 +84,6 @@ s_lock(volatile slock_t *lock, const char *file, int line)
8484
int spins = 0;
8585
int delays = 0;
8686
int cur_delay = MIN_DELAY_CSEC;
87-
struct timeval delay;
8887

8988
while (TAS(lock))
9089
{
@@ -97,9 +96,7 @@ s_lock(volatile slock_t *lock, const char *file, int line)
9796
if (++delays > NUM_DELAYS)
9897
s_lock_stuck(lock, file, line);
9998

100-
delay.tv_sec = cur_delay / 100;
101-
delay.tv_usec = (cur_delay % 100) * 10000;
102-
(void) select(0, NULL, NULL, NULL, &delay);
99+
PG_USLEEP(cur_delay * 10000);
103100

104101
#if defined(S_LOCK_TEST)
105102
fprintf(stdout, "*");

src/include/miscadmin.h

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.142 2004/01/06 23:15:22 momjian Exp $
15+
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.143 2004/01/09 21:08:50 momjian Exp $
1616
*
1717
* NOTES
1818
* some of the information in this file should be moved to
@@ -75,34 +75,40 @@ extern volatile uint32 CritSectionCount;
7575
extern void ProcessInterrupts(void);
7676

7777
#define CHECK_FOR_INTERRUPTS() \
78-
do { \
79-
if (InterruptPending) \
80-
ProcessInterrupts(); \
81-
} while(0)
78+
do { \
79+
if (InterruptPending) \
80+
ProcessInterrupts(); \
81+
} while(0)
8282

8383
#define HOLD_INTERRUPTS() (InterruptHoldoffCount++)
8484

8585
#define RESUME_INTERRUPTS() \
86-
do { \
87-
Assert(InterruptHoldoffCount > 0); \
88-
InterruptHoldoffCount--; \
89-
} while(0)
86+
do { \
87+
Assert(InterruptHoldoffCount > 0); \
88+
InterruptHoldoffCount--; \
89+
} while(0)
9090

9191
#define START_CRIT_SECTION() (CritSectionCount++)
9292

9393
#define END_CRIT_SECTION() \
94-
do { \
95-
Assert(CritSectionCount > 0); \
96-
CritSectionCount--; \
97-
} while(0)
98-
99-
#define PG_DELAY(_msec) \
100-
{ \
94+
do { \
95+
Assert(CritSectionCount > 0); \
96+
CritSectionCount--; \
97+
} while(0)
98+
99+
#define PG_USLEEP(_usec) \
100+
do { \
101+
#ifndef WIN32
102+
/* This will overflow on systems with 32-bit ints for > ~2000 secs */ \
101103
struct timeval delay; \
102-
delay.tv_sec = (_msec) / 1000; \
103-
delay.tv_usec = ((_msec) % 1000) * 1000; \
104+
\
105+
delay.tv_sec = (_usec) / 1000000; \
106+
delay.tv_usec = ((_usec) % 1000000); \
104107
(void) select(0, NULL, NULL, NULL, &delay); \
105-
}
108+
#else
109+
Sleep(_usec < 500) ? 1 : (_usec+500)/ 1000);
110+
#endif
111+
} while(0)
106112

107113
/*****************************************************************************
108114
* globals.h -- *

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy