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
4f4b01cd
Commit
4f4b01cd
authored
Feb 11, 2014
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Переписал mutex-ы на стандартные появившееся в c++11
parent
bee92874
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
101 deletions
+57
-101
configure.ac
configure.ac
+1
-1
stop.sh
extensions/tests/SMemoryTest/stop.sh
+2
-2
uniset-functions.sh
extensions/tests/SMemoryTest/uniset-functions.sh
+2
-2
uniset-start.sh
extensions/tests/SMemoryTest/uniset-start.sh
+2
-2
Mutex.h
include/Mutex.h
+12
-19
IONotifyController.cc
src/Processes/IONotifyController.cc
+1
-3
Mutex.cc
src/Various/Mutex.cc
+34
-69
Makefile.am
tests/Makefile.am
+1
-1
umutex.cc
tests/umutex.cc
+2
-2
No files found.
configure.ac
View file @
4f4b01cd
...
...
@@ -58,7 +58,7 @@ AM_CONDITIONAL(DISABLE_SQLITE, test ${buildsqlite} = false)
# export
LDFLAGS="${OMNI_LIBS} ${XML_LIBS}"
CXXFLAGS="-pedantic -Wall -funsigned-char -std=c++
0x
-g -D_GNU_SOURCE ${OMNI_CFLAGS} ${XML_CFLAGS} -I\$(top_builddir)/include"
CXXFLAGS="-pedantic -Wall -funsigned-char -std=c++
11
-g -D_GNU_SOURCE ${OMNI_CFLAGS} ${XML_CFLAGS} -I\$(top_builddir)/include"
AC_SUBST(LDFLAGS)
AC_SUBST(CXXFLAGS)
...
...
extensions/tests/SMemoryTest/stop.sh
View file @
4f4b01cd
../../../Utilities/scripts/uniset-stop.sh
\ No newline at end of file
../../../Utilities/scripts/uniset2-stop.sh
\ No newline at end of file
extensions/tests/SMemoryTest/uniset-functions.sh
View file @
4f4b01cd
../../../Utilities/scripts/uniset-functions.sh
\ No newline at end of file
../../../Utilities/scripts/uniset2-functions.sh
\ No newline at end of file
extensions/tests/SMemoryTest/uniset-start.sh
View file @
4f4b01cd
../../../Utilities/scripts/uniset-start.sh
\ No newline at end of file
../../../Utilities/scripts/uniset2-start.sh
\ No newline at end of file
include/Mutex.h
View file @
4f4b01cd
...
...
@@ -25,20 +25,15 @@
#define UniSet_MUTEX_H_
// -----------------------------------------------------------------------------------------
#include <string>
#include <omnithread.h>
#include <signal.h>
#include <atomic>
#include <chrono>
#include <mutex>
#include <cc++/thread.h>
// -----------------------------------------------------------------------------------------
namespace
UniSetTypes
{
typedef
ost
::
AtomicCounter
mutex_atomic_t
;
typedef
std
::
atomic_int
mutex_atomic_t
;
/*! \class uniset_mutex
* \note Напрямую функциями \a lock() и \a unlock() лучше не пользоваться.
* Как пользоваться см. \ref MutexHowToPage
* \todo Проверить правильность конструкторов копирования и operator=
*/
class
uniset_mutex
{
public
:
...
...
@@ -46,9 +41,9 @@ namespace UniSetTypes
uniset_mutex
(
const
std
::
string
&
name
);
~
uniset_mutex
();
bool
isRelease
();
void
lock
();
void
unlock
();
bool
try_lock_for
(
const
time_t
&
msec
);
inline
std
::
string
name
(){
return
nm
;
}
inline
void
setName
(
const
std
::
string
&
name
){
nm
=
name
;
}
...
...
@@ -57,13 +52,10 @@ namespace UniSetTypes
private
:
friend
class
uniset_mutex_lock
;
uniset_mutex
(
const
uniset_mutex
&
r
);
uniset_mutex
(
const
uniset_mutex
&
r
);
const
uniset_mutex
&
operator
=
(
const
uniset_mutex
&
r
);
omni_condition
*
cnd
;
std
::
string
nm
;
omni_semaphore
sem
;
omni_mutex
mtx
;
mutex_atomic_t
locked
;
std
::
timed_mutex
m_lock
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
uniset_mutex
&
m
);
...
...
@@ -79,14 +71,15 @@ namespace UniSetTypes
class
uniset_mutex_lock
{
public
:
uniset_mutex_lock
(
uniset_mutex
&
m
,
in
t
timeoutMS
=
0
);
uniset_mutex_lock
(
uniset_mutex
&
m
,
const
time_
t
timeoutMS
=
0
);
~
uniset_mutex_lock
();
bool
lock_ok
();
private
:
uniset_mutex
*
mutex
;
mutex_atomic_t
mlock
;
std
::
atomic
<
int
>
locked
;
uniset_mutex_lock
(
const
uniset_mutex_lock
&
);
uniset_mutex_lock
&
operator
=
(
const
uniset_mutex_lock
&
);
};
...
...
@@ -120,8 +113,8 @@ namespace UniSetTypes
std
::
string
nm
;
friend
class
uniset_rwmutex_lock
;
ost
::
ThreadLock
m
;
ost
::
AtomicCounter
wr_wait
;
static
ost
::
AtomicCounter
num
;
std
::
atomic
<
int
>
wr_wait
;
static
std
::
atomic
<
int
>
num
;
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
uniset_rwmutex
&
m
);
...
...
src/Processes/IONotifyController.cc
View file @
4f4b01cd
...
...
@@ -445,9 +445,7 @@ bool IONotifyController::activateObject()
// сперва вычитаем датчиков и заказчиков..
readDump
();
// а потом уже собственно активация..
IOController
::
activateObject
();
return
true
;
return
IOController
::
activateObject
();
}
// --------------------------------------------------------------------------------------------------------------
void
IONotifyController
::
readDump
()
...
...
src/Various/Mutex.cc
View file @
4f4b01cd
...
...
@@ -22,6 +22,8 @@
*/
// --------------------------------------------------------------------------
#include <chrono>
#include <thread>
#include <unistd.h>
#include "UniSetTypes.h"
#include "Mutex.h"
...
...
@@ -34,24 +36,17 @@ using namespace UniSetTypes;
#define MUTEX_DEBUG(m) {}
uniset_mutex
::
uniset_mutex
()
:
cnd
(
0
),
nm
(
""
),
locked
(
0
)
nm
(
""
)
{
cnd
=
new
omni_condition
(
&
mtx
);
}
// -----------------------------------------------------------------------------
uniset_mutex
::
uniset_mutex
(
const
string
&
name
)
:
cnd
(
0
),
nm
(
name
),
locked
(
0
)
nm
(
name
)
{
cnd
=
new
omni_condition
(
&
mtx
);
}
// -----------------------------------------------------------------------------
uniset_mutex
::~
uniset_mutex
()
{
delete
cnd
;
}
// -----------------------------------------------------------------------------
std
::
ostream
&
UniSetTypes
::
operator
<<
(
std
::
ostream
&
os
,
uniset_mutex
&
m
)
...
...
@@ -61,100 +56,63 @@ std::ostream& UniSetTypes::operator<<(std::ostream& os, uniset_mutex& m )
// -----------------------------------------------------------------------------
void
uniset_mutex
::
lock
()
{
sem
.
wait
();
locked
=
1
;
m_lock
.
lock
();
MUTEX_DEBUG
(
cerr
<<
nm
<<
" Locked.."
<<
endl
;)
}
// -----------------------------------------------------------------------------
void
uniset_mutex
::
unlock
()
{
locked
=
0
;
m_lock
.
unlock
()
;
MUTEX_DEBUG
(
cerr
<<
nm
<<
" Unlocked.."
<<
endl
;)
sem
.
post
();
cnd
->
signal
();
}
// -----------------------------------------------------------------------------
bool
uniset_mutex
::
isRelease
()
{
return
!
locked
;
}
// -----------------------------------------------------------------------------
const
uniset_mutex
&
uniset_mutex
::
operator
=
(
const
uniset_mutex
&
r
)
bool
uniset_mutex
::
try_lock_for
(
const
time_t
&
msec
)
{
// if( this != &r )
// locked = r.locked;
return
*
this
;
return
m_lock
.
try_lock_for
(
std
::
chrono
::
milliseconds
(
msec
)
);
}
// -----------------------------------------------------------------------------
uniset_mutex
::
uniset_mutex
(
const
uniset_mutex
&
r
)
:
cnd
(
0
),
nm
(
r
.
nm
),
locked
(
r
.
locked
)
uniset_mutex_lock
::
uniset_mutex_lock
(
uniset_mutex
&
m
,
const
time_t
timeMS
)
:
mutex
(
&
m
),
locked
(
0
)
{
cnd
=
new
omni_condition
(
&
mtx
);
}
// -----------------------------------------------------------------------------
uniset_mutex_lock
::
uniset_mutex_lock
(
uniset_mutex
&
m
,
int
timeMS
)
:
mutex
(
&
m
)
{
if
(
timeMS
<=
0
||
mutex
->
isRelease
()
)
if
(
timeMS
==
0
)
{
mutex
->
lock
();
mlock
=
1
;
locked
=
1
;
return
;
}
unsigned
long
sec
,
msec
;
omni_thread
::
get_time
(
&
sec
,
&
msec
,
timeMS
/
1000
,
(
timeMS
%
1000
)
*
1000000
);
mutex
->
mtx
.
lock
();
if
(
!
mutex
->
cnd
->
timedwait
(
sec
,
msec
)
)
if
(
!
mutex
->
try_lock_for
(
timeMS
)
)
{
if
(
!
mutex
->
name
().
empty
()
)
{
ulog9
<<
"(mutex_lock): вышло заданное время ожидания "
<<
timeMS
<<
" msec для "
<<
mutex
->
name
()
<<
endl
;
}
mlock
=
0
;
mutex
->
mtx
.
unlock
();
return
;
// ресурс не захватываем
return
;
}
mlock
=
1
;
mutex
->
lock
();
mutex
->
mtx
.
unlock
();
locked
=
1
;
}
// -----------------------------------------------------------------------------
bool
uniset_mutex_lock
::
lock_ok
()
{
return
mlock
;
}
uniset_mutex_lock
::~
uniset_mutex_lock
()
{
if
(
mlock
)
{
mlock
=
0
;
mutex
->
unlock
();
}
{
return
(
locked
==
1
);
}
// -----------------------------------------------------------------------------
uniset_mutex_lock
&
uniset_mutex_lock
::
operator
=
(
const
uniset_mutex_lock
&
r
)
uniset_mutex_lock
::~
uniset_mutex_lock
(
)
{
return
*
this
;
mutex
->
unlock
();
locked
=
0
;
}
// -----------------------------------------------------------------------------
uniset_rwmutex
::
uniset_rwmutex
(
const
std
::
string
&
name
)
:
nm
(
name
),
wr_wait
(
0
)
{
}
ost
::
AtomicCounter
uniset_rwmutex
::
num
=
0
;
uniset_rwmutex
::
uniset_rwmutex
()
:
nm
(
""
),
wr_wait
(
0
)
...
...
@@ -170,6 +128,8 @@ std::ostream& UniSetTypes::operator<<(std::ostream& os, uniset_rwmutex& m )
return
os
<<
m
.
name
();
}
std
::
atomic
<
int
>
uniset_rwmutex
::
num
(
0
);
const
uniset_rwmutex
&
uniset_rwmutex
::
operator
=
(
const
uniset_rwmutex
&
r
)
{
if
(
this
!=
&
r
)
...
...
@@ -178,6 +138,7 @@ const uniset_rwmutex &uniset_rwmutex::operator=( const uniset_rwmutex& r )
ostringstream
s
;
s
<<
r
.
nm
<<
"."
<<
(
++
num
);
nm
=
s
.
str
();
wr_wait
=
0
;
unlock
();
MUTEX_DEBUG
(
cerr
<<
"...copy mutex..."
<<
nm
<<
endl
;)
}
...
...
@@ -186,24 +147,25 @@ const uniset_rwmutex &uniset_rwmutex::operator=( const uniset_rwmutex& r )
}
uniset_rwmutex
::
uniset_rwmutex
(
const
uniset_rwmutex
&
r
)
:
nm
(
r
.
nm
)
nm
(
r
.
nm
),
wr_wait
(
0
)
{
}
void
uniset_rwmutex
::
lock
()
{
MUTEX_DEBUG
(
cerr
<<
nm
<<
" prepare Locked.."
<<
endl
;)
wr_wait
+=
1
;
wr_wait
++
;
m
.
writeLock
();
wr_wait
-=
1
;
wr_wait
--
;
MUTEX_DEBUG
(
cerr
<<
nm
<<
" Locked.."
<<
endl
;)
}
void
uniset_rwmutex
::
wrlock
()
{
MUTEX_DEBUG
(
cerr
<<
nm
<<
" prepare WRLocked.."
<<
endl
;)
wr_wait
+=
1
;
wr_wait
++
;
m
.
writeLock
();
wr_wait
-=
1
;
wr_wait
--
;
MUTEX_DEBUG
(
cerr
<<
nm
<<
" WRLocked.."
<<
endl
;)
}
void
uniset_rwmutex
::
rlock
()
...
...
@@ -211,7 +173,10 @@ void uniset_rwmutex::rlock()
MUTEX_DEBUG
(
cerr
<<
nm
<<
" prepare RLocked.."
<<
endl
;)
while
(
wr_wait
)
msleep
(
2
);
{
MUTEX_DEBUG
(
cerr
<<
nm
<<
" whait... WR="
<<
wr_wait
<<
endl
;
)
msleep
(
2
);
}
m
.
readLock
();
MUTEX_DEBUG
(
cerr
<<
nm
<<
" RLocked.."
<<
endl
;)
...
...
tests/Makefile.am
View file @
4f4b01cd
...
...
@@ -30,7 +30,7 @@ ui_CPPFLAGS = -I$(top_builddir)/include
umutex_SOURCES
=
umutex.cc
umutex_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
$(COMCPP_LIBS)
umutex_CPPFLAGS
=
-
S
-O2
-
I
$(top_builddir)
/include
$(COMCPP_CFLAGS)
umutex_CPPFLAGS
=
-I
$(top_builddir)
/include
$(COMCPP_CFLAGS)
conftest_SOURCES
=
conftest.cc
conftest_LDADD
=
$(top_builddir)
/lib/libUniSet2.la
...
...
tests/umutex.cc
View file @
4f4b01cd
...
...
@@ -140,7 +140,7 @@ int main( int argc, const char **argv )
try
{
#if
0
#if
1
{
uniset_rwmutex
m1
(
"mutex1"
);
uniset_rwmutex
m2
(
"mutex2"
);
...
...
@@ -161,7 +161,7 @@ int main( int argc, const char **argv )
cout
<<
"m3.lock: wrlock OK"
<<
endl
;
}
return 0;
//
return 0;
#endif
#if 0
...
...
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