NeoPZ
pzadmchunkthreadsafe.h
Go to the documentation of this file.
1 
6 #ifndef PZADMCHUNKTHREADSAFE_H
7 #define PZADMCHUNKTHREADSAFE_H
8 
9 #include "pzadmchunk.h"
10 #include <pthread.h>
11 
12 class TPZSavable;
13 
14 template <class T,int EXP=10>
16 {
17  public :
19 
21 
23 
25 
26  int AllocateNewElement();
27 
28  void SetFree(int index);
29 
30  int NFreeElements();
31 
32  int NElements() const;
33 
34  void CompactDataStructure(int type=2);
35 
36  int PrintFree(int i);
37 
38  void Resize(const int newsize);
39 
40  T &operator[](const int nelem) const;
41 
42  int FindObject(T *obj);
43 
44 private:
45 
46  mutable pthread_mutex_t fAdmChunkVectorLock;
47 
48 };
49 
50 //--| IMPLEMENTATION |----------------------------------------------------------
51 
52 template< class T , int EXP>
54  pthread_mutex_lock(&fAdmChunkVectorLock);
56  pthread_mutex_unlock(&fAdmChunkVectorLock);
57 
58  return resul;
59 }
60 
61 template< class T , int EXP>
63  pthread_mutex_lock(&fAdmChunkVectorLock);
65  pthread_mutex_unlock(&fAdmChunkVectorLock);
66 
67  return resul;
68 }
69 
70 template< class T , int EXP>
72  pthread_mutex_lock(&fAdmChunkVectorLock);
74  pthread_mutex_unlock(&fAdmChunkVectorLock);
75 
76  return resul;
77 }
78 
79 template< class T , int EXP>
81 {
82  pthread_mutex_init(&fAdmChunkVectorLock, NULL);
83 }
84 
85 template< class T, int EXP >
87 {
88  pthread_mutex_destroy(&fAdmChunkVectorLock);
89 }
90 
91 template< class T,int EXP >
93 {
94  pthread_mutex_lock(&fAdmChunkVectorLock);
96  pthread_mutex_unlock(&fAdmChunkVectorLock);
97 
98  return resul;
99 }
100 
101 template< class T,int EXP >
103  pthread_mutex_lock(&fAdmChunkVectorLock);
105  pthread_mutex_unlock(&fAdmChunkVectorLock);
106 }
107 
108 template< class T, int EXP >
110  pthread_mutex_lock(&fAdmChunkVectorLock);
112  pthread_mutex_unlock(&fAdmChunkVectorLock);
113 }
114 
115 template < class T,int EXP >
117 {
118  pthread_mutex_init(&fAdmChunkVectorLock, NULL);
119 }
120 
121 template < class T , int EXP>
123 {
124  pthread_mutex_lock(&fAdmChunkVectorLock);
126  pthread_mutex_unlock(&fAdmChunkVectorLock);
127  return resul;
128 }
129 
130 template< class T, int EXP >
132  pthread_mutex_lock(&fAdmChunkVectorLock);
134  pthread_mutex_unlock(&fAdmChunkVectorLock);
135 }
136 
137 template< class T, int EXP >
138 inline T &TPZAdmChunkVectorThreadSafe<T,EXP>::operator[](const int nelem) const {
139  pthread_mutex_lock(&fAdmChunkVectorLock);
140  T &resul = TPZChunkVector<T,EXP>::operator[](nelem);
141  pthread_mutex_unlock(&fAdmChunkVectorLock);
142 
143  return resul;
144 }
145 
146 template<class T, int EXP>
148  pthread_mutex_lock(&fAdmChunkVectorLock);
149  int resul = TPZChunkVector<T,EXP>::FindObject(obj);
150  pthread_mutex_unlock(&fAdmChunkVectorLock);
151 
152  return resul;
153 }
154 
155 
156 #endif // PZADMCHUNKTHREADSAFE_H
157 
158 //--| PZ |----------------------------------------------------------------------
#define DEFAULTNUMBEROFCHUNKS
Default number of elements which will be allocated in the chunk vector.
int AllocateNewElement()
Makes more room for new elements.
Definition: pzadmchunk.h:184
T & operator[](const int64_t nelem) const
Returns a reference to the ith element of the vector.
TPZAdmChunkVectorThreadSafe< T, EXP > & operator=(const TPZAdmChunkVectorThreadSafe< T, EXP > &TPZAdmCh)
Declarates the TPZBlock<REAL>class which implements block matrices.
int PrintFree(int i)
Print index i into the fFree vector.
Definition: pzadmchunk.h:104
int64_t NElements() const
Access method to query the number of elements of the vector.
Implements a chunk vector with free store administration. Utility.
Definition: TPZStream.h:39
int64_t FindObject(T *object)
Finds the index of an object by its pointer.
void Resize(const int newsize)
Increase the size of the chunk vector.
Definition: pzadmchunk.h:280
TPZAdmChunkVectorThreadSafe(const TPZAdmChunkVectorThreadSafe< T, EXP > &AdmCh)
int64_t NFreeElements() const
Access method to return the number of free elements.
Definition: pzadmchunk.h:87
void CompactDataStructure(CompactScheme type=CompactScheme::ALWAYS)
Sets the method to compact the data structure based on the.
Definition: pzadmchunk.h:222
T & operator[](const int nelem) const
void SetFree(int index)
Indicate an element as free.
Definition: pzadmchunk.h:199
void Resize(const int newsize)
This class defines the interface to save and restore objects from TPZStream objects. Persistency.
Definition: TPZSavable.h:67
obj
Definition: test.py:225