7
7
#include < config.h>
8
8
9
9
#include < dhcpsrv/testutils/memory_host_data_source.h>
10
+ #include < util/multi_threading_mgr.h>
10
11
#include < boost/foreach.hpp>
11
12
12
13
using namespace isc ::db;
14
+ using namespace isc ::util;
13
15
using namespace std ;
14
16
15
17
namespace isc {
@@ -22,6 +24,7 @@ MemHostDataSource::getAll(const Host::IdentifierType& identifier_type,
22
24
const size_t identifier_len) const {
23
25
vector<uint8_t > ident (identifier_begin, identifier_begin + identifier_len);
24
26
ConstHostCollection hosts;
27
+ MultiThreadingLock lock (mutex_);
25
28
for (auto const & h : store_) {
26
29
// If identifier type do not match, it's not for us
27
30
if (h->getIdentifierType () != identifier_type) {
@@ -38,6 +41,7 @@ MemHostDataSource::getAll(const Host::IdentifierType& identifier_type,
38
41
ConstHostCollection
39
42
MemHostDataSource::getAll4 (const SubnetID& subnet_id) const {
40
43
ConstHostCollection hosts;
44
+ MultiThreadingLock lock (mutex_);
41
45
for (auto const & h : store_) {
42
46
// Keep it when subnet_id matches.
43
47
if (h->getIPv4SubnetID () == subnet_id) {
@@ -50,6 +54,7 @@ MemHostDataSource::getAll4(const SubnetID& subnet_id) const {
50
54
ConstHostCollection
51
55
MemHostDataSource::getAll6 (const SubnetID& subnet_id) const {
52
56
ConstHostCollection hosts;
57
+ MultiThreadingLock lock (mutex_);
53
58
for (auto const & h : store_) {
54
59
// Keep it when subnet_id matches.
55
60
if (h->getIPv6SubnetID () == subnet_id) {
@@ -62,6 +67,7 @@ MemHostDataSource::getAll6(const SubnetID& subnet_id) const {
62
67
ConstHostCollection
63
68
MemHostDataSource::getAllbyHostname (const std::string& hostname) const {
64
69
ConstHostCollection hosts;
70
+ MultiThreadingLock lock (mutex_);
65
71
for (auto const & h : store_) {
66
72
// Keep it when hostname matches.
67
73
if (h->getLowerHostname () == hostname) {
@@ -75,6 +81,7 @@ ConstHostCollection
75
81
MemHostDataSource::getAllbyHostname4 (const std::string& hostname,
76
82
const SubnetID& subnet_id) const {
77
83
ConstHostCollection hosts;
84
+ MultiThreadingLock lock (mutex_);
78
85
for (auto const & h : store_) {
79
86
// Keep it when hostname and subnet_id match.
80
87
if ((h->getLowerHostname () == hostname) &&
@@ -89,6 +96,7 @@ ConstHostCollection
89
96
MemHostDataSource::getAllbyHostname6 (const std::string& hostname,
90
97
const SubnetID& subnet_id) const {
91
98
ConstHostCollection hosts;
99
+ MultiThreadingLock lock (mutex_);
92
100
for (auto const & h : store_) {
93
101
// Keep it when hostname and subnet_id match.
94
102
if ((h->getLowerHostname () == hostname) &&
@@ -105,6 +113,7 @@ MemHostDataSource::getPage4(const SubnetID& subnet_id,
105
113
uint64_t lower_host_id,
106
114
const HostPageSize& page_size) const {
107
115
ConstHostCollection hosts;
116
+ MultiThreadingLock lock (mutex_);
108
117
for (auto const & h : store_) {
109
118
// Skip it when subnet_id does not match.
110
119
if (h->getIPv4SubnetID () != subnet_id) {
@@ -127,6 +136,7 @@ MemHostDataSource::getPage6(const SubnetID& subnet_id,
127
136
uint64_t lower_host_id,
128
137
const HostPageSize& page_size) const {
129
138
ConstHostCollection hosts;
139
+ MultiThreadingLock lock (mutex_);
130
140
for (auto const & h : store_) {
131
141
// Skip it when subnet_id does not match.
132
142
if (h->getIPv6SubnetID () != subnet_id) {
@@ -148,6 +158,7 @@ MemHostDataSource::getPage4(size_t& /*source_index*/,
148
158
uint64_t lower_host_id,
149
159
const HostPageSize& page_size) const {
150
160
ConstHostCollection hosts;
161
+ MultiThreadingLock lock (mutex_);
151
162
for (auto const & h : store_) {
152
163
if (lower_host_id && (h->getHostId () <= lower_host_id)) {
153
164
continue ;
@@ -165,6 +176,7 @@ MemHostDataSource::getPage6(size_t& /*source_index*/,
165
176
uint64_t lower_host_id,
166
177
const HostPageSize& page_size) const {
167
178
ConstHostCollection hosts;
179
+ MultiThreadingLock lock (mutex_);
168
180
for (auto const & h : store_) {
169
181
if (lower_host_id && (h->getHostId () <= lower_host_id)) {
170
182
continue ;
@@ -180,6 +192,7 @@ MemHostDataSource::getPage6(size_t& /*source_index*/,
180
192
ConstHostCollection
181
193
MemHostDataSource::getAll4 (const asiolink::IOAddress& address) const {
182
194
ConstHostCollection hosts;
195
+ MultiThreadingLock lock (mutex_);
183
196
for (auto const & h : store_) {
184
197
if (h->getIPv4Reservation () == address) {
185
198
hosts.push_back (h);
@@ -195,6 +208,7 @@ MemHostDataSource::get4(const SubnetID& subnet_id,
195
208
const uint8_t * identifier_begin,
196
209
const size_t identifier_len) const {
197
210
vector<uint8_t > ident (identifier_begin, identifier_begin + identifier_len);
211
+ MultiThreadingLock lock (mutex_);
198
212
for (auto const & h : store_) {
199
213
// If either subnet-id or identifier type do not match,
200
214
// it's not our host
@@ -218,6 +232,7 @@ MemHostDataSource::get6(const SubnetID& subnet_id,
218
232
const uint8_t * identifier_begin,
219
233
const size_t identifier_len) const {
220
234
vector<uint8_t > ident (identifier_begin, identifier_begin + identifier_len);
235
+ MultiThreadingLock lock (mutex_);
221
236
for (auto const & h : store_) {
222
237
// If either subnet-id or identifier type do not match,
223
238
// it's not our host
@@ -237,6 +252,7 @@ MemHostDataSource::get6(const SubnetID& subnet_id,
237
252
ConstHostPtr
238
253
MemHostDataSource::get4 (const SubnetID& subnet_id,
239
254
const asiolink::IOAddress& address) const {
255
+ MultiThreadingLock lock (mutex_);
240
256
for (auto const & h : store_) {
241
257
if (h->getIPv4SubnetID () == subnet_id &&
242
258
h->getIPv4Reservation () == address) {
@@ -251,6 +267,7 @@ ConstHostCollection
251
267
MemHostDataSource::getAll4 (const SubnetID& subnet_id,
252
268
const asiolink::IOAddress& address) const {
253
269
ConstHostCollection hosts;
270
+ MultiThreadingLock lock (mutex_);
254
271
for (auto const & h : store_) {
255
272
if (h->getIPv4SubnetID () == subnet_id &&
256
273
h->getIPv4Reservation () == address) {
@@ -270,6 +287,7 @@ MemHostDataSource::get6(const asiolink::IOAddress& /*prefix*/,
270
287
ConstHostPtr
271
288
MemHostDataSource::get6 (const SubnetID& subnet_id,
272
289
const asiolink::IOAddress& address) const {
290
+ MultiThreadingLock lock (mutex_);
273
291
for (auto const & h : store_) {
274
292
275
293
// Naive approach: check hosts one by one
@@ -297,6 +315,7 @@ ConstHostCollection
297
315
MemHostDataSource::getAll6 (const SubnetID& subnet_id,
298
316
const asiolink::IOAddress& address) const {
299
317
ConstHostCollection hosts;
318
+ MultiThreadingLock lock (mutex_);
300
319
for (auto const & h : store_) {
301
320
if (h->getIPv6SubnetID () != subnet_id) {
302
321
continue ;
@@ -316,6 +335,7 @@ MemHostDataSource::getAll6(const SubnetID& subnet_id,
316
335
ConstHostCollection
317
336
MemHostDataSource::getAll6 (const asiolink::IOAddress& address) const {
318
337
ConstHostCollection hosts;
338
+ MultiThreadingLock lock (mutex_);
319
339
for (auto const & h : store_) {
320
340
auto const & resrvs = h->getIPv6Reservations ();
321
341
BOOST_FOREACH (auto const & r, resrvs) {
@@ -330,13 +350,15 @@ MemHostDataSource::getAll6(const asiolink::IOAddress& address) const {
330
350
331
351
void
332
352
MemHostDataSource::add (const HostPtr& host) {
353
+ MultiThreadingLock lock (mutex_);
333
354
host->setHostId (++next_host_id_);
334
355
store_.push_back (host);
335
356
}
336
357
337
358
bool
338
359
MemHostDataSource::del (const SubnetID& subnet_id,
339
360
const asiolink::IOAddress& addr) {
361
+ MultiThreadingLock lock (mutex_);
340
362
for (auto h = store_.begin (); h != store_.end (); ++h) {
341
363
if (addr.isV4 ()) {
342
364
if ((*h)->getIPv4SubnetID () == subnet_id &&
@@ -371,6 +393,7 @@ MemHostDataSource::del4(const SubnetID& subnet_id,
371
393
const uint8_t * identifier_begin,
372
394
const size_t identifier_len) {
373
395
vector<uint8_t > ident (identifier_begin, identifier_begin + identifier_len);
396
+ MultiThreadingLock lock (mutex_);
374
397
for (auto h = store_.begin (); h != store_.end (); ++h) {
375
398
// If either subnet-id or identifier type do not match,
376
399
// it's not our host
@@ -394,6 +417,7 @@ MemHostDataSource::del6(const SubnetID& subnet_id,
394
417
const uint8_t * identifier_begin,
395
418
const size_t identifier_len) {
396
419
vector<uint8_t > ident (identifier_begin, identifier_begin + identifier_len);
420
+ MultiThreadingLock lock (mutex_);
397
421
for (auto h = store_.begin (); h != store_.end (); ++h) {
398
422
// If either subnet-id or identifier type do not match,
399
423
// it's not our host
@@ -412,6 +436,7 @@ MemHostDataSource::del6(const SubnetID& subnet_id,
412
436
413
437
size_t
414
438
MemHostDataSource::size () const {
439
+ MultiThreadingLock lock (mutex_);
415
440
return (store_.size ());
416
441
}
417
442
0 commit comments