Skip to content

Commit 4b74c6a

Browse files
committed
Make init_spin_delay() C89 compliant #2.
My previous attempt at doing so, in 80abbeb, was not sufficient. While that fixed the problem for bufmgr.c and lwlock.c , s_lock.c still has non-constant expressions in the struct initializer, because the file/line/function information comes from the caller of s_lock(). Give up on using a macro, and use a static inline instead. Discussion: 4369.1460435533@sss.pgh.pa.us
1 parent 533cd23 commit 4b74c6a

File tree

4 files changed

+25
-6
lines changed

4 files changed

+25
-6
lines changed

src/backend/storage/buffer/bufmgr.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4029,9 +4029,11 @@ rnode_comparator(const void *p1, const void *p2)
40294029
uint32
40304030
LockBufHdr(BufferDesc *desc)
40314031
{
4032-
SpinDelayStatus delayStatus = init_local_spin_delay();
4032+
SpinDelayStatus delayStatus;
40334033
uint32 old_buf_state;
40344034

4035+
init_local_spin_delay(&delayStatus);
4036+
40354037
while (true)
40364038
{
40374039
/* set BM_LOCKED flag */
@@ -4055,9 +4057,11 @@ LockBufHdr(BufferDesc *desc)
40554057
static uint32
40564058
WaitBufHdrUnlocked(BufferDesc *buf)
40574059
{
4058-
SpinDelayStatus delayStatus = init_local_spin_delay();
4060+
SpinDelayStatus delayStatus;
40594061
uint32 buf_state;
40604062

4063+
init_local_spin_delay(&delayStatus);
4064+
40614065
buf_state = pg_atomic_read_u32(&buf->state);
40624066

40634067
while (buf_state & BM_LOCKED)

src/backend/storage/lmgr/lwlock.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,9 @@ LWLockWaitListLock(LWLock *lock)
870870

871871
/* and then spin without atomic operations until lock is released */
872872
{
873-
SpinDelayStatus delayStatus = init_local_spin_delay();
873+
SpinDelayStatus delayStatus;
874+
875+
init_local_spin_delay(&delayStatus);
874876

875877
while (old_state & LW_FLAG_LOCKED)
876878
{

src/backend/storage/lmgr/s_lock.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ s_lock_stuck(const char *file, int line, const char *func)
9191
int
9292
s_lock(volatile slock_t *lock, const char *file, int line, const char *func)
9393
{
94-
SpinDelayStatus delayStatus = init_spin_delay(file, line, func);
94+
SpinDelayStatus delayStatus;
95+
96+
init_spin_delay(&delayStatus, file, line, func);
9597

9698
while (TAS_SPIN(lock))
9799
{

src/include/storage/s_lock.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,8 +1005,19 @@ typedef struct
10051005
const char *func;
10061006
} SpinDelayStatus;
10071007

1008-
#define init_spin_delay(file, line, func) {0, 0, 0, file, line, func}
1009-
#define init_local_spin_delay() init_spin_delay(__FILE__, __LINE__, PG_FUNCNAME_MACRO)
1008+
static inline void
1009+
init_spin_delay(SpinDelayStatus *status,
1010+
const char *file, int line, const char *func)
1011+
{
1012+
status->spins = 0;
1013+
status->delays = 0;
1014+
status->cur_delay = 0;
1015+
status->file = file;
1016+
status->line = line;
1017+
status->func = func;
1018+
}
1019+
1020+
#define init_local_spin_delay(status) init_spin_delay(status, __FILE__, __LINE__, PG_FUNCNAME_MACRO)
10101021
void perform_spin_delay(SpinDelayStatus *status);
10111022
void finish_spin_delay(SpinDelayStatus *status);
10121023

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