1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
|
// $Id$
#if !defined (ACE_MAP_MANAGER_C)
#define ACE_MAP_MANAGER_C
#define ACE_BUILD_DLL
#include "ace/Synch.h"
#include "ace/Malloc.h"
#include "ace/Service_Config.h"
#include "ace/Map_Manager.h"
#if !defined (__ACE_INLINE__)
#include "ace/Map_Manager.i"
#endif /* __ACE_INLINE__ */
ACE_ALLOC_HOOK_DEFINE(ACE_Map_Entry)
template <class EXT_ID, class INT_ID>
ACE_Map_Entry<EXT_ID, INT_ID>::~ACE_Map_Entry (void)
{
// No-op just to keep some compilers happy...
}
template <class EXT_ID, class INT_ID> void
ACE_Map_Entry<EXT_ID, INT_ID>::dump (void) const
{
ACE_TRACE ("ACE_Map_Entry<EXT_ID, INT_ID>::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("is_free_ = %d"), this->is_free_));
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
ACE_ALLOC_HOOK_DEFINE(ACE_Map_Manager)
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("total_size_ = %d"), this->total_size_));
ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("\ncur_size_ = %d"), this->cur_size_));
this->allocator_->dump ();
this->lock_.dump ();
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager (size_t size,
ACE_Allocator *alloc)
: search_structure_ (0),
allocator_ (0),
total_size_ (0),
cur_size_ (0)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager");
if (this->open (size, alloc) == -1)
ACE_ERROR ((LM_ERROR, ASYS_TEXT ("ACE_Map_Manager\n")));
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager (ACE_Allocator *alloc)
: search_structure_ (0),
allocator_ (0),
total_size_ (0),
cur_size_ (0)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Manager");
if (this->open (ACE_DEFAULT_MAP_SIZE, alloc) == -1)
ACE_ERROR ((LM_ERROR, ASYS_TEXT ("ACE_Map_Manager\n")));
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::close_i (void)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::close_i");
this->free_search_structure ();
return 0;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::close (void)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::close");
ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
return this->close_i ();
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::~ACE_Map_Manager (void)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::~ACE_Map_Manager");
this->close ();
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::resize_i (size_t size)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::resize_i");
// If we need to grow buffer, then remove the existing buffer.
void *ptr;
ACE_ALLOCATOR_RETURN (ptr,
this->allocator_->malloc (size * sizeof (ACE_Map_Entry<EXT_ID, INT_ID>)),
-1);
size_t i;
ACE_Map_Entry<EXT_ID, INT_ID> *temp = (ACE_Map_Entry<EXT_ID, INT_ID> *) ptr;
// Copy over the currently active elements.
for (i = 0; i < this->cur_size_; i++)
{
temp[i] = this->search_structure_[i]; // Structure assignment.
}
this->total_size_ = size;
// Mark the newly allocated elements as being "free".
for (i = this->cur_size_; i < this->total_size_; i++)
{
// Call the constructor for each element in the array.
new (&(temp[i])) ACE_Map_Entry<EXT_ID, INT_ID>;
temp[i].is_free_ = 1;
}
this->free_search_structure ();
this->search_structure_ = temp;
return 0;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::begin (void)
{
return ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::end (void)
{
return ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rbegin (void)
{
return ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rend (void)
{
return ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> (*this, 1);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::free_search_structure (void)
{
if (this->search_structure_ != 0)
{
for (size_t i = 0; i < this->total_size_; i++)
// Explicitly call the destructor.
{
ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[i];
ss.ACE_Map_Entry<EXT_ID, INT_ID>::~ACE_Map_Entry ();
}
// Actually free the memory.
this->allocator_->free (this->search_structure_);
this->search_structure_ = 0;
}
}
// Create a new search_structure of size SIZE.
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::open (size_t size,
ACE_Allocator *alloc)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::open");
ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
if (alloc == 0)
alloc = ACE_Allocator::instance ();
this->allocator_ = alloc;
// If we need to grow buffer, then remove the existing buffer.
if (this->total_size_ < size)
return this->resize_i (size);
else
return 0;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_find (const EXT_ID &ext_id,
int &first_free)
{
// See if the entry is already there, keeping track of the first
// free slot.
for (size_t i = 0; i < this->cur_size_; i++)
{
ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[i];
if (ss.is_free_ == 0)
{
if (ss.ext_id_ == ext_id)
return i;
}
else if (first_free == -1)
first_free = int (i);
}
errno = ENOENT;
return -1;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::equal (const EXT_ID &id1,
const EXT_ID &id2)
{
return id1 == id2;
}
// Find the <int_id> corresponding to the <ext_id>.
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_find (const EXT_ID &ext_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_find");
for (size_t i = 0; i < this->cur_size_; i++)
{
const ACE_Map_Entry<EXT_ID, INT_ID> &ss
= this->search_structure_[i];
if (ss.is_free_ == 0 && this->equal (ss.ext_id_, ext_id))
// We found it!
return i;
}
// not found
errno = ENOENT;
return -1;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_bind (const EXT_ID &ext_id,
const INT_ID &int_id,
int first_free)
{
if (first_free > -1)
{
// We found a free spot, let's reuse it.
ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[first_free];
ss.ext_id_ = ext_id;
ss.int_id_ = int_id;
ss.is_free_ = 0;
this->allocator_->sync ((void *) &this->search_structure_[first_free], sizeof ss);
return 0;
}
// Check if we have reached total_size_
else if (this->cur_size_ == this->total_size_)
// We are out of room so grow the map
if (this->resize_i (this->total_size_ + ACE_DEFAULT_MAP_SIZE) == -1)
return -1;
// Insert at the end of the active portion.
ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[this->cur_size_];
ss.int_id_ = int_id;
ss.ext_id_ = ext_id;
ss.is_free_ = 0;
this->allocator_->sync ((void *) &this->search_structure_[this->cur_size_], sizeof ss);
this->cur_size_++;
this->allocator_->sync ((void *) &this->cur_size_, sizeof this->cur_size_);
return 0;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind_i (const EXT_ID &ext_id,
INT_ID &int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind_i");
int first_free = -1;
int index = this->shared_find (ext_id, first_free);
if (index >= 0)
{
// There was already something there, so make a copy, but
// *don't* update anything in the map!
int_id = this->search_structure_[index].int_id_;
return 1;
}
else
// We didn't find it, so let's bind it!
return this->shared_bind (ext_id, int_id, first_free);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind (const EXT_ID &ext_id,
INT_ID &int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::trybind");
ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
return this->trybind_i (ext_id, int_id);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i (const EXT_ID &ext_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i");
return this->shared_find (ext_id);
}
// Find the INT_ID corresponding to the EXT_ID.
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find (const EXT_ID &ext_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find");
ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
return this->find_i (ext_id);
}
// Unbind (remove) the EXT_ID from the map and return it via an out
// parameter. Note that this method does *not* free up the INT_ID
// structure. Thus, if there is dynamic memory associated with this,
// the caller is responsible for freeing this memory.
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i (const EXT_ID &ext_id,
INT_ID &int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i");
ssize_t index = this->shared_unbind (ext_id);
if (index == -1)
return -1;
else
{
int_id = this->search_structure_[index].int_id_;
return 0;
}
}
// Associate <ext_id> with <int_id>. If <ext_id> is already in the
// map then the <Map_Entry> is not changed. Returns 0 if a new
// entry is bound successfully, returns 1 if an attempt is made to
// bind an existing entry, and returns -1 if failures occur.
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind_i (const EXT_ID &ext_id,
const INT_ID &int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind_i");
int first_free = -1;
// We need to save errno since <shared_find> may set errno to
// ENOENT.
int error = errno;
int index = this->shared_find (ext_id, first_free);
if (index >= 0)
// It was already bound, so return 1.
return 1;
else
{
// Restore errno.
errno = error;
// We didn't find it, so let's bind it!
return this->shared_bind (ext_id, int_id, first_free);
}
}
// Associate <ext_id> with <int_id>. If <ext_id> is not in the
// map then behaves just like <bind>. Otherwise, store the old
// values of <ext_id> and <int_id> into the "out" parameters and
// rebind the new parameters. This is very useful if you need to
// have an atomic way of updating <Map_Entries> and you also need
// full control over memory allocation. Returns 0 if a new entry is
// bound successfully, returns 1 if an existing entry was rebound,
// and returns -1 if failures occur.
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind_i (const EXT_ID &ext_id,
const INT_ID &int_id,
EXT_ID &old_ext_id,
INT_ID &old_int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind_i");
int first_free = -1;
int index = this->shared_find (ext_id, first_free);
if (index >= 0)
{
// We found it, so make copies of the old entries and rebind
// current entries.
ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[index];
old_ext_id = ss.ext_id_;
old_int_id = ss.int_id_;
ss.ext_id_ = ext_id;
ss.int_id_ = int_id;
this->allocator_->sync ((void *) &this->search_structure_[index], sizeof ss);
return 1;
}
else
// We didn't find it, so let's bind it!
return this->shared_bind (ext_id, int_id, first_free);
}
// Find the INT_ID corresponding to the EXT_ID.
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i (const EXT_ID &ext_id,
INT_ID &int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find_i");
int index = this->shared_find (ext_id);
if (index == -1)
// Didn't find it.
return -1;
else
{
// Found it, so assign a copy.
int_id = this->search_structure_[index].int_id_;
return index;
}
}
// Unbind (remove) the EXT_ID from the map. Keeps track of where
// the EXT_ID was found so that this->unbind (EXT_ID, INT_ID)
// can return it to the caller.
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_unbind (const EXT_ID &ext_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::shared_unbind");
for (size_t i = 0; i < this->cur_size_; i++)
{
ACE_Map_Entry<EXT_ID, INT_ID> &ss = this->search_structure_[i];
if (ss.is_free_ == 0 && this->equal (ss.ext_id_, ext_id))
{
size_t index = i;
// Mark this entry as being free.
ss.is_free_ = 1;
this->allocator_->sync ((void *) &ss.is_free_,
sizeof ss.is_free_);
// If we just unbound the highest active entry, then we need
// to figure out where the next highest active entry is.
if (i + 1 == this->cur_size_)
{
while (i > 0 && this->search_structure_[--i].is_free_)
continue;
if (i == 0 && this->search_structure_[i].is_free_)
this->cur_size_ = 0;
else
this->cur_size_ = i + 1;
this->allocator_->sync ((void *) &this->cur_size_,
sizeof this->cur_size_);
}
return index;
}
}
errno = ENOENT;
return -1;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind (const EXT_ID &ext_id,
INT_ID &int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind");
ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
return this->unbind_i (ext_id, int_id);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind (const EXT_ID &ext_id,
const INT_ID &int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::bind");
ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
return this->bind_i (ext_id, int_id);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind (const EXT_ID &ext_id,
const INT_ID &int_id,
EXT_ID &old_ext_id,
INT_ID &old_int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::rebind");
ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
return this->rebind_i (ext_id, int_id, old_ext_id, old_int_id);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find (const EXT_ID &ext_id,
INT_ID &int_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::find");
ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
return this->find_i (ext_id, int_id);
}
// Unbind (remove) the EXT_ID from the map. Don't return the INT_ID
// to the caller (this is useful for collections where the INT_IDs are
// *not* dynamically allocated...)
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i (const EXT_ID &ext_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind_i");
return this->shared_unbind (ext_id) == -1 ? -1 : 0;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind (const EXT_ID &ext_id)
{
ACE_TRACE ("ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::unbind");
ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_, -1);
return this->unbind_i (ext_id) == -1 ? -1 : 0;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> size_t
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::current_size (void)
{
ACE_TRACE ("ACE_Map_Manager::current_size");
ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_,
ACE_static_cast(size_t, -1));
return this->cur_size_;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> size_t
ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK>::total_size (void)
{
ACE_TRACE ("ACE_Map_Manager::total_size");
ACE_WRITE_GUARD_RETURN (ACE_LOCK, ace_mon, this->lock_,
ACE_static_cast(size_t, -1));
return this->total_size_;
}
// @@ && @@
ACE_ALLOC_HOOK_DEFINE(ACE_Map_Iterator_Base)
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::dump_i (void) const
{
ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::dump");
ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));
ACE_DEBUG ((LM_DEBUG, ASYS_TEXT ("next_ = %d"), this->next_));
ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator_Base (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm, int head)
: map_man_ (&mm),
next_ (-1)
{
ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator_Base");
if (head == 0)
this->next_ = this->map_man_->cur_size_;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::next (ACE_Map_Entry<EXT_ID, INT_ID> *&mm)
{
ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::next");
ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
if (this->map_man_->search_structure_ != 0
// Note that this->next_ is never negative at this point...
&& ACE_static_cast(size_t, this->next_) < this->map_man_->cur_size_
&& this->next_ > -1)
{
mm = &this->map_man_->search_structure_[this->next_];
return 1;
}
else
return 0;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::done (void) const
{
ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::done");
ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
return this->map_man_->search_structure_ == 0
// Note that this->next_ is never negative at this point...
|| ACE_static_cast (size_t, this->next_) >= this->map_man_->cur_size_
|| this->next_ <= -1;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::forward_i (void)
{
ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::forward_i");
ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
for (++this->next_;
ACE_static_cast(size_t, this->next_) < this->map_man_->cur_size_
&& this->map_man_->search_structure_[this->next_].is_free_;
this->next_++)
continue;
return ACE_static_cast(size_t, this->next_) < this->map_man_->cur_size_;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::reverse_i (void)
{
ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::reverse_i");
ACE_READ_GUARD_RETURN (ACE_LOCK, ace_mon, this->map_man_->lock_, -1);
for (--this->next_;
this->next_ >= 0
&& this->map_man_->search_structure_[this->next_].is_free_;
this->next_--)
continue;
return this->next_ >= 0;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Entry<EXT_ID, INT_ID>&
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator* (void)
{
ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator*");
ACE_Map_Entry<EXT_ID, INT_ID> *retv;
ACE_ASSERT (this->next (retv) != 0);
return *retv;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator== (const ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
{
ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator==");
return (this->map_man_ == rhs.map_man_ && this->next_ == rhs.next_);
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator!= (const ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> &rhs) const
{
ACE_TRACE ("ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK>::operator!=");
return (this->next_ != rhs.next_ || this->map_man_ != rhs.map_man_);
}
ACE_ALLOC_HOOK_DEFINE(ACE_Map_Iterator)
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
{
ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump");
this->dump_i ();
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm, int tail)
: ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm, (tail == 0 ? 1 : 0))
{
ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Iterator");
if (tail == 0 && this->map_man_->search_structure_ != 0)
this->forward_i ();
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
{
ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance");
return this->forward_i ();
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)
{
ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)")
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
this->forward_i ();
return retv;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>&
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)
{
ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)")
this->forward_i ();
return *this;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)
{
ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)")
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
this->reverse_i ();
return retv;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>&
ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
{
ACE_TRACE ("ACE_Map_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)")
this->reverse_i ();
return *this;
}
ACE_ALLOC_HOOK_DEFINE(ACE_Map_Reverse_Iterator)
template <class EXT_ID, class INT_ID, class ACE_LOCK> void
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump (void) const
{
ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::dump");
this->dump_i ();
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Reverse_Iterator (ACE_Map_Manager<EXT_ID, INT_ID, ACE_LOCK> &mm, int head)
: ACE_Map_Iterator_Base<EXT_ID, INT_ID, ACE_LOCK> (mm, head)
{
ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::ACE_Map_Reverse_Iterator");
if (head == 0 && this->map_man_->search_structure_ != 0)
this->reverse_i ();
}
template <class EXT_ID, class INT_ID, class ACE_LOCK> int
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance (void)
{
ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::advance");
return this->reverse_i ();
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)
{
ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (void)");
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
this->reverse_i ();
return retv;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>&
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)
{
ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator++ (int)");
this->reverse_i ();
return *this;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)
{
ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (void)");
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK> retv (*this);
this->forward_i ();
return retv;
}
template <class EXT_ID, class INT_ID, class ACE_LOCK>
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>&
ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)
{
ACE_TRACE ("ACE_Map_Reverse_Iterator<EXT_ID, INT_ID, ACE_LOCK>::operator-- (int)");
this->forward_i ();
return *this;
}
#endif /* ACE_MAP_MANAGER_C */
|