idmap.inc

Go to the documentation of this file.
00001 
00029 #include "abacus/master.h"
00030 #include "abacus/id.h"
00031 #include "abacus/hash.h"
00032 
00033 template <class Type> 
00034   ABA_IDMAP<Type>::ABA_IDMAP(ABA_MASTER *master, int size, int index)
00035     :
00036     master_(master),  
00037     map_(master, size),  
00038     sequence_(1),  
00039     index_(index)
00040   {
00041     proc_ = master->parmaster()->hostId();
00042   }
00043 
00044   template <class Type> 
00045   ABA_IDMAP<Type>::~ABA_IDMAP()
00046   {
00047   }
00048 
00049   template <class Type>
00050   ostream& operator<<(ostream &out, const ABA_IDMAP<Type> &idmap)
00051   {
00052     idmap.mp_.acquire();
00053 
00054     out << "ABA_IDMAP: proc=" << idmap.proc_
00055         << ", sequence=" << idmap.sequence_
00056         << endl;
00057     out << idmap.map_;
00058 
00059     idmap.mp_.release();
00060     return out;
00061   }
00062 
00063   template<class Type>
00064   Type *ABA_IDMAP<Type>::find(const ABA_ID &id)
00065   {
00066     mp_.acquire();
00067 
00068     const Type **ptr = map_.find(id);
00069 
00070     mp_.release();
00071     return ptr ? (Type*)(*ptr) : 0;
00072   }
00073 
00074   template<class Type>
00075   void ABA_IDMAP<Type>::insert(const ABA_ID &id, const Type *obj)
00076   {
00077     mp_.acquire();
00078 
00079 #ifdef ABACUSSAFE
00080     if (map_.find(id)) {
00081       master_->err() << "ABA_IDMAP::insert(): tried to insert ABA_ID "
00082                      << id << " more than once.";
00083       exit(Fatal);
00084     }
00085 #endif
00086 
00087     map_.insert(id, obj);
00088 
00089     mp_.release();
00090   }
00091 
00092 extern "C" {
00093 #include <limits.h>     
00094 }
00095   template<class Type>
00096   void ABA_IDMAP<Type>::insertWithNewId(ABA_ID &id, const Type *obj)
00097   {
00098     mp_.acquire();
00099 
00100     if (sequence_ == ULONG_MAX) {
00101       master_->err() << "ABA_IDMAP::insertWithNewId(): insertion failed, "
00102                         "maximum sequence number ULONG_MAX = "
00103                      << ULONG_MAX << " reached";
00104       exit (Fatal);
00105     }
00106     id.initialize(sequence_++, proc_, index_);
00107 
00108 #ifdef ABACUSSAFE
00109     if (map_.find(id)) {
00110       master_->err() << "ABA_IDMAP::insertWithNewId(): tried to insert ABA_ID "
00111                      << id << " more than once.";
00112       exit(Fatal);
00113     }
00114 #endif
00115 
00116     map_.insert(id, obj);
00117     mp_.release();
00118   }
00119 
00120   template<class Type>
00121   int ABA_IDMAP<Type>::remove(const ABA_ID &id)
00122   {
00123     mp_.acquire();
00124     int status = map_.remove(id);
00125     mp_.release();
00126     return status;
00127   }

Generated on Tue Aug 14 18:09:53 2007 for ABACUS by  doxygen 1.5.1