FemProcess
The GeMA Fem Process Plugin
gmpFemLocker.h
Go to the documentation of this file.
1 /************************************************************************
2 **
3 ** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4 ** All rights reserved.
5 **
6 ** This file is part of the "GeMA" software. It's use should respect
7 ** the terms in the license agreement that can be found together
8 ** with this source code.
9 ** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11 ** A PARTICULAR PURPOSE.
12 **
13 ************************************************************************/
14 
24 #ifndef _GEMA_PLUGIN_FEM_LOCKER_H_
25 #define _GEMA_PLUGIN_FEM_LOCKER_H_
26 
27 #include "gmpFemProcessConfig.h"
28 
29 #include <gmSpinLock.h>
30 
31 #include <QVector>
32 
33 class GmElementMesh;
34 
38 class GMP_FEM_PROCESS_API_EXPORT GmpFemLocker
39 {
40 public:
42  GmpFemLocker() { assert(GmThreadManager::inMainThread()); _psize = _npart = 0; }
43 
45  ~GmpFemLocker() { assert(GmThreadManager::inMainThread()); qDeleteAll(_lockList); }
46 
48  void setNumPartitions(int numdof, int npart)
49  {
50  assert(npart && numdof);
52 
53  if(npart + 1 > _lockList.size())
54  {
55  _lockList.resize(npart + 1); // + 1 for the negative values lock
56  for(int i = _npart; i < npart + 1; i++)
57  _lockList[i] = new GmSpinLock;
58  }
59  _npart = npart + 1;
60  _psize = (numdof+npart-1) / npart;
61  }
62 
64  int numPartitions() const { return _npart - 1; }
65 
67  void lockDof(int dofIndex) { _lockList[dofToLockIndex(dofIndex)]->lock(); }
68 
70  void unlockDof(int dofIndex) { _lockList[dofToLockIndex(dofIndex)]->unlock(); }
71 
72 private:
73  Q_DISABLE_COPY(GmpFemLocker)
74 
75 
76  int dofToLockIndex(int dofIndex)
77  {
78  assert(_psize && _npart);
79  assert(_npart <= _lockList.size());
80  int r = (dofIndex < 0) ? 0 : (dofIndex / _psize) + 1;
81  assert(r >= 0 && r < _npart);
82  return r;
83  }
84 
85  int _psize;
86  int _npart;
88 };
89 
90 
91 #endif
92 
int _npart
The number of partitions (including the extra partition for negative numbers)
Definition: gmpFemLocker.h:86
int numPartitions() const
Returns the number of configured partitions.
Definition: gmpFemLocker.h:64
void lockDof(int dofIndex)
Aquires the lock protecting the given dof index.
Definition: gmpFemLocker.h:67
A lock manager to be used by GmpFemAssemblerMatrixAdder and GmpFemAssemblerVectorAdder objects when w...
Definition: gmpFemLocker.h:38
void setNumPartitions(int numdof, int npart)
Adjusts the number of locks according to the number of degrees of freedom and partitions.
Definition: gmpFemLocker.h:48
QVector< GmSpinLock * > _lockList
The set of available locks.
Definition: gmpFemLocker.h:87
static bool inMainThread()
int _psize
The number of dofs in each partition.
Definition: gmpFemLocker.h:85
GmpFemLocker()
Constructor.
Definition: gmpFemLocker.h:42
Declaration of usefull configuration definitions for the plugin library.
~GmpFemLocker()
Destructor.
Definition: gmpFemLocker.h:45
void unlockDof(int dofIndex)
Releases the lock protecting the given dof index.
Definition: gmpFemLocker.h:70