Changeset 3208 in Sophya for trunk/SophyaLib/BaseTools
- Timestamp:
- Apr 10, 2007, 5:57:02 PM (18 years ago)
- Location:
- trunk/SophyaLib/BaseTools
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/BaseTools/datatype.cc
r2884 r3208 14 14 { 15 15 } 16 #if defined(__SGICC__) || defined(__IBMCPP__) 17 template <class T> 18 string DataTypeInfo<T>::getTypeName() 19 { 20 if (typeid(T) == typeid(uint_1)) return("uint_1"); 21 else if (typeid(T) == typeid(uint_2)) return("uint_2"); 22 else if (typeid(T) == typeid(int_2)) return("int_2"); 23 else if (typeid(T) == typeid(int_4)) return("int_4"); 24 else if (typeid(T) == typeid(int_8)) return("int_8"); 25 else if (typeid(T) == typeid(uint_4)) return("uint_4"); 26 else if (typeid(T) == typeid(uint_8)) return("uint_8"); 27 else if (typeid(T) == typeid(r_4)) return("r_4"); 28 else if (typeid(T) == typeid(r_8)) return("r_8"); 29 else if (typeid(T) == typeid(complex<r_4>)) return(" complex<r_4> "); 30 else if (typeid(T) == typeid(complex<r_8>)) return(" complex<r_8> "); 31 else return("???unknowntype???"); 32 } 33 #else 16 //! Return the type name of T, as a string, (Example: T=uint_8 --> "uint_8") 34 17 template <class T> 35 18 string DataTypeInfo<T>::getTypeName() { return("???unknowntype???"); } … … 37 20 string DataTypeInfo<uint_1>::getTypeName() { return("uint_1"); } 38 21 DECL_TEMP_SPEC 22 string DataTypeInfo<int_1>::getTypeName() { return("int_1"); } 23 DECL_TEMP_SPEC 39 24 string DataTypeInfo<uint_2>::getTypeName() { return("uint_2"); } 40 25 DECL_TEMP_SPEC 41 26 string DataTypeInfo<int_2>::getTypeName() { return("int_2"); } 42 27 DECL_TEMP_SPEC 28 string DataTypeInfo<uint_4>::getTypeName() { return("uint_4"); } 29 DECL_TEMP_SPEC 43 30 string DataTypeInfo<int_4>::getTypeName() { return("int_4"); } 44 31 DECL_TEMP_SPEC 32 string DataTypeInfo<uint_8>::getTypeName() { return("uint_8"); } 33 DECL_TEMP_SPEC 45 34 string DataTypeInfo<int_8>::getTypeName() { return("int_8"); } 46 DECL_TEMP_SPEC47 string DataTypeInfo<uint_4>::getTypeName() { return("uint_4"); }48 DECL_TEMP_SPEC49 string DataTypeInfo<uint_8>::getTypeName() { return("uint_8"); }50 35 DECL_TEMP_SPEC 51 36 string DataTypeInfo<r_4>::getTypeName() { return("r_4"); } … … 56 41 DECL_TEMP_SPEC 57 42 string DataTypeInfo< complex<r_8> >::getTypeName() { return(" complex<r_8> "); } 58 #endif 43 44 /*! 45 \ brief Return an identifier associated to T 46 uint_1 -> 1 , int_1 -> 2 47 uint_2 -> 3 , int_2 -> 4 48 uint_4 -> 5 , int_4 -> 6 49 uint_8 -> 7 , int_8 -> 8 50 r_4 -> 9 , r_8 -> 10 51 complex<r_4> -> 11 , complex<r_8> -> 12 52 */ 53 template <class T> 54 int DataTypeInfo<T>::getTypeId() { return(0); } 55 DECL_TEMP_SPEC 56 int DataTypeInfo<uint_1>::getTypeId() { return(1); } 57 DECL_TEMP_SPEC 58 int DataTypeInfo<int_1>::getTypeId() { return(2); } 59 DECL_TEMP_SPEC 60 int DataTypeInfo<uint_2>::getTypeId() { return(3); } 61 DECL_TEMP_SPEC 62 int DataTypeInfo<int_2>::getTypeId() { return(4); } 63 DECL_TEMP_SPEC 64 int DataTypeInfo<uint_4>::getTypeId() { return(5); } 65 DECL_TEMP_SPEC 66 int DataTypeInfo<int_4>::getTypeId() { return(6); } 67 DECL_TEMP_SPEC 68 int DataTypeInfo<uint_8>::getTypeId() { return(7); } 69 DECL_TEMP_SPEC 70 int DataTypeInfo<int_8>::getTypeId() { return(8); } 71 DECL_TEMP_SPEC 72 int DataTypeInfo<r_4>::getTypeId() { return(9); } 73 DECL_TEMP_SPEC 74 int DataTypeInfo<r_8>::getTypeId() { return(10); } 75 DECL_TEMP_SPEC 76 int DataTypeInfo< complex<r_4> >::getTypeId() { return(11); } 77 DECL_TEMP_SPEC 78 int DataTypeInfo< complex<r_8> >::getTypeId() { return(12); } 79 59 80 60 81 … … 115 136 #ifdef __CXX_PRAGMA_TEMPLATES__ 116 137 #pragma define_template DataTypeInfo<uint_1> 138 #pragma define_template DataTypeInfo<int_1> 117 139 #pragma define_template DataTypeInfo<uint_2> 118 140 #pragma define_template DataTypeInfo<int_2> … … 130 152 namespace SOPHYA { 131 153 template class DataTypeInfo<uint_1>; 154 template class DataTypeInfo<int_1>; 132 155 template class DataTypeInfo<uint_2>; 133 156 template class DataTypeInfo<int_2>; -
trunk/SophyaLib/BaseTools/datatype.h
r1238 r3208 13 13 namespace SOPHYA { 14 14 15 //! class returning type name for usual numrical types (int_2,int_4,r_4,r_8 ...) 15 16 template <class T> 16 17 class DataTypeInfo { 17 18 public: 18 19 static string getTypeName(); 20 static int getTypeId(); 19 21 DataTypeInfo(); 20 22 }; -
trunk/SophyaLib/BaseTools/ndatablock.cc
r3113 r3208 32 32 template <class T> size_t NDataBlock<T>::NallocData = 0; 33 33 template <class T> size_t NDataBlock<T>::NallocSRef = 0; 34 template <class T> ThSafeOp* NDataBlock<T>::gThsop = NULL; 34 35 35 36 //! Set debug (and level print) for allocation and references debug. … … 88 89 if(Debug_NDataBlock>1) 89 90 cout<<"?_NDataBlock::NDataBlock("<<this<<",n="<<n<<")"<<endl; 91 if (gThsop == NULL) gThsop = new ThSafeOp; 90 92 91 93 Alloc(n, NULL, NULL, fzero); // allocation et mise a zero … … 107 109 cout<<"?_NDataBlock::NDataBlock("<<this 108 110 <<",data="<<data<<",br="<<br<<")"<<endl; 111 if (gThsop == NULL) gThsop = new ThSafeOp; 109 112 110 113 Alloc(n,data,br); … … 119 122 if(Debug_NDataBlock>1) 120 123 cout<<"?_NDataBlock::NDataBlock("<<this<<") default"<<endl; 124 if (gThsop == NULL) gThsop = new ThSafeOp; 121 125 } 122 126 … … 160 164 cout<<"?_NDataBlock::~NDataBlock("<<this<<")"<<endl; 161 165 162 De lete();166 Dealloc(); // ThreadSafe version of Delete() 163 167 } 164 168 … … 197 201 if(&a==NULL) throw(NullPtrError("NDataBlock::Share &a==NULL\n")); 198 202 if(!a.mSRef || a.mSz==0) throw(NullPtrError("NDataBlock::Share a.mSz=0\n")); 203 //--- Start of atomic (in one block) operation for thread safety 204 gThsop->lock(); // (ThreadSafe) 199 205 if(mSRef) Delete(); 200 206 mSz = a.mSz; mSRef = a.mSRef; mSRef->nref++; 207 gThsop->unlock(); // (ThreadSafe) 208 //--- End of atomic operation 201 209 202 210 if(Debug_NDataBlock>1) … … 330 338 throw(NullPtrError("NDataBlock::Alloc br!=NULL && data==NULL\n")); 331 339 if(n==0) throw(SzMismatchError("NDataBlock::Alloc n==0\n")); 340 //--- Start of atomic (in one block) operation for thread safety (ThreadSafe) 341 gThsop->lock(); // (ThreadSafe) 332 342 if(mSRef) Delete(); 333 343 mSz = n; … … 338 348 else {mSRef->data = new T[n]; if (zero) memset(mSRef->data,0,n*sizeof(T));} 339 349 mSRef->bridge = br; 350 gThsop->unlock(); // (ThreadSafe) 351 //--- End of atomic operation (ThreadSafe) 340 352 341 353 if(Debug_NDataBlock>0) { … … 354 366 } 355 367 356 //! Management of de-allocation 368 //! Management of de-allocation (NOT thread-safe) 357 369 template <class T> 358 370 void NDataBlock<T>::Delete(void) … … 460 472 } 461 473 474 /*! 475 \brief Calls the protected Delete() method to set the size to zero 476 This is the public - thread safe version - of the Delete() method 477 The memory is freed if last referenced structure. 478 */ 479 template <class T> 480 void NDataBlock<T>::Dealloc() 481 { 482 gThsop->lock(); 483 Delete(); 484 gThsop->unlock(); 485 } 486 462 487 //////////////// 463 488 // Impression // -
trunk/SophyaLib/BaseTools/ndatablock.h
r3172 r3208 10 10 #include "anydataobj.h" 11 11 #include <iostream> 12 13 #include "thsafeop.h" /* For thread safe operation (Ref.Count/Share) */ 12 14 13 15 namespace SOPHYA { … … 88 90 void Realloc(size_t nnew,bool force=false); 89 91 90 // ! Calls Delete() to set the size to zero (The memory is freed if last referenced structure)91 inline void Dealloc() { Delete(); }92 // Public, thread safe interface to Delete() (set the size to zero) 93 void Dealloc(); 92 94 93 95 // Informations pointeur/data … … 172 174 static size_t NallocData; //!< DEBUG: number of allocations (all type<T> classes) 173 175 static size_t NallocSRef; //!< DEBUG: number of references (all type<T> classes) 176 static ThSafeOp* gThsop; //!< DEBUG: for thread safe operation 174 177 175 178 size_t mSz; //!< size of data structure
Note:
See TracChangeset
for help on using the changeset viewer.