Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
07b432db
Commit
07b432db
authored
May 17, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
добавлен тест rwmutex
parent
d4e47234
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
7 deletions
+57
-7
IOBase.cc
extensions/lib/IOBase.cc
+4
-6
Mutex.h
include/Mutex.h
+1
-1
test_mutex.cc
tests/test_mutex.cc
+52
-0
No files found.
extensions/lib/IOBase.cc
View file @
07b432db
...
@@ -372,8 +372,7 @@ long IOBase::processingAsAO( IOBase* it, const std::shared_ptr<SMInterface>& shm
...
@@ -372,8 +372,7 @@ long IOBase::processingAsAO( IOBase* it, const std::shared_ptr<SMInterface>& shm
if
(
cal
&&
cal
->
maxRaw
!=
cal
->
minRaw
)
// задана калибровка
if
(
cal
&&
cal
->
maxRaw
!=
cal
->
minRaw
)
// задана калибровка
{
{
// Калибруем в обратную сторону!!!
// Калибруем в обратную сторону!!!
val
=
UniSetTypes
::
lcalibrate
(
val
,
val
=
UniSetTypes
::
lcalibrate
(
val
,
cal
->
minCal
,
cal
->
maxCal
,
cal
->
minRaw
,
cal
->
maxRaw
,
it
->
calcrop
);
cal
->
minCal
,
cal
->
maxCal
,
cal
->
minRaw
,
cal
->
maxRaw
,
it
->
calcrop
);
}
}
}
}
}
}
...
@@ -521,7 +520,7 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
...
@@ -521,7 +520,7 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
if
(
sid
==
DefaultObjectId
)
if
(
sid
==
DefaultObjectId
)
{
{
if
(
dlog
&&
dlog
->
is_crit
()
)
if
(
dlog
&&
dlog
->
is_crit
()
)
dlog
->
crit
()
<<
myname
<<
"(readItem): ("
<<
DefaultObjectId
<<
")
Не удалось получить ID для датчика:
"
dlog
->
crit
()
<<
myname
<<
"(readItem): ("
<<
DefaultObjectId
<<
")
Unknown Sensor ID for
"
<<
sname
<<
endl
;
<<
sname
<<
endl
;
return
false
;
return
false
;
...
@@ -550,7 +549,6 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
...
@@ -550,7 +549,6 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
msec
=
initIntProp
(
it
,
"offdelay"
,
prefix
,
init_prefix_only
,
UniSetTimer
::
WaitUpTime
);
msec
=
initIntProp
(
it
,
"offdelay"
,
prefix
,
init_prefix_only
,
UniSetTimer
::
WaitUpTime
);
b
->
ptOffDelay
.
setTiming
(
msec
);
b
->
ptOffDelay
.
setTiming
(
msec
);
b
->
front
=
false
;
b
->
front
=
false
;
std
::
string
front_t
(
initProp
(
it
,
"iofront"
,
prefix
,
init_prefix_only
)
);
std
::
string
front_t
(
initProp
(
it
,
"iofront"
,
prefix
,
init_prefix_only
)
);
...
@@ -583,8 +581,8 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
...
@@ -583,8 +581,8 @@ bool IOBase::initItem( IOBase* b, UniXML::iterator& it, const std::shared_ptr<SM
if
(
b
->
stype
==
UniversalIO
::
UnknownIOType
)
if
(
b
->
stype
==
UniversalIO
::
UnknownIOType
)
{
{
if
(
dlog
&&
dlog
->
is_crit
()
)
if
(
dlog
&&
dlog
->
is_crit
()
)
dlog
->
crit
()
<<
myname
<<
"(IOBase::readItem):
неизвестный
iotype=: "
dlog
->
crit
()
<<
myname
<<
"(IOBase::readItem):
Unknown
iotype=: "
<<
initProp
(
it
,
"iotype"
,
prefix
,
init_prefix_only
)
<<
"
для
"
<<
sname
<<
endl
;
<<
initProp
(
it
,
"iotype"
,
prefix
,
init_prefix_only
)
<<
"
for
"
<<
sname
<<
endl
;
return
false
;
return
false
;
}
}
...
...
include/Mutex.h
View file @
07b432db
...
@@ -123,7 +123,7 @@ namespace UniSetTypes
...
@@ -123,7 +123,7 @@ namespace UniSetTypes
private
:
private
:
std
::
string
nm
;
std
::
string
nm
;
friend
class
uniset_rwmutex_lock
;
friend
class
uniset_rwmutex_lock
;
ost
::
ThreadLock
m
;
ost
::
ThreadLock
m
;
// это рекурсивный mutex (!)
};
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
uniset_rwmutex
&
m
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
uniset_rwmutex
&
m
);
...
...
tests/test_mutex.cc
View file @
07b432db
#include <catch.hpp>
#include <catch.hpp>
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
#include <iostream>
#include <iostream>
#include <thread>
#include <future>
#include "Mutex.h"
#include "Mutex.h"
#include "UniSetTypes.h"
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
using
namespace
std
;
using
namespace
std
;
using
namespace
UniSetTypes
;
using
namespace
UniSetTypes
;
...
@@ -173,3 +176,52 @@ TEST_CASE("uniset_rwmutex_{wr|r}lock", "[mutex][basic]" )
...
@@ -173,3 +176,52 @@ TEST_CASE("uniset_rwmutex_{wr|r}lock", "[mutex][basic]" )
CHECK_FALSE
(
m
.
try_lock
()
);
CHECK_FALSE
(
m
.
try_lock
()
);
}
}
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
uniset_rwmutex
g_mutex
;
bool
writer_thread
(
int
num
)
{
uniset_rwmutex_wrlock
l
(
g_mutex
);
msleep
(
1000
);
return
true
;
}
bool
reader_thread
(
int
num
)
{
uniset_rwmutex_rlock
l
(
g_mutex
);
msleep
(
50
);
return
true
;
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"uniset_rwmutex_{wr|r} thread lock"
,
"[mutex][threadlock][basic]"
)
{
g_mutex
.
rlock
();
std
::
vector
<
std
::
future
<
bool
>
>
vw
(
3
);
for
(
int
w
=
0
;
w
<
3
;
w
++
)
vw
.
push_back
(
std
::
async
(
std
::
launch
::
async
,
writer_thread
,
w
)
);
std
::
vector
<
std
::
future
<
bool
>
>
vr
(
3
);
for
(
int
r
=
0
;
r
<
5
;
r
++
)
vr
.
push_back
(
std
::
async
(
std
::
launch
::
async
,
reader_thread
,
r
)
);
msleep
(
10
);
// read захватывают сразу без задержек..
for
(
auto
&&
i
:
vr
)
{
if
(
i
.
valid
()
)
REQUIRE
(
i
.
get
()
==
true
);
}
// теперь отпускаю mutex
g_mutex
.
unlock
();
// проверяем что write-ы завершают работу.
for
(
auto
&
i
:
vw
)
{
if
(
i
.
valid
()
)
REQUIRE
(
i
.
get
()
==
true
);
}
}
// -----------------------------------------------------------------------------
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