@@ -385,6 +385,10 @@ class rw_trx_hash_t
385
385
LF_HASH hash;
386
386
387
387
388
+ template <typename T>
389
+ using walk_action= my_bool(rw_trx_hash_element_t *element, T *action);
390
+
391
+
388
392
/* *
389
393
Constructor callback for lock-free allocator.
390
394
@@ -487,18 +491,19 @@ class rw_trx_hash_t
487
491
}
488
492
489
493
490
- struct eliminate_duplicates_arg
494
+ template < typename T> struct eliminate_duplicates_arg
491
495
{
492
496
trx_ids_t ids;
493
- my_hash_walk_action action;
494
- void *argument;
495
- eliminate_duplicates_arg (size_t size, my_hash_walk_action act, void * arg):
497
+ walk_action<T> * action;
498
+ T *argument;
499
+ eliminate_duplicates_arg (size_t size, walk_action<T> * act, T * arg):
496
500
action (act), argument(arg) { ids.reserve (size); }
497
501
};
498
502
499
503
504
+ template <typename T>
500
505
static my_bool eliminate_duplicates (rw_trx_hash_element_t *element,
501
- eliminate_duplicates_arg *arg)
506
+ eliminate_duplicates_arg<T> *arg)
502
507
{
503
508
for (trx_ids_t ::iterator it= arg->ids .begin (); it != arg->ids .end (); it++)
504
509
{
@@ -525,15 +530,16 @@ class rw_trx_hash_t
525
530
}
526
531
527
532
528
- struct debug_iterator_arg
533
+ template < typename T> struct debug_iterator_arg
529
534
{
530
- my_hash_walk_action action;
531
- void *argument;
535
+ walk_action<T> * action;
536
+ T *argument;
532
537
};
533
538
534
539
540
+ template <typename T>
535
541
static my_bool debug_iterator (rw_trx_hash_element_t *element,
536
- debug_iterator_arg *arg)
542
+ debug_iterator_arg<T> *arg)
537
543
{
538
544
mutex_enter (&element->mutex );
539
545
if (element->trx )
@@ -748,23 +754,28 @@ class rw_trx_hash_t
748
754
@retval 1 iteration was interrupted (action returned 1)
749
755
*/
750
756
751
- int iterate(trx_t *caller_trx, my_hash_walk_action action, void *argument)
757
+ template <typename T>
758
+ int iterate(trx_t *caller_trx, walk_action<T> *action, T *argument= nullptr )
752
759
{
753
760
LF_PINS *pins= caller_trx ? get_pins (caller_trx) : lf_hash_get_pins (&hash);
754
761
ut_a (pins);
755
762
#ifdef UNIV_DEBUG
756
- debug_iterator_arg debug_arg= { action, argument };
757
- action= reinterpret_cast <my_hash_walk_action >(debug_iterator);
758
- argument= &debug_arg;
763
+ debug_iterator_arg<T> debug_arg= { action, argument };
764
+ action= reinterpret_cast <decltype (action) >(debug_iterator<T> );
765
+ argument= reinterpret_cast <T*>( &debug_arg) ;
759
766
#endif
760
- int res= lf_hash_iterate (&hash, pins, action, argument);
767
+ int res= lf_hash_iterate (&hash, pins,
768
+ reinterpret_cast <my_hash_walk_action>(action),
769
+ const_cast <void *>(static_cast <const void *>
770
+ (argument)));
761
771
if (!caller_trx)
762
772
lf_hash_put_pins (pins);
763
773
return res;
764
774
}
765
775
766
776
767
- int iterate(my_hash_walk_action action, void *argument)
777
+ template <typename T>
778
+ int iterate(walk_action<T> *action, T *argument= nullptr )
768
779
{
769
780
return iterate(current_trx (), action, argument);
770
781
}
@@ -776,16 +787,17 @@ class rw_trx_hash_t
776
787
@sa iterate()
777
788
*/
778
789
779
- int iterate_no_dups (trx_t *caller_trx, my_hash_walk_action action,
780
- void *argument)
790
+ template <typename T>
791
+ int iterate_no_dups (trx_t *caller_trx, walk_action<T> *action,
792
+ T *argument= nullptr )
781
793
{
782
- eliminate_duplicates_arg arg (size () + 32 , action, argument);
783
- return iterate(caller_trx, reinterpret_cast <my_hash_walk_action>
784
- (eliminate_duplicates), &arg);
794
+ eliminate_duplicates_arg<T> arg (size () + 32 , action, argument);
795
+ return iterate(caller_trx, eliminate_duplicates<T>, &arg);
785
796
}
786
797
787
798
788
- int iterate_no_dups (my_hash_walk_action action, void *argument)
799
+ template <typename T>
800
+ int iterate_no_dups (walk_action<T> *action, T *argument= nullptr )
789
801
{
790
802
return iterate_no_dups (current_trx (), action, argument);
791
803
}
@@ -881,8 +893,7 @@ class trx_sys_t
881
893
trx_id_t get_min_trx_id ()
882
894
{
883
895
trx_id_t id= get_max_trx_id ();
884
- rw_trx_hash.iterate(reinterpret_cast <my_hash_walk_action>
885
- (get_min_trx_id_callback), &id);
896
+ rw_trx_hash.iterate(get_min_trx_id_callback, &id);
886
897
return id;
887
898
}
888
899
@@ -976,9 +987,7 @@ class trx_sys_t
976
987
977
988
ids->clear ();
978
989
ids->reserve (rw_trx_hash.size () + 32 );
979
- rw_trx_hash.iterate(caller_trx,
980
- reinterpret_cast <my_hash_walk_action>(copy_one_id),
981
- &arg);
990
+ rw_trx_hash.iterate(caller_trx, copy_one_id, &arg);
982
991
983
992
*max_trx_id= arg.m_id ;
984
993
*min_trx_no= arg.m_no ;
0 commit comments