FemProcess
The GeMA Fem Process Plugin
Loading...
Searching...
No Matches
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
33class GmElementMesh;
34
38class GMP_FEM_PROCESS_API_EXPORT GmpFemLocker
39{
40public:
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
51 assert(npart && numdof);
53
54 if(npart + 1 > _lockList.size())
55 {
56 _lockList.resize(npart + 1); // + 1 for the negative values lock
57 for(int i = _npart; i < npart + 1; i++)
58 _lockList[i] = new GmSpinLock;
59 }
60 _npart = npart + 1;
61 _psize = (numdof+npart-1) / npart;
62
63 }
64
66 int numPartitions() const { return _npart - 1; }
67
69 void lockDof(int dofIndex) { _lockList[dofToLockIndex(dofIndex)]->lock(); }
70
72 void unlockDof(int dofIndex) { _lockList[dofToLockIndex(dofIndex)]->unlock(); }
73
74private:
75 Q_DISABLE_COPY(GmpFemLocker)
76
77
78 int dofToLockIndex(int dofIndex)
79 {
80 assert(_psize && _npart);
81 assert(_npart <= _lockList.size());
82 int r = (dofIndex < 0) ? 0 : (dofIndex / _psize) + 1;
83 assert(r >= 0 && r < _npart);
84 return r;
85 }
86
87 int _psize;
88 int _npart;
90};
91
92
93#endif
94
static bool inMainThread()
A lock manager to be used by GmpFemAssemblerMatrixAdder and GmpFemAssemblerVectorAdder objects when w...
Definition gmpFemLocker.h:39
int _psize
The number of dofs in each partition.
Definition gmpFemLocker.h:87
int numPartitions() const
Returns the number of configured partitions.
Definition gmpFemLocker.h:66
QVector< GmSpinLock * > _lockList
The set of available locks.
Definition gmpFemLocker.h:89
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
void unlockDof(int dofIndex)
Releases the lock protecting the given dof index.
Definition gmpFemLocker.h:72
int _npart
The number of partitions (including the extra partition for negative numbers)
Definition gmpFemLocker.h:88
~GmpFemLocker()
Destructor.
Definition gmpFemLocker.h:45
GmpFemLocker()
Constructor.
Definition gmpFemLocker.h:42
void lockDof(int dofIndex)
Aquires the lock protecting the given dof index.
Definition gmpFemLocker.h:69
Declaration of useful configuration definitions for the plugin library.