STLdb

PrevUpHomeNext

Class template trans_assoc_iterator

stldb::concurrent::trans_assoc_iterator

Synopsis

// In header: </Users/bobw/workspace/stldb_lib/stldb/containers/concurrent_trans_assoc_iterator.h>

template<typename container_t, typename base_iterator, typename lock_type> 
class trans_assoc_iterator {
public:
  // types
  typedef iterator_traits< base_iterator >::value_type              value_type;          
  typedef iterator_traits< base_iterator >::value_type::first_type  K;                   
  typedef iterator_traits< base_iterator >::value_type::second_type V;                   
  typedef container_t::pending_change_map_t                         pending_change_map_t;
  typedef container_t::picket_lock_t                                picket_lock_t;       
  typedef value_type &                                              reference;           
  typedef value_type *                                              pointer;             

  // member classes/structs/unions

  struct lock_info {
    // construct/copy/destruct
    lock_info();
    lock_info(const lock_info &);

    // public member functions
    void lock(container_t *, const base_iterator &) ;
    void move_lock(base_iterator &, lock_type &) ;
    void unlock() ;
    lock_type _lock;
    base_iterator _current_pos;
  };

  // construct/copy/destruct
  trans_assoc_iterator();
  trans_assoc_iterator(base_iterator, container_t *, lock_type &);
  trans_assoc_iterator(base_iterator, container_t *);
  trans_assoc_iterator(base_iterator, container_t *, Transaction &, 
                       lock_type &);
  trans_assoc_iterator(base_iterator, container_t *, Transaction &);
  trans_assoc_iterator(const trans_assoc_iterator &);
  ~trans_assoc_iterator();

  // public member functions
  reference operator*() const;
  pointer operator->() const;
  trans_assoc_iterator & operator++() ;
  trans_assoc_iterator & operator--() ;
  trans_assoc_iterator operator++(int) ;
  trans_assoc_iterator operator--(int) ;
  base_iterator & base() ;
  bool valid() const;
  bool lock() const;
  bool lock() ;
  void unlock() const;
  bool locked() const;
  lock_type & lock_held() ;

  // private static functions
  static lock_info * thread_lockinfo(container_t *) ;

  // private member functions
  void forward(int) ;
  void backward(int) ;
};

Description

This is an iterator adapter which will work for any associative iterator type in which the value type of the base iterator is pair<const K,transEntry<V>> for any K,V.

This adapter provides a transactionally aware iterator which keeps transactions isolated from each other.

First, the iterator will skip over any uncomitted data, or any uncomitted data not associated with the transaction that the iterator was constructed with. This provides a consistent view of the data in the map.

Finally, when the iterator lands on an entry which has been modified by the current transaction, it composes a value_type entry which has the key and the pending update value on it, and returns references to that pair. In this case, the pair being seen is not actually in the map, but is rather a pending change.

trans_assoc_iterator public construct/copy/destruct

  1. trans_assoc_iterator();

    TODO: There seems to be a bug with boost::interprocess::map<>, because although map::value_type is pair<const K, V>, it seems that map::iterator::operator* is returning pair<K,V>, in violation of current C++ standards. The workaround are the reinterpret casts seen below and in the tcc.

  2. trans_assoc_iterator(base_iterator i, container_t * container, 
                         lock_type & already_held);
  3. trans_assoc_iterator(base_iterator i, container_t * container);
  4. trans_assoc_iterator(base_iterator i, container_t * container, 
                         Transaction & trans, lock_type & already_held);
  5. trans_assoc_iterator(base_iterator i, container_t * container, 
                         Transaction & trans);
  6. trans_assoc_iterator(const trans_assoc_iterator & rarg);
  7. ~trans_assoc_iterator();

trans_assoc_iterator public member functions

  1. reference operator*() const;
  2. pointer operator->() const;
  3. trans_assoc_iterator & operator++() ;
  4. trans_assoc_iterator & operator--() ;
  5. trans_assoc_iterator operator++(int n) ;
  6. trans_assoc_iterator operator--(int n) ;
  7. base_iterator & base() ;
  8. bool valid() const;
  9. bool lock() const;

    Acquire the lock on the appropriate mutex for this entry, if it is not already held. This method is idempotent, but NOT recursive.

  10. bool lock() ;
  11. void unlock() const;

    Release the lock on the mutex for this entry, if one is held. This method is idempotent, but not recursive.

  12. bool locked() const;

    Return true if the entry pointed to by this iterator is currently locked with the appropriate mutex from the picket lock.

  13. lock_type & lock_held() ;

trans_assoc_iterator private static functions

  1. static lock_info * thread_lockinfo(container_t * container) ;

trans_assoc_iterator private member functions

  1. void forward(int n) ;
  2. void backward(int n) ;

PrevUpHomeNext