[master] 6f360c9 Non volatile reads/writes use the temperature lock
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Fri Sep 9 18:50:16 CEST 2016
commit 6f360c9f652a30a5964fef52ad9fe043498b5b05
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Tue Aug 30 22:02:46 2016 +0200
Non volatile reads/writes use the temperature lock
Acquiring a read lock on the CLI thread is unnecessary since a write
lock may only be acquired on that very thread.
The locking order when both are required is:
(struct vcl).temp_rwl => vcl_mtx
Fixes #2008
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index e5bb70e..85e3c5b 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -184,7 +184,9 @@ vcl_get(struct vcl **vcc, struct vcl *vcl)
{
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+ AZ(pthread_rwlock_rdlock(&vcl->temp_rwl));
assert(VCL_WARM(vcl));
+ AZ(pthread_rwlock_unlock(&vcl->temp_rwl));
Lck_Lock(&vcl_mtx);
AN(vcl);
if (vcl->label == NULL)
@@ -212,7 +214,9 @@ void
VCL_Refresh(struct vcl **vcc)
{
CHECK_OBJ_NOTNULL(vcl_active, VCL_MAGIC);
+ AZ(pthread_rwlock_rdlock(&vcl_active->temp_rwl));
assert(VCL_WARM(vcl_active));
+ AZ(pthread_rwlock_unlock(&vcl_active->temp_rwl));
if (*vcc == vcl_active)
return;
if (*vcc != NULL)
@@ -225,7 +229,9 @@ VCL_Ref(struct vcl *vcl)
{
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
+ AZ(pthread_rwlock_rdlock(&vcl->temp_rwl));
assert(!VCL_COLD(vcl));
+ AZ(pthread_rwlock_unlock(&vcl->temp_rwl));
Lck_Lock(&vcl_mtx);
assert(vcl->busy > 0);
vcl->busy++;
@@ -261,8 +267,11 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be)
CHECK_OBJ_NOTNULL(vcl, VCL_MAGIC);
CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
- if (vcl->temp == VCL_TEMP_COOLING)
+ AZ(pthread_rwlock_rdlock(&vcl->temp_rwl));
+ if (vcl->temp == VCL_TEMP_COOLING) {
+ AZ(pthread_rwlock_unlock(&vcl->temp_rwl));
return (1);
+ }
Lck_Lock(&vcl_mtx);
VTAILQ_INSERT_TAIL(&vcl->backend_list, be, vcl_list);
@@ -273,6 +282,7 @@ VCL_AddBackend(struct vcl *vcl, struct backend *be)
VBE_Event(be, VCL_EVENT_WARM);
else if (vcl->temp != VCL_TEMP_INIT)
WRONG("Dynamic Backends can only be added to warm VCLs");
+ AZ(pthread_rwlock_unlock(&vcl->temp_rwl));
return (0);
}
@@ -288,8 +298,11 @@ VCL_DelBackend(struct backend *be)
Lck_Lock(&vcl_mtx);
VTAILQ_REMOVE(&vcl->backend_list, be, vcl_list);
Lck_Unlock(&vcl_mtx);
- if (vcl->temp == VCL_TEMP_WARM)
+
+ AZ(pthread_rwlock_rdlock(&vcl->temp_rwl));
+ if (VCL_WARM(vcl))
VBE_Event(be, VCL_EVENT_COLD);
+ AZ(pthread_rwlock_unlock(&vcl->temp_rwl));
}
static void
@@ -627,6 +640,7 @@ vcl_set_state(struct vrt_ctx *ctx, const char *state)
assert(ctx->msg != NULL || *state == '0');
vcl = ctx->vcl;
+ AZ(pthread_rwlock_wrlock(&vcl->temp_rwl));
AN(vcl->temp);
switch(state[0]) {
@@ -668,6 +682,8 @@ vcl_set_state(struct vrt_ctx *ctx, const char *state)
default:
WRONG("Wrong enum state");
}
+ AZ(pthread_rwlock_unlock(&vcl->temp_rwl));
+
return (i);
}
More information about the varnish-commit
mailing list