]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/store/LocalSearch.cc
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 47 Store Search */
12 #include "debug/Stream.h"
14 #include "store/LocalSearch.h"
15 #include "StoreSearch.h"
19 /// iterates local store_table
20 class LocalSearch
: public StoreSearch
22 CBDATA_CLASS(LocalSearch
);
26 void next(void (callback
)(void *cbdata
), void *cbdata
) override
;
28 bool error() const override
;
29 bool isDone() const override
;
30 StoreEntry
*currentItem() override
;
36 std::vector
<StoreEntry
*> entries
;
41 CBDATA_NAMESPACED_CLASS_INIT(Store
, LocalSearch
);
44 Store::NewLocalSearch()
46 return new LocalSearch
;
50 Store::LocalSearch::next(void (aCallback
)(void *), void *aCallbackData
)
53 aCallback (aCallbackData
);
57 Store::LocalSearch::next()
62 while (!isDone() && !entries
.size())
65 return currentItem() != nullptr;
69 Store::LocalSearch::error() const
75 Store::LocalSearch::isDone() const
77 return bucket
>= store_hash_buckets
|| _done
;
81 Store::LocalSearch::currentItem()
86 return entries
.back();
90 Store::LocalSearch::copyBucket()
92 /* probably need to lock the store entries...
93 * we copy them all to prevent races on the links. */
94 assert (!entries
.size());
95 hash_link
*link_ptr
= nullptr;
96 hash_link
*link_next
= nullptr;
97 link_next
= hash_get_bucket(store_table
, bucket
);
99 while (nullptr != (link_ptr
= link_next
)) {
100 link_next
= link_ptr
->next
;
101 StoreEntry
*e
= (StoreEntry
*) link_ptr
;
103 entries
.push_back(e
);
106 // minimize debugging: we may be called more than a million times on startup
107 if (const auto count
= entries
.size())
108 debugs(47, 8, "bucket #" << bucket
<< " entries: " << count
);