1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-13 16:22:44 +03:00

Change the spinlock primitives to function as compiler barriers.

Previously, they functioned as barriers against CPU reordering but not
compiler reordering, an odd API that required extensive use of volatile
everywhere that spinlocks are used.  That's error-prone and has negative
implications for performance, so change it.

In theory, this makes it safe to remove many of the uses of volatile
that we currently have in our code base, but we may find that there are
some bugs in this effort when we do.  In the long run, though, this
should make for much more maintainable code.

Patch by me.  Review by Andres Freund.
This commit is contained in:
Robert Haas
2014-09-09 17:45:20 -04:00
parent e80252d424
commit 0709b7ee72
2 changed files with 79 additions and 16 deletions

View File

@@ -154,6 +154,18 @@ s_lock(volatile slock_t *lock, const char *file, int line)
return delays;
}
#ifdef USE_DEFAULT_S_UNLOCK
void
s_unlock(slock_t *lock)
{
#ifdef TAS_ACTIVE_WORD
/* HP's PA-RISC */
*TAS_ACTIVE_WORD(lock) = -1;
#else
*lock = 0;
#endif
}
#endif
/*
* Set local copy of spins_per_delay during backend startup.