This is an automated email from the ASF dual-hosted git repository. bcall pushed a commit to branch 8.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit 3f3b54fe9be3dfedf4185b181602487aef27fd4e Author: Randall Meyer <r...@apache.org> AuthorDate: Wed Nov 20 16:32:18 2019 +0800 Run dos2unix on all files in tree Intentionally ignorng files under lib/yamlcpp (since we just maintain a copy of their distro) (cherry picked from commit 994a2f04be6c28ffe7207c08480ad944690a0411) Additional files on 8.0.x to backport include/tscore/MT_hashtable.h tests/gold_tests/pluginTest/xdebug/x_remap/out.gold Conflicts: tests/gold_tests/pluginTest/regex_remap/gold/regex_remap_crash.gold tests/gold_tests/pluginTest/regex_remap/gold/regex_remap_smoke.gold tests/gold_tests/pluginTest/regex_revalidate/gold/regex_reval-hit.gold tests/gold_tests/pluginTest/regex_revalidate/gold/regex_reval-miss.gold tests/gold_tests/pluginTest/regex_revalidate/gold/regex_reval-stale.gold tests/gold_tests/pluginTest/slice/gold/slice_200.stdout.gold tests/gold_tests/pluginTest/slice/gold/slice_206.stdout.gold tests/gold_tests/pluginTest/slice/gold/slice_first.stdout.gold tests/gold_tests/pluginTest/slice/gold/slice_last.stderr.gold tests/gold_tests/pluginTest/slice/gold/slice_last.stdout.gold tests/gold_tests/pluginTest/slice/gold/slice_mid.stderr.gold tests/gold_tests/pluginTest/slice/gold/slice_mid.stdout.gold tests/gold_tests/pluginTest/slice/gold_error/crr.stdout.gold tests/gold_tests/pluginTest/slice/gold_error/etag.stdout.gold tests/gold_tests/pluginTest/slice/gold_error/lm.stdout.gold tests/gold_tests/pluginTest/slice/gold_error/non206.stdout.gold --- include/tscore/MT_hashtable.h | 882 ++++++++++----------- .../data/www.customplugin204.test_get.txt | 4 +- .../data/www.customtemplate204.test_get.txt | 4 +- .../body_factory/data/www.default204.test_get.txt | 4 +- .../body_factory/data/www.default304.test_get.txt | 4 +- .../body_factory/data/www.example.test_get_200.txt | 6 +- .../body_factory/data/www.example.test_get_304.txt | 8 +- .../body_factory/data/www.example.test_head.txt | 6 +- .../data/www.example.test_head_200.txt | 6 +- .../headers/data/www.passthrough.test_get.txt | 4 +- .../headers/data/www.redirect0.test_get.txt | 4 +- .../headers/data/www.redirect301.test_get.txt | 4 +- .../headers/data/www.redirect302.test_get.txt | 4 +- .../headers/data/www.redirect307.test_get.txt | 4 +- .../headers/data/www.redirect308.test_get.txt | 4 +- .../headers/general-connection-failure-502.gold | 14 +- tests/gold_tests/pluginTest/url_sig/url_sig.gold | 30 +- .../gold_tests/pluginTest/xdebug/x_remap/out.gold | 58 +- tests/gold_tests/redirect/gold/redirect.gold | 6 +- 19 files changed, 528 insertions(+), 528 deletions(-) diff --git a/include/tscore/MT_hashtable.h b/include/tscore/MT_hashtable.h index bfbae79..2c24225 100644 --- a/include/tscore/MT_hashtable.h +++ b/include/tscore/MT_hashtable.h @@ -1,441 +1,441 @@ -/** @file - - A brief file description - - @section license License - - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -/**************************************************************************** - - MT_hashtable.h - - Multithread Safe Hash table implementation - - - ****************************************************************************/ -#pragma once - -#define MT_HASHTABLE_PARTITION_BITS 6 -#define MT_HASHTABLE_PARTITIONS (1 << MT_HASHTABLE_PARTITION_BITS) -#define MT_HASHTABLE_PARTITION_MASK (MT_HASHTABLE_PARTITIONS - 1) -#define MT_HASHTABLE_MAX_CHAIN_AVG_LEN 4 -template <class key_t, class data_t> struct HashTableEntry { - key_t key; - data_t data; - HashTableEntry *next; - - static HashTableEntry * - alloc() - { - return (HashTableEntry *)ats_malloc(sizeof(HashTableEntry)); - } - - static void - free(HashTableEntry *entry) - { - ats_free(entry); - } -}; - -/* -struct MT_ListEntry{ - MT_ListEntry():next(NULL),prev(NULL){} - MT_ListEntry* next; - MT_ListEntry* prev; -}; - -#define INIT_CHAIN_HEAD(h) {(h)->next = (h)->prev = (h);} -#define APPEND_TO_CHAIN(h, p) {(p)->next = (h)->next; (h)->next->prev = (p); (p)->prev = (h); (h)->next = (p);} -#define REMOVE_FROM_CHAIN(p) {(p)->next->prev = (p)->prev; (p)->prev->next = (p)->next; (p)->prev = (p)->next = NULL;} -#define GET_OBJ_PTR(p, type, offset) ((type*)((char*)(p) - offset)) -*/ - -template <class key_t, class data_t> class HashTableIteratorState -{ -public: - HashTableIteratorState() : cur_buck(-1), ppcur(NULL) {} - int cur_buck; - HashTableEntry<key_t, data_t> **ppcur; -}; - -template <class key_t, class data_t> class IMTHashTable -{ -public: - IMTHashTable(int size, bool (*gc_func)(data_t) = NULL, void (*pre_gc_func)(void) = nullptr) - { - m_gc_func = gc_func; - m_pre_gc_func = pre_gc_func; - bucket_num = size; - cur_size = 0; - buckets = new HashTableEntry<key_t, data_t> *[bucket_num]; - memset(buckets, 0, bucket_num * sizeof(HashTableEntry<key_t, data_t> *)); - } - ~IMTHashTable() { reset(); } - int - getBucketNum() - { - return bucket_num; - } - int - getCurSize() - { - return cur_size; - } - - int - bucket_id(key_t key, int a_bucket_num) - { - return (int)(((key >> MT_HASHTABLE_PARTITION_BITS) ^ key) % a_bucket_num); - } - - int - bucket_id(key_t key) - { - return bucket_id(key, bucket_num); - } - - void - reset() - { - HashTableEntry<key_t, data_t> *tmp; - for (int i = 0; i < bucket_num; i++) { - tmp = buckets[i]; - while (tmp) { - buckets[i] = tmp->next; - HashTableEntry<key_t, data_t>::free(tmp); - tmp = buckets[i]; - } - } - delete[] buckets; - buckets = NULL; - } - - data_t insert_entry(key_t key, data_t data); - data_t remove_entry(key_t key); - data_t lookup_entry(key_t key); - - data_t first_entry(int bucket_id, HashTableIteratorState<key_t, data_t> *s); - static data_t next_entry(HashTableIteratorState<key_t, data_t> *s); - static data_t cur_entry(HashTableIteratorState<key_t, data_t> *s); - data_t remove_entry(HashTableIteratorState<key_t, data_t> *s); - - void - GC(void) - { - if (m_gc_func == NULL) { - return; - } - if (m_pre_gc_func) { - m_pre_gc_func(); - } - for (int i = 0; i < bucket_num; i++) { - HashTableEntry<key_t, data_t> *cur = buckets[i]; - HashTableEntry<key_t, data_t> *prev = NULL; - HashTableEntry<key_t, data_t> *next = NULL; - while (cur != NULL) { - next = cur->next; - if (m_gc_func(cur->data)) { - if (prev != NULL) { - prev->next = next; - } else { - buckets[i] = next; - } - ats_free(cur); - cur_size--; - } else { - prev = cur; - } - cur = next; - } - } - } - - void - resize(int size) - { - int new_bucket_num = size; - HashTableEntry<key_t, data_t> **new_buckets = new HashTableEntry<key_t, data_t> *[new_bucket_num]; - memset(new_buckets, 0, new_bucket_num * sizeof(HashTableEntry<key_t, data_t> *)); - - for (int i = 0; i < bucket_num; i++) { - HashTableEntry<key_t, data_t> *cur = buckets[i]; - HashTableEntry<key_t, data_t> *next = NULL; - while (cur != NULL) { - next = cur->next; - int new_id = bucket_id(cur->key, new_bucket_num); - cur->next = new_buckets[new_id]; - new_buckets[new_id] = cur; - cur = next; - } - buckets[i] = NULL; - } - delete[] buckets; - buckets = new_buckets; - bucket_num = new_bucket_num; - } - -private: - HashTableEntry<key_t, data_t> **buckets; - int cur_size; - int bucket_num; - bool (*m_gc_func)(data_t); - void (*m_pre_gc_func)(void); - -private: - IMTHashTable(); - IMTHashTable(IMTHashTable &); -}; - -/* - * we can use ClassAllocator here if the malloc performance becomes a problem - */ - -template <class key_t, class data_t> -inline data_t -IMTHashTable<key_t, data_t>::insert_entry(key_t key, data_t data) -{ - int id = bucket_id(key); - HashTableEntry<key_t, data_t> *cur = buckets[id]; - while (cur != NULL && cur->key != key) { - cur = cur->next; - } - if (cur != NULL) { - if (data == cur->data) { - return (data_t)0; - } else { - data_t tmp = cur->data; - cur->data = data; - // potential memory leak, need to check the return value by the caller - return tmp; - } - } - - HashTableEntry<key_t, data_t> *newEntry = HashTableEntry<key_t, data_t>::alloc(); - newEntry->key = key; - newEntry->data = data; - newEntry->next = buckets[id]; - buckets[id] = newEntry; - cur_size++; - if (cur_size / bucket_num > MT_HASHTABLE_MAX_CHAIN_AVG_LEN) { - GC(); - if (cur_size / bucket_num > MT_HASHTABLE_MAX_CHAIN_AVG_LEN) { - resize(bucket_num * 2); - } - } - return (data_t)0; -} - -template <class key_t, class data_t> -inline data_t -IMTHashTable<key_t, data_t>::remove_entry(key_t key) -{ - int id = bucket_id(key); - data_t ret = (data_t)0; - HashTableEntry<key_t, data_t> *cur = buckets[id]; - HashTableEntry<key_t, data_t> *prev = NULL; - while (cur != NULL && cur->key != key) { - prev = cur; - cur = cur->next; - } - if (cur != NULL) { - if (prev != NULL) { - prev->next = cur->next; - } else { - buckets[id] = cur->next; - } - ret = cur->data; - HashTableEntry<key_t, data_t>::free(cur); - cur_size--; - } - - return ret; -} - -template <class key_t, class data_t> -inline data_t -IMTHashTable<key_t, data_t>::lookup_entry(key_t key) -{ - int id = bucket_id(key); - data_t ret = (data_t)0; - HashTableEntry<key_t, data_t> *cur = buckets[id]; - while (cur != NULL && cur->key != key) { - cur = cur->next; - } - if (cur != NULL) { - ret = cur->data; - } - return ret; -} - -template <class key_t, class data_t> -inline data_t -IMTHashTable<key_t, data_t>::first_entry(int bucket_id, HashTableIteratorState<key_t, data_t> *s) -{ - s->cur_buck = bucket_id; - s->ppcur = &(buckets[bucket_id]); - if (*(s->ppcur) != NULL) { - return (*(s->ppcur))->data; - } - return (data_t)0; -} - -template <class key_t, class data_t> -inline data_t -IMTHashTable<key_t, data_t>::next_entry(HashTableIteratorState<key_t, data_t> *s) -{ - if ((*(s->ppcur)) != NULL) { - s->ppcur = &((*(s->ppcur))->next); - if (*(s->ppcur) != NULL) { - return (*(s->ppcur))->data; - } - } - return (data_t)0; -} - -template <class key_t, class data_t> -inline data_t -IMTHashTable<key_t, data_t>::cur_entry(HashTableIteratorState<key_t, data_t> *s) -{ - if (*(s->ppcur) == NULL) { - return (data_t)0; - } - return (*(s->ppcur))->data; -} - -template <class key_t, class data_t> -inline data_t -IMTHashTable<key_t, data_t>::remove_entry(HashTableIteratorState<key_t, data_t> *s) -{ - data_t data = (data_t)0; - HashTableEntry<key_t, data_t> *pEntry = *(s->ppcur); - if (pEntry != NULL) { - data = pEntry->data; - (*(s->ppcur)) = pEntry->next; - HashTableEntry<key_t, data_t>::free(pEntry); - cur_size--; - } - return data; -} - -template <class key_t, class data_t> class MTHashTable -{ -public: - MTHashTable(int size, bool (*gc_func)(data_t) = NULL, void (*pre_gc_func)(void) = nullptr) - { - for (int i = 0; i < MT_HASHTABLE_PARTITIONS; i++) { - locks[i] = new_ProxyMutex(); - hashTables[i] = new IMTHashTable<key_t, data_t>(size, gc_func, pre_gc_func); - // INIT_CHAIN_HEAD(&chain_heads[i]); - // last_GC_time[i] = 0; - } - // cur_items = 0; - } - ~MTHashTable() - { - for (int i = 0; i < MT_HASHTABLE_PARTITIONS; i++) { - locks[i] = NULL; - delete hashTables[i]; - } - } - - ProxyMutex * - lock_for_key(key_t key) - { - return locks[part_num(key)].get(); - } - - int - getSize() - { - return MT_HASHTABLE_PARTITIONS; - } - int - part_num(key_t key) - { - return (int)(key & MT_HASHTABLE_PARTITION_MASK); - } - data_t - insert_entry(key_t key, data_t data) - { - // ink_atomic_increment(&cur_items, 1); - return hashTables[part_num(key)]->insert_entry(key, data); - } - data_t - remove_entry(key_t key) - { - // ink_atomic_increment(&cur_items, -1); - return hashTables[part_num(key)]->remove_entry(key); - } - data_t - lookup_entry(key_t key) - { - return hashTables[part_num(key)]->lookup_entry(key); - } - - data_t - first_entry(int part_id, HashTableIteratorState<key_t, data_t> *s) - { - data_t ret = (data_t)0; - for (int i = 0; i < hashTables[part_id]->getBucketNum(); i++) { - ret = hashTables[part_id]->first_entry(i, s); - if (ret != (data_t)0) { - return ret; - } - } - return (data_t)0; - } - - data_t - cur_entry(int part_id, HashTableIteratorState<key_t, data_t> *s) - { - data_t data = IMTHashTable<key_t, data_t>::cur_entry(s); - if (!data) { - data = next_entry(part_id, s); - } - return data; - }; - data_t - next_entry(int part_id, HashTableIteratorState<key_t, data_t> *s) - { - data_t ret = IMTHashTable<key_t, data_t>::next_entry(s); - if (ret != (data_t)0) { - return ret; - } - for (int i = s->cur_buck + 1; i < hashTables[part_id]->getBucketNum(); i++) { - ret = hashTables[part_id]->first_entry(i, s); - if (ret != (data_t)0) { - return ret; - } - } - return (data_t)0; - } - data_t - remove_entry(int part_id, HashTableIteratorState<key_t, data_t> *s) - { - // ink_atomic_increment(&cur_items, -1); - return hashTables[part_id]->remove_entry(s); - } - -private: - IMTHashTable<key_t, data_t> *hashTables[MT_HASHTABLE_PARTITIONS]; - Ptr<ProxyMutex> locks[MT_HASHTABLE_PARTITIONS]; - // MT_ListEntry chain_heads[MT_HASHTABLE_PARTITIONS]; - // int last_GC_time[MT_HASHTABLE_PARTITIONS]; - // int32_t cur_items; -}; +/** @file + + A brief file description + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +/**************************************************************************** + + MT_hashtable.h + + Multithread Safe Hash table implementation + + + ****************************************************************************/ +#pragma once + +#define MT_HASHTABLE_PARTITION_BITS 6 +#define MT_HASHTABLE_PARTITIONS (1 << MT_HASHTABLE_PARTITION_BITS) +#define MT_HASHTABLE_PARTITION_MASK (MT_HASHTABLE_PARTITIONS - 1) +#define MT_HASHTABLE_MAX_CHAIN_AVG_LEN 4 +template <class key_t, class data_t> struct HashTableEntry { + key_t key; + data_t data; + HashTableEntry *next; + + static HashTableEntry * + alloc() + { + return (HashTableEntry *)ats_malloc(sizeof(HashTableEntry)); + } + + static void + free(HashTableEntry *entry) + { + ats_free(entry); + } +}; + +/* +struct MT_ListEntry{ + MT_ListEntry():next(NULL),prev(NULL){} + MT_ListEntry* next; + MT_ListEntry* prev; +}; + +#define INIT_CHAIN_HEAD(h) {(h)->next = (h)->prev = (h);} +#define APPEND_TO_CHAIN(h, p) {(p)->next = (h)->next; (h)->next->prev = (p); (p)->prev = (h); (h)->next = (p);} +#define REMOVE_FROM_CHAIN(p) {(p)->next->prev = (p)->prev; (p)->prev->next = (p)->next; (p)->prev = (p)->next = NULL;} +#define GET_OBJ_PTR(p, type, offset) ((type*)((char*)(p) - offset)) +*/ + +template <class key_t, class data_t> class HashTableIteratorState +{ +public: + HashTableIteratorState() : cur_buck(-1), ppcur(NULL) {} + int cur_buck; + HashTableEntry<key_t, data_t> **ppcur; +}; + +template <class key_t, class data_t> class IMTHashTable +{ +public: + IMTHashTable(int size, bool (*gc_func)(data_t) = NULL, void (*pre_gc_func)(void) = nullptr) + { + m_gc_func = gc_func; + m_pre_gc_func = pre_gc_func; + bucket_num = size; + cur_size = 0; + buckets = new HashTableEntry<key_t, data_t> *[bucket_num]; + memset(buckets, 0, bucket_num * sizeof(HashTableEntry<key_t, data_t> *)); + } + ~IMTHashTable() { reset(); } + int + getBucketNum() + { + return bucket_num; + } + int + getCurSize() + { + return cur_size; + } + + int + bucket_id(key_t key, int a_bucket_num) + { + return (int)(((key >> MT_HASHTABLE_PARTITION_BITS) ^ key) % a_bucket_num); + } + + int + bucket_id(key_t key) + { + return bucket_id(key, bucket_num); + } + + void + reset() + { + HashTableEntry<key_t, data_t> *tmp; + for (int i = 0; i < bucket_num; i++) { + tmp = buckets[i]; + while (tmp) { + buckets[i] = tmp->next; + HashTableEntry<key_t, data_t>::free(tmp); + tmp = buckets[i]; + } + } + delete[] buckets; + buckets = NULL; + } + + data_t insert_entry(key_t key, data_t data); + data_t remove_entry(key_t key); + data_t lookup_entry(key_t key); + + data_t first_entry(int bucket_id, HashTableIteratorState<key_t, data_t> *s); + static data_t next_entry(HashTableIteratorState<key_t, data_t> *s); + static data_t cur_entry(HashTableIteratorState<key_t, data_t> *s); + data_t remove_entry(HashTableIteratorState<key_t, data_t> *s); + + void + GC(void) + { + if (m_gc_func == NULL) { + return; + } + if (m_pre_gc_func) { + m_pre_gc_func(); + } + for (int i = 0; i < bucket_num; i++) { + HashTableEntry<key_t, data_t> *cur = buckets[i]; + HashTableEntry<key_t, data_t> *prev = NULL; + HashTableEntry<key_t, data_t> *next = NULL; + while (cur != NULL) { + next = cur->next; + if (m_gc_func(cur->data)) { + if (prev != NULL) { + prev->next = next; + } else { + buckets[i] = next; + } + ats_free(cur); + cur_size--; + } else { + prev = cur; + } + cur = next; + } + } + } + + void + resize(int size) + { + int new_bucket_num = size; + HashTableEntry<key_t, data_t> **new_buckets = new HashTableEntry<key_t, data_t> *[new_bucket_num]; + memset(new_buckets, 0, new_bucket_num * sizeof(HashTableEntry<key_t, data_t> *)); + + for (int i = 0; i < bucket_num; i++) { + HashTableEntry<key_t, data_t> *cur = buckets[i]; + HashTableEntry<key_t, data_t> *next = NULL; + while (cur != NULL) { + next = cur->next; + int new_id = bucket_id(cur->key, new_bucket_num); + cur->next = new_buckets[new_id]; + new_buckets[new_id] = cur; + cur = next; + } + buckets[i] = NULL; + } + delete[] buckets; + buckets = new_buckets; + bucket_num = new_bucket_num; + } + +private: + HashTableEntry<key_t, data_t> **buckets; + int cur_size; + int bucket_num; + bool (*m_gc_func)(data_t); + void (*m_pre_gc_func)(void); + +private: + IMTHashTable(); + IMTHashTable(IMTHashTable &); +}; + +/* + * we can use ClassAllocator here if the malloc performance becomes a problem + */ + +template <class key_t, class data_t> +inline data_t +IMTHashTable<key_t, data_t>::insert_entry(key_t key, data_t data) +{ + int id = bucket_id(key); + HashTableEntry<key_t, data_t> *cur = buckets[id]; + while (cur != NULL && cur->key != key) { + cur = cur->next; + } + if (cur != NULL) { + if (data == cur->data) { + return (data_t)0; + } else { + data_t tmp = cur->data; + cur->data = data; + // potential memory leak, need to check the return value by the caller + return tmp; + } + } + + HashTableEntry<key_t, data_t> *newEntry = HashTableEntry<key_t, data_t>::alloc(); + newEntry->key = key; + newEntry->data = data; + newEntry->next = buckets[id]; + buckets[id] = newEntry; + cur_size++; + if (cur_size / bucket_num > MT_HASHTABLE_MAX_CHAIN_AVG_LEN) { + GC(); + if (cur_size / bucket_num > MT_HASHTABLE_MAX_CHAIN_AVG_LEN) { + resize(bucket_num * 2); + } + } + return (data_t)0; +} + +template <class key_t, class data_t> +inline data_t +IMTHashTable<key_t, data_t>::remove_entry(key_t key) +{ + int id = bucket_id(key); + data_t ret = (data_t)0; + HashTableEntry<key_t, data_t> *cur = buckets[id]; + HashTableEntry<key_t, data_t> *prev = NULL; + while (cur != NULL && cur->key != key) { + prev = cur; + cur = cur->next; + } + if (cur != NULL) { + if (prev != NULL) { + prev->next = cur->next; + } else { + buckets[id] = cur->next; + } + ret = cur->data; + HashTableEntry<key_t, data_t>::free(cur); + cur_size--; + } + + return ret; +} + +template <class key_t, class data_t> +inline data_t +IMTHashTable<key_t, data_t>::lookup_entry(key_t key) +{ + int id = bucket_id(key); + data_t ret = (data_t)0; + HashTableEntry<key_t, data_t> *cur = buckets[id]; + while (cur != NULL && cur->key != key) { + cur = cur->next; + } + if (cur != NULL) { + ret = cur->data; + } + return ret; +} + +template <class key_t, class data_t> +inline data_t +IMTHashTable<key_t, data_t>::first_entry(int bucket_id, HashTableIteratorState<key_t, data_t> *s) +{ + s->cur_buck = bucket_id; + s->ppcur = &(buckets[bucket_id]); + if (*(s->ppcur) != NULL) { + return (*(s->ppcur))->data; + } + return (data_t)0; +} + +template <class key_t, class data_t> +inline data_t +IMTHashTable<key_t, data_t>::next_entry(HashTableIteratorState<key_t, data_t> *s) +{ + if ((*(s->ppcur)) != NULL) { + s->ppcur = &((*(s->ppcur))->next); + if (*(s->ppcur) != NULL) { + return (*(s->ppcur))->data; + } + } + return (data_t)0; +} + +template <class key_t, class data_t> +inline data_t +IMTHashTable<key_t, data_t>::cur_entry(HashTableIteratorState<key_t, data_t> *s) +{ + if (*(s->ppcur) == NULL) { + return (data_t)0; + } + return (*(s->ppcur))->data; +} + +template <class key_t, class data_t> +inline data_t +IMTHashTable<key_t, data_t>::remove_entry(HashTableIteratorState<key_t, data_t> *s) +{ + data_t data = (data_t)0; + HashTableEntry<key_t, data_t> *pEntry = *(s->ppcur); + if (pEntry != NULL) { + data = pEntry->data; + (*(s->ppcur)) = pEntry->next; + HashTableEntry<key_t, data_t>::free(pEntry); + cur_size--; + } + return data; +} + +template <class key_t, class data_t> class MTHashTable +{ +public: + MTHashTable(int size, bool (*gc_func)(data_t) = NULL, void (*pre_gc_func)(void) = nullptr) + { + for (int i = 0; i < MT_HASHTABLE_PARTITIONS; i++) { + locks[i] = new_ProxyMutex(); + hashTables[i] = new IMTHashTable<key_t, data_t>(size, gc_func, pre_gc_func); + // INIT_CHAIN_HEAD(&chain_heads[i]); + // last_GC_time[i] = 0; + } + // cur_items = 0; + } + ~MTHashTable() + { + for (int i = 0; i < MT_HASHTABLE_PARTITIONS; i++) { + locks[i] = NULL; + delete hashTables[i]; + } + } + + ProxyMutex * + lock_for_key(key_t key) + { + return locks[part_num(key)].get(); + } + + int + getSize() + { + return MT_HASHTABLE_PARTITIONS; + } + int + part_num(key_t key) + { + return (int)(key & MT_HASHTABLE_PARTITION_MASK); + } + data_t + insert_entry(key_t key, data_t data) + { + // ink_atomic_increment(&cur_items, 1); + return hashTables[part_num(key)]->insert_entry(key, data); + } + data_t + remove_entry(key_t key) + { + // ink_atomic_increment(&cur_items, -1); + return hashTables[part_num(key)]->remove_entry(key); + } + data_t + lookup_entry(key_t key) + { + return hashTables[part_num(key)]->lookup_entry(key); + } + + data_t + first_entry(int part_id, HashTableIteratorState<key_t, data_t> *s) + { + data_t ret = (data_t)0; + for (int i = 0; i < hashTables[part_id]->getBucketNum(); i++) { + ret = hashTables[part_id]->first_entry(i, s); + if (ret != (data_t)0) { + return ret; + } + } + return (data_t)0; + } + + data_t + cur_entry(int part_id, HashTableIteratorState<key_t, data_t> *s) + { + data_t data = IMTHashTable<key_t, data_t>::cur_entry(s); + if (!data) { + data = next_entry(part_id, s); + } + return data; + }; + data_t + next_entry(int part_id, HashTableIteratorState<key_t, data_t> *s) + { + data_t ret = IMTHashTable<key_t, data_t>::next_entry(s); + if (ret != (data_t)0) { + return ret; + } + for (int i = s->cur_buck + 1; i < hashTables[part_id]->getBucketNum(); i++) { + ret = hashTables[part_id]->first_entry(i, s); + if (ret != (data_t)0) { + return ret; + } + } + return (data_t)0; + } + data_t + remove_entry(int part_id, HashTableIteratorState<key_t, data_t> *s) + { + // ink_atomic_increment(&cur_items, -1); + return hashTables[part_id]->remove_entry(s); + } + +private: + IMTHashTable<key_t, data_t> *hashTables[MT_HASHTABLE_PARTITIONS]; + Ptr<ProxyMutex> locks[MT_HASHTABLE_PARTITIONS]; + // MT_ListEntry chain_heads[MT_HASHTABLE_PARTITIONS]; + // int last_GC_time[MT_HASHTABLE_PARTITIONS]; + // int32_t cur_items; +}; diff --git a/tests/gold_tests/body_factory/data/www.customplugin204.test_get.txt b/tests/gold_tests/body_factory/data/www.customplugin204.test_get.txt index be603f9..4cf018a 100644 --- a/tests/gold_tests/body_factory/data/www.customplugin204.test_get.txt +++ b/tests/gold_tests/body_factory/data/www.customplugin204.test_get.txt @@ -1,2 +1,2 @@ -GET HTTP://www.customplugin204.test/ HTTP/1.1 - +GET HTTP://www.customplugin204.test/ HTTP/1.1 + diff --git a/tests/gold_tests/body_factory/data/www.customtemplate204.test_get.txt b/tests/gold_tests/body_factory/data/www.customtemplate204.test_get.txt index 395d798..f16fbc7 100644 --- a/tests/gold_tests/body_factory/data/www.customtemplate204.test_get.txt +++ b/tests/gold_tests/body_factory/data/www.customtemplate204.test_get.txt @@ -1,2 +1,2 @@ -GET HTTP://www.customtemplate204.test/ HTTP/1.1 - +GET HTTP://www.customtemplate204.test/ HTTP/1.1 + diff --git a/tests/gold_tests/body_factory/data/www.default204.test_get.txt b/tests/gold_tests/body_factory/data/www.default204.test_get.txt index e77408a..1a421dd 100644 --- a/tests/gold_tests/body_factory/data/www.default204.test_get.txt +++ b/tests/gold_tests/body_factory/data/www.default204.test_get.txt @@ -1,2 +1,2 @@ -GET HTTP://www.default204.test/ HTTP/1.1 - +GET HTTP://www.default204.test/ HTTP/1.1 + diff --git a/tests/gold_tests/body_factory/data/www.default304.test_get.txt b/tests/gold_tests/body_factory/data/www.default304.test_get.txt index c9064fa..d251435 100644 --- a/tests/gold_tests/body_factory/data/www.default304.test_get.txt +++ b/tests/gold_tests/body_factory/data/www.default304.test_get.txt @@ -1,2 +1,2 @@ -GET HTTP://www.default304.test/ HTTP/1.1 - +GET HTTP://www.default304.test/ HTTP/1.1 + diff --git a/tests/gold_tests/body_factory/data/www.example.test_get_200.txt b/tests/gold_tests/body_factory/data/www.example.test_get_200.txt index c53681f..5994603 100644 --- a/tests/gold_tests/body_factory/data/www.example.test_get_200.txt +++ b/tests/gold_tests/body_factory/data/www.example.test_get_200.txt @@ -1,3 +1,3 @@ -GET /get200 HTTP/1.1 -Host: www.example.test - +GET /get200 HTTP/1.1 +Host: www.example.test + diff --git a/tests/gold_tests/body_factory/data/www.example.test_get_304.txt b/tests/gold_tests/body_factory/data/www.example.test_get_304.txt index 8d0aecf..03a8d59 100644 --- a/tests/gold_tests/body_factory/data/www.example.test_get_304.txt +++ b/tests/gold_tests/body_factory/data/www.example.test_get_304.txt @@ -1,4 +1,4 @@ -GET /get304 HTTP/1.1 -Host: www.example.test -If-Modified-Since: Thu, 1 Jan 1970 00:00:00 GMT - +GET /get304 HTTP/1.1 +Host: www.example.test +If-Modified-Since: Thu, 1 Jan 1970 00:00:00 GMT + diff --git a/tests/gold_tests/body_factory/data/www.example.test_head.txt b/tests/gold_tests/body_factory/data/www.example.test_head.txt index c5a5c97..514c107 100644 --- a/tests/gold_tests/body_factory/data/www.example.test_head.txt +++ b/tests/gold_tests/body_factory/data/www.example.test_head.txt @@ -1,3 +1,3 @@ -HEAD http://www.example.test/ HTTP/1.1 -Host: www.example.test - +HEAD http://www.example.test/ HTTP/1.1 +Host: www.example.test + diff --git a/tests/gold_tests/body_factory/data/www.example.test_head_200.txt b/tests/gold_tests/body_factory/data/www.example.test_head_200.txt index 6d214e1..fc0f1d5 100644 --- a/tests/gold_tests/body_factory/data/www.example.test_head_200.txt +++ b/tests/gold_tests/body_factory/data/www.example.test_head_200.txt @@ -1,3 +1,3 @@ -HEAD /head200 HTTP/1.1 -Host: www.example.test - +HEAD /head200 HTTP/1.1 +Host: www.example.test + diff --git a/tests/gold_tests/headers/data/www.passthrough.test_get.txt b/tests/gold_tests/headers/data/www.passthrough.test_get.txt index 0cba742..ffe69c2 100644 --- a/tests/gold_tests/headers/data/www.passthrough.test_get.txt +++ b/tests/gold_tests/headers/data/www.passthrough.test_get.txt @@ -1,2 +1,2 @@ -GET http://www.passthrough.test/ HTTP/1.1 - +GET http://www.passthrough.test/ HTTP/1.1 + diff --git a/tests/gold_tests/headers/data/www.redirect0.test_get.txt b/tests/gold_tests/headers/data/www.redirect0.test_get.txt index 40fce98..3d3d219 100644 --- a/tests/gold_tests/headers/data/www.redirect0.test_get.txt +++ b/tests/gold_tests/headers/data/www.redirect0.test_get.txt @@ -1,2 +1,2 @@ -GET http://www.redirect0.test/ HTTP/1.1 - +GET http://www.redirect0.test/ HTTP/1.1 + diff --git a/tests/gold_tests/headers/data/www.redirect301.test_get.txt b/tests/gold_tests/headers/data/www.redirect301.test_get.txt index 4835267..e51c353 100644 --- a/tests/gold_tests/headers/data/www.redirect301.test_get.txt +++ b/tests/gold_tests/headers/data/www.redirect301.test_get.txt @@ -1,2 +1,2 @@ -GET http://www.redirect301.test/ HTTP/1.1 - +GET http://www.redirect301.test/ HTTP/1.1 + diff --git a/tests/gold_tests/headers/data/www.redirect302.test_get.txt b/tests/gold_tests/headers/data/www.redirect302.test_get.txt index 6aae266..35f7750 100644 --- a/tests/gold_tests/headers/data/www.redirect302.test_get.txt +++ b/tests/gold_tests/headers/data/www.redirect302.test_get.txt @@ -1,2 +1,2 @@ -GET http://www.redirect302.test/ HTTP/1.1 - +GET http://www.redirect302.test/ HTTP/1.1 + diff --git a/tests/gold_tests/headers/data/www.redirect307.test_get.txt b/tests/gold_tests/headers/data/www.redirect307.test_get.txt index b37c8ae..49bb1bc 100644 --- a/tests/gold_tests/headers/data/www.redirect307.test_get.txt +++ b/tests/gold_tests/headers/data/www.redirect307.test_get.txt @@ -1,2 +1,2 @@ -GET http://www.redirect307.test/ HTTP/1.1 - +GET http://www.redirect307.test/ HTTP/1.1 + diff --git a/tests/gold_tests/headers/data/www.redirect308.test_get.txt b/tests/gold_tests/headers/data/www.redirect308.test_get.txt index 05bcbf8..097e95e 100644 --- a/tests/gold_tests/headers/data/www.redirect308.test_get.txt +++ b/tests/gold_tests/headers/data/www.redirect308.test_get.txt @@ -1,2 +1,2 @@ -GET http://www.redirect308.test/ HTTP/1.1 - +GET http://www.redirect308.test/ HTTP/1.1 + diff --git a/tests/gold_tests/headers/general-connection-failure-502.gold b/tests/gold_tests/headers/general-connection-failure-502.gold index 4749e20..a5e2732 100644 --- a/tests/gold_tests/headers/general-connection-failure-502.gold +++ b/tests/gold_tests/headers/general-connection-failure-502.gold @@ -1,10 +1,10 @@ -HTTP/1.1 502 connect failed -Connection: keep-alive -Cache-Control: no-store -Content-Type: text/html -Content-Language: en -Content-Length: 247 - +HTTP/1.1 502 connect failed +Connection: keep-alive +Cache-Control: no-store +Content-Type: text/html +Content-Language: en +Content-Length: 247 + <HTML> <HEAD> <TITLE>Could Not Connect</TITLE> diff --git a/tests/gold_tests/pluginTest/url_sig/url_sig.gold b/tests/gold_tests/pluginTest/url_sig/url_sig.gold index 256898b..12043d8 100644 --- a/tests/gold_tests/pluginTest/url_sig/url_sig.gold +++ b/tests/gold_tests/pluginTest/url_sig/url_sig.gold @@ -1,15 +1,15 @@ -< HTTP/1.1 403 Forbidden -< HTTP/1.1 403 Forbidden -< HTTP/1.1 403 Forbidden -< HTTP/1.1 403 Forbidden -< HTTP/1.1 403 Forbidden -< HTTP/1.1 403 Forbidden -< HTTP/1.1 403 Forbidden -< HTTP/1.1 403 Forbidden -< HTTP/1.1 403 Forbidden -< HTTP/1.1 200 OK -< HTTP/1.1 200 OK -< HTTP/1.1 200 OK -< HTTP/1.1 200 OK -< HTTP/1.1 200 OK -< HTTP/1.1 200 OK +< HTTP/1.1 403 Forbidden +< HTTP/1.1 403 Forbidden +< HTTP/1.1 403 Forbidden +< HTTP/1.1 403 Forbidden +< HTTP/1.1 403 Forbidden +< HTTP/1.1 403 Forbidden +< HTTP/1.1 403 Forbidden +< HTTP/1.1 403 Forbidden +< HTTP/1.1 403 Forbidden +< HTTP/1.1 200 OK +< HTTP/1.1 200 OK +< HTTP/1.1 200 OK +< HTTP/1.1 200 OK +< HTTP/1.1 200 OK +< HTTP/1.1 200 OK diff --git a/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold b/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold index cb8fd49..057b5ce 100644 --- a/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold +++ b/tests/gold_tests/pluginTest/xdebug/x_remap/out.gold @@ -1,13 +1,13 @@ -HTTP/1.1 502 Cannot find server. +HTTP/1.1 502 Cannot find server. Date:`` -Connection: keep-alive +Connection: keep-alive Server:`` -Cache-Control: no-store -Content-Type: text/html -Content-Language: en -X-Remap: from=Not-Found, to=Not-Found -Content-Length: 391 - +Cache-Control: no-store +Content-Type: text/html +Content-Language: en +X-Remap: from=Not-Found, to=Not-Found +Content-Length: 391 + <HTML> <HEAD> <TITLE>Unknown Host</TITLE> @@ -26,36 +26,36 @@ name and try again. <HR> </BODY> ====== -HTTP/1.1 200 OK +HTTP/1.1 200 OK Date:`` Age:`` -Transfer-Encoding: chunked -Connection: keep-alive +Transfer-Encoding: chunked +Connection: keep-alive Server:`` -X-Remap: from=http://one/, to=http://127.0.0.1:SERVER_PORT/ - -0 - +X-Remap: from=http://one/, to=http://127.0.0.1:SERVER_PORT/ + +0 + ====== -HTTP/1.1 200 OK +HTTP/1.1 200 OK Date:`` Age:`` -Transfer-Encoding: chunked -Connection: keep-alive +Transfer-Encoding: chunked +Connection: keep-alive Server:`` -X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/ - -0 - +X-Remap: from=http://two/, to=http://127.0.0.1:SERVER_PORT/ + +0 + ====== -HTTP/1.1 200 OK +HTTP/1.1 200 OK Date:`` Age:`` -Transfer-Encoding: chunked -Connection: keep-alive +Transfer-Encoding: chunked +Connection: keep-alive Server:`` -X-Remap: from=http://three[0-9]+/, to=http://127.0.0.1:SERVER_PORT/ - -0 - +X-Remap: from=http://three[0-9]+/, to=http://127.0.0.1:SERVER_PORT/ + +0 + ====== diff --git a/tests/gold_tests/redirect/gold/redirect.gold b/tests/gold_tests/redirect/gold/redirect.gold index 9500bf9..3082e74 100644 --- a/tests/gold_tests/redirect/gold/redirect.gold +++ b/tests/gold_tests/redirect/gold/redirect.gold @@ -1,5 +1,5 @@ -HTTP/1.1 204 No Content +HTTP/1.1 204 No Content `` -Age: `` -Connection: keep-alive +Age: `` +Connection: keep-alive