LocalSearch.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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  LocalSearch();
26 
27  /* StoreSearch API */
28  virtual void next(void (callback)(void *cbdata), void *cbdata) override;
29  virtual bool next() override;
30  virtual bool error() const override;
31  virtual bool isDone() const override;
32  virtual StoreEntry *currentItem() override;
33 
34 private:
35  void copyBucket();
36  void (*callback)(void *cbdata);
37  void *cbdata;
38  bool _done;
39  int bucket;
40  std::vector<StoreEntry *> entries;
41 };
42 
43 } // namespace Store
44 
45 CBDATA_NAMESPACED_CLASS_INIT(Store, LocalSearch);
46 
49 {
50  return new LocalSearch;
51 }
52 
54  callback(NULL),
55  cbdata(NULL),
56  _done(false),
57  bucket(0)
58 {}
59 
60 void
61 Store::LocalSearch::next(void (aCallback)(void *), void *aCallbackData)
62 {
63  next();
64  aCallback (aCallbackData);
65 }
66 
67 bool
69 {
70  if (!entries.empty())
71  entries.pop_back();
72 
73  while (!isDone() && !entries.size())
74  copyBucket();
75 
76  return currentItem() != NULL;
77 }
78 
79 bool
81 {
82  return false;
83 }
84 
85 bool
87 {
88  return bucket >= store_hash_buckets || _done;
89 }
90 
91 StoreEntry *
93 {
94  if (!entries.size())
95  return NULL;
96 
97  return entries.back();
98 }
99 
100 void
102 {
103  /* probably need to lock the store entries...
104  * we copy them all to prevent races on the links. */
105  debugs(47, 3, "Store::LocalSearch::copyBucket #" << bucket);
106  assert (!entries.size());
107  hash_link *link_ptr = NULL;
108  hash_link *link_next = NULL;
109  link_next = hash_get_bucket(store_table, bucket);
110 
111  while (NULL != (link_ptr = link_next)) {
112  link_next = link_ptr->next;
113  StoreEntry *e = (StoreEntry *) link_ptr;
114 
115  entries.push_back(e);
116  }
117 
118  ++bucket;
119  debugs(47,3, "got entries: " << entries.size());
120 }
121 
hash_table * store_table
virtual bool isDone() const override
Definition: LocalSearch.cc:86
#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:92
virtual bool next() override
Definition: LocalSearch.cc:68
int store_hash_buckets
void(* callback)(void *cbdata)
Definition: LocalSearch.cc:36
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
std::vector< StoreEntry * > entries
Definition: LocalSearch.cc:40
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:80
#define NULL
Definition: types.h:166
#define false
Definition: GnuRegex.c:233
StoreSearch * NewLocalSearch()
Definition: LocalSearch.cc:48

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors