aboutsummaryrefslogtreecommitdiff
path: root/src/backend/storage/lmgr/s_lock.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2016-04-13 16:42:01 -0700
committerAndres Freund <andres@anarazel.de>2016-04-13 17:00:53 -0700
commit80abbeba23d466b6541cf95082a9e1f36704424e (patch)
tree088426c853cdd776344f04ede1d4a3bae9e3b29d /src/backend/storage/lmgr/s_lock.c
parent6cead413bb92be0579a2dbf6320121edcc32e369 (diff)
downloadpostgresql-80abbeba23d466b6541cf95082a9e1f36704424e.tar.gz
postgresql-80abbeba23d466b6541cf95082a9e1f36704424e.zip
Make init_spin_delay() C89 compliant and change stuck spinlock reporting.
The current definition of init_spin_delay (introduced recently in 48354581a) wasn't C89 compliant. It's not legal to refer to refer to non-constant expressions, and the ptr argument was one. This, as reported by Tom, lead to a failure on buildfarm animal pademelon. The pointer, especially on system systems with ASLR, isn't super helpful anyway, though. So instead of making init_spin_delay into an inline function, make s_lock_stuck() report the function name in addition to file:line and change init_spin_delay() accordingly. While not a direct replacement, the function name is likely more useful anyway (line numbers are often hard to interpret in third party reports). This also fixes what file/line number is reported for waits via s_lock(). As PG_FUNCNAME_MACRO is now used outside of elog.h, move it to c.h. Reported-By: Tom Lane Discussion: 4369.1460435533@sss.pgh.pa.us
Diffstat (limited to 'src/backend/storage/lmgr/s_lock.c')
-rw-r--r--src/backend/storage/lmgr/s_lock.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/backend/storage/lmgr/s_lock.c b/src/backend/storage/lmgr/s_lock.c
index 4a6ffb4f890..3902cbf2d96 100644
--- a/src/backend/storage/lmgr/s_lock.c
+++ b/src/backend/storage/lmgr/s_lock.c
@@ -70,16 +70,18 @@ static int spins_per_delay = DEFAULT_SPINS_PER_DELAY;
* s_lock_stuck() - complain about a stuck spinlock
*/
static void
-s_lock_stuck(void *p, const char *file, int line)
+s_lock_stuck(const char *file, int line, const char *func)
{
+ if (!func)
+ func = "(unknown)";
#if defined(S_LOCK_TEST)
fprintf(stderr,
- "\nStuck spinlock (%p) detected at %s:%d.\n",
- p, file, line);
+ "\nStuck spinlock detected at %s, %s:%d.\n",
+ func, file, line);
exit(1);
#else
- elog(PANIC, "stuck spinlock (%p) detected at %s:%d",
- p, file, line);
+ elog(PANIC, "stuck spinlock detected at %s, %s:%d",
+ func, file, line);
#endif
}
@@ -87,9 +89,9 @@ s_lock_stuck(void *p, const char *file, int line)
* s_lock(lock) - platform-independent portion of waiting for a spinlock.
*/
int
-s_lock(volatile slock_t *lock, const char *file, int line)
+s_lock(volatile slock_t *lock, const char *file, int line, const char *func)
{
- SpinDelayStatus delayStatus = init_spin_delay((void *) lock);
+ SpinDelayStatus delayStatus = init_spin_delay(file, line, func);
while (TAS_SPIN(lock))
{
@@ -127,7 +129,7 @@ perform_spin_delay(SpinDelayStatus *status)
if (++(status->spins) >= spins_per_delay)
{
if (++(status->delays) > NUM_DELAYS)
- s_lock_stuck(status->ptr, status->file, status->line);
+ s_lock_stuck(status->file, status->line, status->func);
if (status->cur_delay == 0) /* first time to delay? */
status->cur_delay = MIN_DELAY_USEC;