Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kumir2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kumir
kumir2
Commits
32bf75b8
Commit
32bf75b8
authored
Sep 21, 2016
by
Denis Khachko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Vodoley mutex lock
parent
bb56d0ee
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
29 deletions
+35
-29
src/actors/vodoley/vodoley.cpp
src/actors/vodoley/vodoley.cpp
+11
-6
src/actors/vodoley/vodoley.h
src/actors/vodoley/vodoley.h
+6
-5
src/actors/vodoley/vodoleymodule.cpp
src/actors/vodoley/vodoleymodule.cpp
+18
-18
No files found.
src/actors/vodoley/vodoley.cpp
View file @
32bf75b8
...
...
@@ -27,7 +27,7 @@
static
const
double
Pi
=
3.14159265358979323846264338327950288419717
;
Menzurka
::
Menzurka
(
int
x
,
int
y
,
uint
size
,
float
lsize
)
Menzurka
::
Menzurka
(
int
x
,
int
y
,
uint
size
,
float
lsize
,
QMutex
*
mutex
)
{
SizeInLiters
=
size
;
literSize
=
lsize
;
...
...
@@ -37,6 +37,7 @@ Menzurka::Menzurka(int x,int y,uint size,float lsize)
GpY
=
4
;
curFil
=
1
;
needFill
=-
1
;
M
=
mutex
;
};
...
...
@@ -45,7 +46,7 @@ void Menzurka::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
{
Q_UNUSED
(
option
);
Q_UNUSED
(
widget
);
M
->
lock
();
//qDebug()<<"Repaint menzurka "<<Gp<<" curFil"<<curFil;
QBrush
black
(
Qt
::
black
);
float
size
=
(
literSize
*
SizeInLiters
);
...
...
@@ -128,6 +129,7 @@ void Menzurka::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
//painter->drawLine(offsetX+1, offsetY+size-literSize*curFil,offsetX+X_SIZE-2,offsetY+size);
M
->
unlock
();
};
Vodoley
::
Vodoley
()
...
...
@@ -260,9 +262,9 @@ void Vodoley::CreateVodoley(void)
{
float
literSize
=
MAX_SIZE
/
maxSize
();
qDebug
()
<<
"Liter Size:"
<<
literSize
;
Amen
=
new
Menzurka
(
30
,
30
+
(
maxSize
()
-
Asize
())
*
literSize
,
Asize
(),
literSize
);
Bmen
=
new
Menzurka
(
140
,
30
+
(
maxSize
()
-
Bsize
())
*
literSize
,
Bsize
(),
literSize
);
Cmen
=
new
Menzurka
(
250
,
30
+
(
maxSize
()
-
Csize
())
*
literSize
,
Csize
(),
literSize
);
Amen
=
new
Menzurka
(
30
,
30
+
(
maxSize
()
-
Asize
())
*
literSize
,
Asize
(),
literSize
,
&
mutex
);
Bmen
=
new
Menzurka
(
140
,
30
+
(
maxSize
()
-
Bsize
())
*
literSize
,
Bsize
(),
literSize
,
&
mutex
);
Cmen
=
new
Menzurka
(
250
,
30
+
(
maxSize
()
-
Csize
())
*
literSize
,
Csize
(),
literSize
,
&
mutex
);
Amen
->
setCurFill
(
CurA
());
Bmen
->
setCurFill
(
CurB
());
...
...
@@ -353,7 +355,8 @@ void Vodoley::FillC()
void
Vodoley
::
MoveFromTo
(
uint
from
,
uint
to
)
{
if
(
to
>
2
){
Curfill
[
from
]
=
0
;
updateMenzur
();
return
;};
//Выливаем
mutex
.
lock
();
if
(
to
>
2
){
Curfill
[
from
]
=
0
;
mutex
.
unlock
();
updateMenzur
();
return
;};
//Выливаем
int
svobodno
=
Maxfill
[
to
]
-
Curfill
[
to
];
Curfill
[
to
]
=
Curfill
[
to
]
+
Curfill
[
from
];
if
(
Curfill
[
to
]
>
Maxfill
[
to
])
Curfill
[
to
]
=
Maxfill
[
to
];
...
...
@@ -363,7 +366,9 @@ void Vodoley::MoveFromTo(uint from,uint to)
Curfill
[
from
]
=
0
;
else
Curfill
[
from
]
=
Curfill
[
from
]
-
svobodno
;
mutex
.
unlock
();
updateMenzur
();
};
...
...
src/actors/vodoley/vodoley.h
View file @
32bf75b8
...
...
@@ -37,7 +37,7 @@ class Menzurka:public QGraphicsItem
{
public:
Menzurka
(
int
x
,
int
y
,
uint
size
,
float
lsize
);
Menzurka
(
int
x
,
int
y
,
uint
size
,
float
lsize
,
QMutex
*
mutex
);
~
Menzurka
(){};
QRectF
boundingRect
()
const
...
...
@@ -91,7 +91,7 @@ private:
int
offsetX
;
int
offsetY
;
int
Gp
,
GpY
;
QMutex
*
M
;
};
class
NewDialog
:
public
QDialog
...
...
@@ -136,15 +136,15 @@ public:
show
();
setVisible
(
true
);
}
uint
CurA
()
uint
CurA
()
const
{
return
Curfill
[
0
];
};
uint
CurB
()
uint
CurB
()
const
{
return
Curfill
[
1
];
};
uint
CurC
()
uint
CurC
()
const
{
return
Curfill
[
2
];
};
...
...
@@ -251,6 +251,7 @@ private:
Menzurka
*
Amen
;
Menzurka
*
Bmen
;
Menzurka
*
Cmen
;
QMutex
mutex
;
QString
curDir
;
bool
autoClose
;
// WHeader* vodHeader;
...
...
src/actors/vodoley/vodoleymodule.cpp
View file @
32bf75b8
...
...
@@ -192,72 +192,72 @@ private:
{
/* алг вылей B */
// TODO implement me
mutex
.
lock
();
//
mutex.lock();
MainWindow
->
MoveFromTo
(
1
,
3
);
mutex
.
unlock
();
//
mutex.unlock();
}
/* public slot */
void
VodoleyModule
::
runEmptyC
()
{
/* алг вылей C */
// TODO implement me
mutex
.
lock
();
//
mutex.lock();
MainWindow
->
MoveFromTo
(
1
,
3
);
mutex
.
unlock
();
//
mutex.unlock();
}
/* public slot */
void
VodoleyModule
::
runFromAToB
()
{
/* алг перелей из A в B */
// TODO implement me
mutex
.
lock
();
//
mutex.lock();
MainWindow
->
MoveFromTo
(
0
,
1
);
mutex
.
unlock
();
//
mutex.unlock();
}
/* public slot */
void
VodoleyModule
::
runFromAToC
()
{
/* алг перелей из A в C */
// TODO implement me
mutex
.
lock
();
//
mutex.lock();
MainWindow
->
MoveFromTo
(
0
,
2
);
mutex
.
unlock
();
//
mutex.unlock();
}
/* public slot */
void
VodoleyModule
::
runFromBToA
()
{
/* алг перелей из B в A */
// TODO implement me
mutex
.
lock
();
//
mutex.lock();
MainWindow
->
MoveFromTo
(
1
,
0
);
mutex
.
unlock
();
//
mutex.unlock();
}
/* public slot */
void
VodoleyModule
::
runFromBToC
()
{
/* алг перелей из B в C */
// TODO implement me
mutex
.
lock
();
//
mutex.lock();
MainWindow
->
MoveFromTo
(
1
,
2
);
mutex
.
unlock
();
//
mutex.unlock();
}
/* public slot */
void
VodoleyModule
::
runFromCToB
()
{
/* алг перелей из C в B */
// TODO implement me
mutex
.
lock
();
//
mutex.lock();
MainWindow
->
MoveFromTo
(
2
,
1
);
mutex
.
unlock
();
//
mutex.unlock();
}
/* public slot */
void
VodoleyModule
::
runFromCToA
()
{
/* алг перелей из C в A */
// TODO implement me
mutex
.
lock
();
//
mutex.lock();
MainWindow
->
MoveFromTo
(
2
,
0
);
mutex
.
unlock
();
//
mutex.unlock();
}
/* public slot */
bool
VodoleyModule
::
runTaskComplited
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment