From: Amos Jeffries Date: Fri, 28 Oct 2016 01:37:51 +0000 (+1300) Subject: Cleanup: Remove custom StrList/link_list implementation X-Git-Tag: SQUID_4_0_16~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a522894240236b9cca86320cbcf1cd257a9bc1f8;p=thirdparty%2Fsquid.git Cleanup: Remove custom StrList/link_list implementation Use FIFO queue STL container instead. --- diff --git a/src/Makefile.am b/src/Makefile.am index 4c132c9f70..5d17687e15 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -358,8 +358,6 @@ squid_SOURCES = \ ipcache.cc \ ipcache.h \ $(LEAKFINDERSOURCE) \ - SquidList.h \ - SquidList.cc \ LogTags.cc \ LogTags.h \ lookup_t.h \ @@ -1059,8 +1057,6 @@ tests_testACLMaxUserIP_SOURCES= \ MasterXaction.h \ Notes.cc \ Notes.h \ - SquidList.h \ - SquidList.cc \ mem_node.cc \ Parsing.cc \ tests/stub_libsecurity.cc \ @@ -1296,8 +1292,6 @@ tests_testCacheManager_SOURCES = \ internal.cc \ LogTags.cc \ tests/stub_libsecurity.cc \ - SquidList.h \ - SquidList.cc \ MasterXaction.cc \ MasterXaction.h \ multicast.h \ @@ -1479,8 +1473,6 @@ tests_testDiskIO_SOURCES = \ HttpReply.cc \ int.h \ int.cc \ - SquidList.h \ - SquidList.cc \ MasterXaction.cc \ MasterXaction.h \ MemBuf.cc \ @@ -1725,8 +1717,6 @@ tests_testEvent_SOURCES = \ internal.cc \ LogTags.cc \ tests/stub_libsecurity.cc \ - SquidList.h \ - SquidList.cc \ MasterXaction.cc \ MasterXaction.h \ tests/stub_libmem.cc \ @@ -1963,8 +1953,6 @@ tests_testEventLoop_SOURCES = \ internal.h \ internal.cc \ LogTags.cc \ - SquidList.h \ - SquidList.cc \ MasterXaction.cc \ MasterXaction.h \ MemBuf.cc \ @@ -2197,8 +2185,6 @@ tests_test_http_range_SOURCES = \ $(IPC_SOURCE) \ ipcache.cc \ LogTags.cc \ - SquidList.h \ - SquidList.cc \ MasterXaction.cc \ MasterXaction.h \ MemBuf.cc \ @@ -2511,8 +2497,6 @@ tests_testHttpRequest_SOURCES = \ internal.cc \ LogTags.cc \ tests/stub_libsecurity.cc \ - SquidList.h \ - SquidList.cc \ MasterXaction.cc \ MasterXaction.h \ multicast.h \ @@ -2741,8 +2725,6 @@ tests_testStore_SOURCES= \ RequestFlags.h \ int.h \ int.cc \ - SquidList.h \ - SquidList.cc \ MasterXaction.cc \ MasterXaction.h \ mem_node.cc \ @@ -2967,8 +2949,6 @@ tests_testUfs_SOURCES = \ int.cc \ RequestFlags.h \ RequestFlags.cc \ - SquidList.h \ - SquidList.cc \ Transients.cc \ MasterXaction.cc \ MasterXaction.h \ @@ -3152,8 +3132,6 @@ tests_testRock_SOURCES = \ HttpReply.cc \ int.h \ int.cc \ - SquidList.h \ - SquidList.cc \ MasterXaction.cc \ MasterXaction.h \ MemBuf.cc \ @@ -3367,8 +3345,6 @@ tests_testURL_SOURCES = \ internal.cc \ tests/stub_libeui.cc \ LogTags.cc \ - SquidList.h \ - SquidList.cc \ MasterXaction.cc \ MasterXaction.h \ multicast.h \ diff --git a/src/SquidList.cc b/src/SquidList.cc deleted file mode 100644 index 0e09517b9a..0000000000 --- a/src/SquidList.cc +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 1996-2016 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -/* DEBUG: none Linked list functions (deprecated) */ - -#include "squid.h" -#include "mem/forward.h" -#include "SquidList.h" - -/* This should go away, in favour of the List template class */ - -void -linklistPush(link_list ** L, void *p) -{ - link_list *l = (link_list *)memAllocate(MEM_LINK_LIST); - l->next = NULL; - l->ptr = p; - - while (*L) - L = &(*L)->next; - - *L = l; -} - -void * -linklistShift(link_list ** L) -{ - void *p; - link_list *l; - - if (NULL == *L) - return NULL; - - l = *L; - - p = l->ptr; - - *L = (*L)->next; - - memFree(l, MEM_LINK_LIST); - - return p; -} - diff --git a/src/SquidList.h b/src/SquidList.h deleted file mode 100644 index 1fbeb741da..0000000000 --- a/src/SquidList.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 1996-2016 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -/* DEBUG: none Linked list functions (deprecated) */ - -#ifndef SQUID_SQUIDLIST_H_ -#define SQUID_SQUIDLIST_H_ - -class link_list -{ -public: - void *ptr; - link_list *next; -}; - -void linklistPush(link_list **, void *); -void *linklistShift(link_list **); - -#endif /* SQUID_SQUIDLIST_H_ */ - diff --git a/src/mem/forward.h b/src/mem/forward.h index d7adc84629..ed44f06189 100644 --- a/src/mem/forward.h +++ b/src/mem/forward.h @@ -44,7 +44,6 @@ typedef enum { MEM_16K_BUF, MEM_32K_BUF, MEM_64K_BUF, - MEM_LINK_LIST, MEM_DREAD_CTRL, MEM_DWRITE_Q, MEM_MD5_DIGEST, diff --git a/src/mem/old_api.cc b/src/mem/old_api.cc index 9ce3d444bd..1126ce27c3 100644 --- a/src/mem/old_api.cc +++ b/src/mem/old_api.cc @@ -22,7 +22,6 @@ #include "MemBuf.h" #include "mgr/Registration.h" #include "SquidConfig.h" -#include "SquidList.h" #include "SquidTime.h" #include "Store.h" @@ -440,7 +439,6 @@ Mem::Init(void) memDataInit(MEM_16K_BUF, "16K Buffer", 16384, 10, false); memDataInit(MEM_32K_BUF, "32K Buffer", 32768, 10, false); memDataInit(MEM_64K_BUF, "64K Buffer", 65536, 10, false); - memDataInit(MEM_LINK_LIST, "link_list", sizeof(link_list), 10); memDataInit(MEM_DREAD_CTRL, "dread_ctrl", sizeof(dread_ctrl), 0); memDataInit(MEM_DWRITE_Q, "dwrite_q", sizeof(dwrite_q), 0); memDataInit(MEM_MD5_DIGEST, "MD5 digest", SQUID_MD5_DIGEST_LENGTH, 0); diff --git a/src/repl/heap/store_repl_heap.cc b/src/repl/heap/store_repl_heap.cc index c4e64b0607..d6aa21563e 100644 --- a/src/repl/heap/store_repl_heap.cc +++ b/src/repl/heap/store_repl_heap.cc @@ -20,11 +20,12 @@ #include "squid.h" #include "heap.h" #include "MemObject.h" -#include "SquidList.h" #include "Store.h" #include "store_heap_replacement.h" #include "wordlist.h" +#include + REMOVALPOLICYCREATE createRemovalPolicy_heap; static int nr_heap_policies = 0; @@ -181,11 +182,11 @@ heap_walkInit(RemovalPolicy * policy) /** RemovalPurgeWalker **/ -typedef struct _HeapPurgeData HeapPurgeData; - -struct _HeapPurgeData { - link_list *locked_entries; - heap_key min_age; +class HeapPurgeData +{ +public: + std::queue locked_entries; + heap_key min_age = 0.0; }; static StoreEntry * @@ -209,7 +210,7 @@ try_again: if (entry->locked()) { entry->lock("heap_purgeNext"); - linklistPush(&heap_walker->locked_entries, entry); + heap_walker->locked_entries.push(entry); goto try_again; } @@ -225,7 +226,6 @@ heap_purgeDone(RemovalPurgeWalker * walker) HeapPurgeData *heap_walker = (HeapPurgeData *)walker->_data; RemovalPolicy *policy = walker->_policy; HeapPolicyData *h = (HeapPolicyData *)policy->_data; - StoreEntry *entry; assert(strcmp(policy->_type, "heap") == 0); assert(h->nwalkers > 0); h->nwalkers -= 1; @@ -235,16 +235,16 @@ heap_purgeDone(RemovalPurgeWalker * walker) debugs(81, 3, "Heap age set to " << h->theHeap->age); } - /* - * Reinsert the locked entries - */ - while ((entry = (StoreEntry *)linklistShift(&heap_walker->locked_entries))) { + // Reinsert the locked entries + while (!heap_walker->locked_entries.empty()) { + StoreEntry *entry = heap_walker->locked_entries.front(); heap_node *node = heap_insert(h->theHeap, entry); h->setPolicyNode(entry, node); entry->unlock("heap_purgeDone"); + heap_walker->locked_entries.pop(); } - safe_free(walker->_data); + delete heap_walker; delete walker; } @@ -256,9 +256,7 @@ heap_purgeInit(RemovalPolicy * policy, int max_scan) HeapPurgeData *heap_walk; h->nwalkers += 1; walker = new RemovalPurgeWalker; - heap_walk = (HeapPurgeData *)xcalloc(1, sizeof(*heap_walk)); - heap_walk->min_age = 0.0; - heap_walk->locked_entries = NULL; + heap_walk = new HeapPurgeData; walker->_policy = policy; walker->_data = heap_walk; walker->max_scan = max_scan;