Commit 84a0cffa authored by Geoff Simmons's avatar Geoff Simmons

If available, tell pthread_rwlock to avoid writer starvation.

Changes in the keys are expected to be rare compared to key reads.
But when there are changes, they should be executed urgently (a
key may need to be changed because it has been compromised).
parent b5d01d9c
......@@ -50,6 +50,7 @@ AC_SUBST([VARNISH_LIBRARY_PATH],
[$LIBVARNISHAPI_LIBDIR:$LIBVARNISHAPI_LIBDIR/varnish])
# Checks for C sources
AC_CHECK_FUNCS([pthread_rwlockattr_setkind_np])
# --enable-set-salt
AC_ARG_ENABLE(set-salt,
......
......@@ -28,8 +28,8 @@
#include "config.h"
// for pthread_rwlock_* and posix_memalign()
#define _POSIX_C_SOURCE 200112L
// for pthread_rwlock_* (including _setkind_np) and posix_memalign()
#define _POSIX_C_SOURCE 200809L
#include <pthread.h>
#include <unistd.h>
......@@ -161,6 +161,17 @@ KEY_Init(VRT_CTX)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
#ifdef HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP
/* If we can, tell pthread_rwlock to prevent writer starvation. */
pthread_rwlockattr_t lock_attr;
AZ(pthread_rwlockattr_init(&lock_attr));
AZ(pthread_rwlockattr_setkind_np(&lock_attr,
PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP));
# define LOCK_ATTR (&lock_attr)
#else
# define LOCK_ATTR (NULL)
#endif
errno = 0;
pagesz = sysconf(_SC_PAGESIZE);
if (pagesz < 1) {
......@@ -187,7 +198,7 @@ KEY_Init(VRT_CTX)
for (unsigned i = 0; i < UINT8_MAX; i++) {
VRBT_INIT(&key_tbl[i].tree);
AZ(pthread_rwlock_init(&key_tbl[i].lock, NULL));
AZ(pthread_rwlock_init(&key_tbl[i].lock, LOCK_ATTR));
}
return (0);
}
......
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