Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

matcher_check default_when_unstarted to avoid race

  • Loading branch information...
commit 718cde2c554c511d1141d4df7447084f5ecfaf39 1 parent a9d6d83
@steveyen steveyen authored
View
8 cproxy_front.c
@@ -134,8 +134,7 @@ void mcache_stop(mcache *m) {
if (m->lock)
pthread_mutex_lock(m->lock);
- if (m->map != NULL)
- g_hash_table_destroy(m->map);
+ GHashTable *x = m->map;
m->map = NULL;
m->max = 0;
@@ -145,6 +144,11 @@ void mcache_stop(mcache *m) {
if (m->lock)
pthread_mutex_unlock(m->lock);
+
+ // Destroying hash table outside the lock.
+ //
+ if (x != NULL)
+ g_hash_table_destroy(x);
}
void *mcache_get(mcache *m, char *key, int key_len,
View
10 cproxy_multiget.c
@@ -356,12 +356,10 @@ void multiget_ascii_downstream_response(downstream *d, item *it) {
pthread_mutex_unlock(&p->proxy_lock);
if (front_cache_lifespan > 0) {
- if ((matcher_started(&p->front_cache_matcher) == false ||
- matcher_check(&p->front_cache_matcher,
- ITEM_key(it), it->nkey) == true) &&
- (matcher_started(&p->front_cache_unmatcher) == false ||
- matcher_check(&p->front_cache_unmatcher,
- ITEM_key(it), it->nkey) == false)) {
+ if (matcher_check(&p->front_cache_matcher,
+ ITEM_key(it), it->nkey, true) == true &&
+ matcher_check(&p->front_cache_unmatcher,
+ ITEM_key(it), it->nkey, true) == false) {
mcache_add(&p->front_cache, it,
front_cache_lifespan + msec_current_time);
}
View
5 cproxy_protocol.c
@@ -359,9 +359,8 @@ bool cproxy_optimize_set_ascii(downstream *d, conn *uc,
assert(uc);
assert(uc->next == NULL);
- if (matcher_started(&d->ptd->proxy->optimize_set_matcher) &&
- matcher_check(&d->ptd->proxy->optimize_set_matcher,
- key, key_len)) {
+ if (matcher_check(&d->ptd->proxy->optimize_set_matcher,
+ key, key_len, false)) {
d->upstream_conn = NULL;
d->upstream_suffix = NULL;
View
40 matcher.c
@@ -141,9 +141,9 @@ matcher *matcher_clone(matcher *m, matcher *copy) {
return NULL;
}
+/** Assuming caller has m->lock already.
+ */
void matcher_add(matcher *m, char *pattern) {
- // Assuming caller has m->lock already.
- //
assert(m);
assert(m->patterns_num <= m->patterns_max);
assert(pattern);
@@ -182,7 +182,8 @@ void matcher_add(matcher *m, char *pattern) {
}
}
-bool matcher_check(matcher *m, char *str, int str_len) {
+bool matcher_check(matcher *m, char *str, int str_len,
+ bool default_when_unstarted) {
assert(m);
bool found = false;
@@ -190,24 +191,29 @@ bool matcher_check(matcher *m, char *str, int str_len) {
if (m->lock)
pthread_mutex_lock(m->lock);
- assert(m->patterns_num <= m->patterns_max);
-
- for (int i = 0; i < m->patterns_num; i++) {
- assert(m->patterns);
- assert(m->lengths);
- assert(m->hits);
+ if (m->patterns != NULL &&
+ m->patterns_num > 0) {
+ assert(m->patterns_num <= m->patterns_max);
- int n = m->lengths[i];
- if (n <= str_len) {
- if (strncmp(str, m->patterns[i], n) == 0) {
- m->hits[i]++;
- found = true;
+ for (int i = 0; i < m->patterns_num; i++) {
+ assert(m->patterns);
+ assert(m->lengths);
+ assert(m->hits);
+
+ int n = m->lengths[i];
+ if (n <= str_len) {
+ if (strncmp(str, m->patterns[i], n) == 0) {
+ m->hits[i]++;
+ found = true;
+ }
}
}
- }
- if (!found)
- m->misses++;
+ if (!found)
+ m->misses++;
+ } else {
+ found = default_when_unstarted;
+ }
if (m->lock)
pthread_mutex_unlock(m->lock);
View
3  matcher.h
@@ -29,7 +29,8 @@ void matcher_start(matcher *m, char *spec);
bool matcher_started(matcher *m);
void matcher_stop(matcher *m);
matcher *matcher_clone(matcher *m, matcher *copy);
-bool matcher_check(matcher *m, char *str, int str_len);
+bool matcher_check(matcher *m, char *str, int str_len,
+ bool default_when_unstarted);
#endif /* MATCHER_H */
Please sign in to comment.
Something went wrong with that request. Please try again.