LocalSearch.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 /* DEBUG: section 47 Store Search */
10 
11 #include "squid.h"
12 #include "Debug.h"
13 #include "globals.h"
14 #include "store/LocalSearch.h"
15 #include "StoreSearch.h"
16 
17 namespace Store {
18 
20 class LocalSearch : public StoreSearch
21 {
23 
24 public:
25  /* StoreSearch API */
26  virtual void next(void (callback)(void *cbdata), void *cbdata) override;
27  virtual bool next() override;
28  virtual bool error() const override;
29  virtual bool isDone() const override;
30  virtual StoreEntry *currentItem() override;
31 
32 private:
33  void copyBucket();
34  bool _done = false;
35  int bucket = 0;
36  std::vector<StoreEntry *> entries;
37 };
38 
39 } // namespace Store
40 
41 CBDATA_NAMESPACED_CLASS_INIT(Store, LocalSearch);
42 
45 {
46  return new LocalSearch;
47 }
48 
49 void
50 Store::LocalSearch::next(void (aCallback)(void *), void *aCallbackData)
51 {
52  next();
53  aCallback (aCallbackData);
54 }
55 
56 bool
58 {
59  if (!entries.empty())
60  entries.pop_back();
61 
62  while (!isDone() && !entries.size())
63  copyBucket();
64 
65  return currentItem() != NULL;
66 }
67 
68 bool
70 {
71  return false;
72 }
73 
74 bool
76 {
77  return bucket >= store_hash_buckets || _done;
78 }
79 
80 StoreEntry *
82 {
83  if (!entries.size())
84  return NULL;
85 
86  return entries.back();
87 }
88 
89 void
91 {
92  /* probably need to lock the store entries...
93  * we copy them all to prevent races on the links. */
94  debugs(47, 3, "Store::LocalSearch::copyBucket #" << bucket);
95  assert (!entries.size());
96  hash_link *link_ptr = NULL;
97  hash_link *link_next = NULL;
98  link_next = hash_get_bucket(store_table, bucket);
99 
100  while (NULL != (link_ptr = link_next)) {
101  link_next = link_ptr->next;
102  StoreEntry *e = (StoreEntry *) link_ptr;
103 
104  entries.push_back(e);
105  }
106 
107  ++bucket;
108  debugs(47,3, "got entries: " << entries.size());
109 }
110 
hash_table * store_table
virtual bool isDone() const override
Definition: LocalSearch.cc:75
#define assert(EX)
Definition: assert.h:17
void const char HLPCB * callback
Definition: stub_helper.cc:16
Definition: cbdata.cc:60
virtual StoreEntry * currentItem() override
Definition: LocalSearch.cc:81
virtual bool next() override
Definition: LocalSearch.cc:57
int store_hash_buckets
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:124
std::vector< StoreEntry * > entries
Definition: LocalSearch.cc:36
SQUIDCEXTERN hash_link * hash_get_bucket(hash_table *, unsigned int)
Definition: hash.cc:248
CBDATA_NAMESPACED_CLASS_INIT(Store, LocalSearch)
CBDATA_CLASS(LocalSearch)
iterates local store_table
Definition: LocalSearch.cc:20
virtual bool error() const override
Definition: LocalSearch.cc:69
#define NULL
Definition: types.h:166
StoreSearch * NewLocalSearch()
Definition: LocalSearch.cc:44

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors