Commit 4b74c6a4 authored by Andres Freund's avatar Andres Freund

Make init_spin_delay() C89 compliant #2.

My previous attempt at doing so, in 80abbeba, 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
parent 533cd230
...@@ -4029,9 +4029,11 @@ rnode_comparator(const void *p1, const void *p2) ...@@ -4029,9 +4029,11 @@ rnode_comparator(const void *p1, const void *p2)
uint32 uint32
LockBufHdr(BufferDesc *desc) LockBufHdr(BufferDesc *desc)
{ {
SpinDelayStatus delayStatus = init_local_spin_delay(); SpinDelayStatus delayStatus;
uint32 old_buf_state; uint32 old_buf_state;
init_local_spin_delay(&delayStatus);
while (true) while (true)
{ {
/* set BM_LOCKED flag */ /* set BM_LOCKED flag */
...@@ -4055,9 +4057,11 @@ LockBufHdr(BufferDesc *desc) ...@@ -4055,9 +4057,11 @@ LockBufHdr(BufferDesc *desc)
static uint32 static uint32
WaitBufHdrUnlocked(BufferDesc *buf) WaitBufHdrUnlocked(BufferDesc *buf)
{ {
SpinDelayStatus delayStatus = init_local_spin_delay(); SpinDelayStatus delayStatus;
uint32 buf_state; uint32 buf_state;
init_local_spin_delay(&delayStatus);
buf_state = pg_atomic_read_u32(&buf->state); buf_state = pg_atomic_read_u32(&buf->state);
while (buf_state & BM_LOCKED) while (buf_state & BM_LOCKED)
......
...@@ -870,7 +870,9 @@ LWLockWaitListLock(LWLock *lock) ...@@ -870,7 +870,9 @@ LWLockWaitListLock(LWLock *lock)
/* and then spin without atomic operations until lock is released */ /* and then spin without atomic operations until lock is released */
{ {
SpinDelayStatus delayStatus = init_local_spin_delay(); SpinDelayStatus delayStatus;
init_local_spin_delay(&delayStatus);
while (old_state & LW_FLAG_LOCKED) while (old_state & LW_FLAG_LOCKED)
{ {
......
...@@ -91,7 +91,9 @@ s_lock_stuck(const char *file, int line, const char *func) ...@@ -91,7 +91,9 @@ s_lock_stuck(const char *file, int line, const char *func)
int int
s_lock(volatile slock_t *lock, const char *file, int line, const char *func) s_lock(volatile slock_t *lock, const char *file, int line, const char *func)
{ {
SpinDelayStatus delayStatus = init_spin_delay(file, line, func); SpinDelayStatus delayStatus;
init_spin_delay(&delayStatus, file, line, func);
while (TAS_SPIN(lock)) while (TAS_SPIN(lock))
{ {
......
...@@ -1005,8 +1005,19 @@ typedef struct ...@@ -1005,8 +1005,19 @@ typedef struct
const char *func; const char *func;
} SpinDelayStatus; } SpinDelayStatus;
#define init_spin_delay(file, line, func) {0, 0, 0, file, line, func} static inline void
#define init_local_spin_delay() init_spin_delay(__FILE__, __LINE__, PG_FUNCNAME_MACRO) init_spin_delay(SpinDelayStatus *status,
const char *file, int line, const char *func)
{
status->spins = 0;
status->delays = 0;
status->cur_delay = 0;
status->file = file;
status->line = line;
status->func = func;
}
#define init_local_spin_delay(status) init_spin_delay(status, __FILE__, __LINE__, PG_FUNCNAME_MACRO)
void perform_spin_delay(SpinDelayStatus *status); void perform_spin_delay(SpinDelayStatus *status);
void finish_spin_delay(SpinDelayStatus *status); void finish_spin_delay(SpinDelayStatus *status);
......
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