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
54b685e2
Commit
54b685e2
authored
Jan 19, 2015
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Очередная версия механизма завершения процессов. Добавлен контрольный поток
(делающий KILL если процессы не завершились), а также проведены некоторые стилистические правки.
parent
b1ef89fe
Show whitespace changes
Inline
Side-by-side
Showing
35 changed files
with
323 additions
and
160 deletions
+323
-160
ctl-cpp-cc-alone-ask.xsl
Utilities/codegen/ctl-cpp-cc-alone-ask.xsl
+4
-4
ctl-cpp-cc-alone.xsl
Utilities/codegen/ctl-cpp-cc-alone.xsl
+2
-2
ctl-cpp-cc-ask.xsl
Utilities/codegen/ctl-cpp-cc-ask.xsl
+5
-4
ctl-cpp-cc.xsl
Utilities/codegen/ctl-cpp-cc.xsl
+2
-2
ctl-cpp-common.xsl
Utilities/codegen/ctl-cpp-common.xsl
+17
-9
ctl-cpp-main-alone.xsl
Utilities/codegen/ctl-cpp-main-alone.xsl
+4
-0
ctl-cpp-main.xsl
Utilities/codegen/ctl-cpp-main.xsl
+4
-0
Makefile.am
Utilities/codegen/tests/Makefile.am
+2
-2
start_fg_mbtcp.sh
extensions/ModbusMaster/start_fg_mbtcp.sh
+1
-0
MBTCPTestServer.cc
extensions/ModbusMaster/tests/MBTCPTestServer.cc
+1
-1
uniset-start.sh
extensions/ModbusMaster/uniset-start.sh
+0
-2
uniset2-start.sh
extensions/ModbusMaster/uniset2-start.sh
+2
-0
MBSlave.cc
extensions/ModbusSlave/MBSlave.cc
+4
-1
start_tcp_fg.sh
extensions/ModbusSlave/start_tcp_fg.sh
+2
-1
start_fg.sh
extensions/SharedMemory/start_fg.sh
+1
-1
UNetReceiver.h
extensions/UNetUDP/UNetReceiver.h
+0
-0
UObject_SK.h
extensions/include/UObject_SK.h
+1
-1
UObject_SK.cc
extensions/lib/UObject_SK.cc
+10
-8
tests_with_sm.sh
extensions/tests/tests_with_sm.sh
+1
-1
OmniThreadCreator.h
include/OmniThreadCreator.h
+2
-0
PassiveTimer.h
include/PassiveTimer.h
+18
-19
ThreadCreator.h
include/ThreadCreator.h
+2
-0
UniSetActivator.h
include/UniSetActivator.h
+1
-2
UniSetObject.h
include/UniSetObject.h
+11
-2
UInterface.cc
src/Interfaces/UInterface.cc
+10
-1
UniSetActivator.cc
src/ObjectRepository/UniSetActivator.cc
+85
-30
UniSetObject.cc
src/ObjectRepository/UniSetObject.cc
+38
-7
Makefile.am
src/Timers/Makefile.am
+1
-1
PassiveCondTimer.cc
src/Timers/PassiveCondTimer.cc
+15
-46
PassiveSigTimer.cc
src/Timers/PassiveSigTimer.cc
+12
-12
Configuration.cc
src/Various/Configuration.cc
+4
-0
SViewer.cc
src/Various/SViewer.cc
+0
-0
Makefile.am
tests/Makefile.am
+1
-0
test_hourglass.cc
tests/test_hourglass.cc
+1
-1
test_passivecondtimer.cc
tests/test_passivecondtimer.cc
+59
-0
No files found.
Utilities/codegen/ctl-cpp-cc-alone-ask.xsl
View file @
54b685e2
...
...
@@ -96,9 +96,9 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::callback()
ucrit
<<
myname
<<
"(execute): СORBA::SystemException: "
<<
ex.NP_minorString()
<<
endl;
}
catch(...
)
catch( std::exception
&
ex
)
{
ucrit
<<
myname
<<
"(execute): catch
..."
<<
endl;
ucrit
<<
myname
<<
"(execute): catch
"
<<
ex.what()
<<
endl;
}
if( !active )
...
...
@@ -168,9 +168,9 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preAskSensors( UniversalIO::UIOComm
{
ucrit
<<
myname
<<
"(preAskSensors): "
<<
ex
<<
endl;
}
catch(...
)
catch( std::exception
&
ex
)
{
ucrit
<<
myname
<<
"(preAskSensors): catch(...)"
<<
endl;
ucrit
<<
myname
<<
"(execute): catch "
<<
ex.what()
<<
endl;
}
msleep(askPause);
}
...
...
Utilities/codegen/ctl-cpp-cc-alone.xsl
View file @
54b685e2
...
...
@@ -101,9 +101,9 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::callback()
ucrit
<<
myname
<<
"(execute): СORBA::SystemException: "
<<
ex.NP_minorString()
<<
endl;
}
catch(
...
)
catch(
std::exception
&
ex
)
{
ucrit
<<
myname
<<
"(execute): catch
..."
<<
endl;
ucrit
<<
myname
<<
"(execute): catch
"
<<
ex.what()
<<
endl;
}
if( !active )
...
...
Utilities/codegen/ctl-cpp-cc-ask.xsl
View file @
54b685e2
...
...
@@ -95,9 +95,9 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::callback()
ucrit
<<
myname
<<
"(execute): СORBA::SystemException: "
<<
ex.NP_minorString()
<<
endl;
}
catch(...
)
catch( std::exception
&
ex
)
{
ucrit
<<
myname
<<
"(execute): catch
..."
<<
endl;
ucrit
<<
myname
<<
"(execute): catch
"
<<
ex.what()
<<
endl;
}
if( !active )
...
...
@@ -233,10 +233,11 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::preAskSensors( UniversalIO::UIOComm
{
ucrit
<<
myname
<<
"(preAskSensors): "
<<
ex
<<
endl;
}
catch(...
)
catch( std::exception
&
ex
)
{
ucrit
<<
myname
<<
"(preAskSensors): catch(...)"
<<
endl;
ucrit
<<
myname
<<
"(execute): catch "
<<
ex.what()
<<
endl;
}
msleep(askPause);
}
}
...
...
Utilities/codegen/ctl-cpp-cc.xsl
View file @
54b685e2
...
...
@@ -99,9 +99,9 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::callback()
ucrit
<<
myname
<<
"(execute): СORBA::SystemException: "
<<
ex.NP_minorString()
<<
endl;
}
catch(...
)
catch( std::exception
&
ex
)
{
ucrit
<<
myname
<<
"(execute): catch
..."
<<
endl;
ucrit
<<
myname
<<
"(execute): catch
"
<<
ex.what()
<<
endl;
}
if( !active )
...
...
Utilities/codegen/ctl-cpp-common.xsl
View file @
54b685e2
...
...
@@ -115,7 +115,10 @@
ui->setValue( si,(m_
<xsl:value-of
select=
"../../@name"
/>
? 1:0), getId() );
return true;
}
catch(...){}
catch( std::exception
&
ex )
{
ucrit
<<
myname
<<
"(execute): catch "
<<
ex.what()
<<
endl;
}
return false;
}
</xsl:when>
...
...
@@ -395,10 +398,11 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::waitSM( int wait_msec, ObjectId _te
<<
wait_msec
<<
" мсек";
ucrit
<<
err.str()
<<
endl;
// terminate();
// abort();
raise(SIGTERM);
terminate();
abort();
// kill(SIGTERM,getpid()); // прерываем (перезапускаем) процесс...
throw SystemError(err.str());
// throw SystemError(err.str());
}
<xsl:if
test=
"normalize-space($TESTMODE)!=''"
>
...
...
@@ -412,10 +416,10 @@ void <xsl:value-of select="$CLASSNAME"/>_SK::waitSM( int wait_msec, ObjectId _te
<<
wait_msec
<<
" мсек";
ucrit
<<
err.str()
<<
endl;
terminate();
abort();
// kill(SIGTERM,getpid()); // прерываем (перезапускаем) процесс...
throw SystemError(err.str());
//
terminate();
//
abort();
raise(SIGTERM);
//
throw SystemError(err.str());
}
}
</xsl:if>
...
...
@@ -809,7 +813,11 @@ bool <xsl:value-of select="$CLASSNAME"/>_SK::alarm( UniSetTypes::ObjectId _code,
ui->setValue( si,m_
<xsl:value-of
select=
"@name"
/>
,getId() );
return true;
}
catch(...){}
catch( std::exception
&
ex )
{
ucrit
<<
myname
<<
"(execute): catch "
<<
ex.what()
<<
endl;
}
return false;
}
</xsl:for-each>
...
...
Utilities/codegen/ctl-cpp-main-alone.xsl
View file @
54b685e2
...
...
@@ -84,6 +84,10 @@ int main( int argc,char* argv[] )
{
cerr
<<
"(main): "
<<
ex
<<
endl;
}
catch( std::exception
&
ex )
{
ucrit
<<
"(main): catch "
<<
ex.what()
<<
endl;
}
catch(...)
{
cerr
<<
"(main): catch ..."
<<
endl;
...
...
Utilities/codegen/ctl-cpp-main.xsl
View file @
54b685e2
...
...
@@ -92,6 +92,10 @@ int main( int argc, const char** argv )
{
cerr
<<
"(main): "
<<
ex
<<
endl;
}
catch( std::exception
&
ex )
{
cerr
<<
"(main): catch "
<<
ex.what()
<<
endl;
}
catch(...)
{
cerr
<<
"(main): catch ..."
<<
endl;
...
...
Utilities/codegen/tests/Makefile.am
View file @
54b685e2
...
...
@@ -13,10 +13,10 @@ GENERATED=TestGen_SK.h TestGen_SK.cc TestGen-main.cc
GENERATED2
=
TestGenAlone_SK.h TestGenAlone_SK.cc TestGenAlone-main.cc
GENUOBJ
=
UObject_SK.cc UObject_SK.h
TestGen_SK.cc
:
../@PACKAGE@-codegen testgen.src.xml ../*.xsl
TestGen_SK.cc
TestGen_SK.h
:
../@PACKAGE@-codegen testgen.src.xml ../*.xsl
../@PACKAGE@-codegen
-l
$(top_builddir)
/Utilities/codegen
--local-include
-n
TestGen testgen.src.xml
TestGenAlone_SK.cc
:
../@PACKAGE@-codegen testgen-alone.src.xml ../*.xsl
TestGenAlone_SK.cc
TestGenAlone_SK.h
:
../@PACKAGE@-codegen testgen-alone.src.xml ../*.xsl
../@PACKAGE@-codegen
-l
$(top_builddir)
/Utilities/codegen
--local-include
--alone
-n
TestGenAlone testgen-alone.src.xml
$(GENUOBJ)
:
../@PACKAGE@-codegen uobject.src.xml ../*.xsl
...
...
extensions/ModbusMaster/start_fg_mbtcp.sh
View file @
54b685e2
...
...
@@ -14,6 +14,7 @@
--mbtcp-force-disconnect
1
\
--mbtcp-polltime
3000
\
--mbtcp-force-out
1
\
--ulog-add-levels
system
\
$*
#--mbtcp-exchange-mode-id MB1_Mode_AS \
...
...
extensions/ModbusMaster/tests/MBTCPTestServer.cc
View file @
54b685e2
...
...
@@ -95,7 +95,7 @@ void MBTCPTestServer::runThread()
void
MBTCPTestServer
::
execute
()
{
isrunning
=
true
;
cerr
<<
"******************** MBTCPTestServer("
<<
myname
<<
") running... "
<<
endl
;
//
cerr << "******************** MBTCPTestServer(" << myname << ") running... " << endl;
// Работа...
while
(
1
)
{
...
...
extensions/ModbusMaster/uniset-start.sh
deleted
120000 → 0
View file @
b1ef89fe
../../Utilities/scripts/uniset2-start.sh
\ No newline at end of file
extensions/ModbusMaster/uniset2-start.sh
0 → 120000
View file @
54b685e2
../../Utilities/scripts/uniset2-start.sh
\ No newline at end of file
extensions/ModbusSlave/MBSlave.cc
View file @
54b685e2
...
...
@@ -389,7 +389,10 @@ void MBSlave::waitSMReady()
ostringstream
err
;
err
<<
myname
<<
"(waitSMReady): Не дождались готовности SharedMemory к работе в течение "
<<
ready_timeout
<<
" мсек"
;
dcrit
<<
err
.
str
()
<<
endl
;
throw
SystemError
(
err
.
str
());
// throw SystemError(err.str());
raise
(
SIGTERM
);
terminate
();
// abort();
}
}
// -----------------------------------------------------------------------------
...
...
extensions/ModbusSlave/start_tcp_fg.sh
View file @
54b685e2
...
...
@@ -4,7 +4,7 @@ uniset2-start.sh -f ./uniset2-mbslave --confile test.xml --dlog-add-levels any \
--smemory-id
SharedMemory
\
--mbs-name
MBSlave1
\
--mbs-type
TCP
--mbs-inet-addr
127.0.0.1
--mbs-inet-port
2048
--mbs-reg-from-id
1
--mbs-my-addr
0x01
\
--mbs-askcount-id
SVU_AskCount_AS
--mbs-respond-id
RespondRTU_S
--mbs-respond-invert
1
$*
--mbs-askcount-id
SVU_AskCount_AS
--mbs-respond-id
RespondRTU_S
--mbs-respond-invert
1
--ulog-add-levels
system
$*
# --mbs-force 1
#--mbs-reg-from-id 1 \
#--mbs-filter-field CAN2sender --mbs-filter-value SYSTSNode \
\ No newline at end of file
extensions/SharedMemory/start_fg.sh
View file @
54b685e2
...
...
@@ -5,6 +5,6 @@ export LD_LIBRARY_PATH="../../lib/.libs;../lib/.libs"
ulimit
-Sc
10000000000
./uniset2-start.sh
-f
./uniset2-smemory
--smemory-id
SharedMemory
--pulsar-id
DO_C
--pulsar-iotype
DO
--pulsar-msec
100
\
--confile
test.xml
--datfile
test.xml
--db-logging
1
$*
\
--confile
test.xml
--datfile
test.xml
--db-logging
1
--ulog-add-levels
system
$*
\
#--ulog-add-levels info,crit,warn,level9,system \
#--dlog-add-levels info,crit,warn \
extensions/UNetUDP/UNetReceiver.h
View file @
54b685e2
extensions/include/UObject_SK.h
View file @
54b685e2
...
...
@@ -8,7 +8,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2015-01-1
7
+03:00
// generate timestamp: 2015-01-1
9
+03:00
// -----------------------------------------------------------------------------
#ifndef UObject_SK_H_
#define UObject_SK_H_
...
...
extensions/lib/UObject_SK.cc
View file @
54b685e2
...
...
@@ -11,7 +11,7 @@
ВСЕ ВАШИ ИЗМЕНЕНИЯ БУДУТ ПОТЕРЯНЫ.
*/
// --------------------------------------------------------------------------
// generate timestamp: 2015-01-1
7
+03:00
// generate timestamp: 2015-01-1
9
+03:00
// -----------------------------------------------------------------------------
#include "Configuration.h"
#include "Exceptions.h"
...
...
@@ -342,10 +342,11 @@ void UObject_SK::waitSM( int wait_msec, ObjectId _testID )
<<
wait_msec
<<
" мсек"
;
ucrit
<<
err
.
str
()
<<
endl
;
// terminate();
// abort();
raise
(
SIGTERM
);
terminate
();
abort
();
// kill(SIGTERM,getpid()); // прерываем (перезапускаем) процесс...
throw
SystemError
(
err
.
str
());
// throw SystemError(err.str());
}
...
...
@@ -402,9 +403,9 @@ void UObject_SK::callback()
ucrit
<<
myname
<<
"(execute): СORBA::SystemException: "
<<
ex
.
NP_minorString
()
<<
endl
;
}
catch
(...
)
catch
(
std
::
exception
&
ex
)
{
ucrit
<<
myname
<<
"(execute): catch
..."
<<
endl
;
ucrit
<<
myname
<<
"(execute): catch
"
<<
ex
.
what
()
<<
endl
;
}
if
(
!
active
)
...
...
@@ -483,10 +484,11 @@ void UObject_SK::preAskSensors( UniversalIO::UIOCommand _cmd )
{
ucrit
<<
myname
<<
"(preAskSensors): "
<<
ex
<<
endl
;
}
catch
(...
)
catch
(
std
::
exception
&
ex
)
{
ucrit
<<
myname
<<
"(preAskSensors): catch(...)"
<<
endl
;
ucrit
<<
myname
<<
"(execute): catch "
<<
ex
.
what
()
<<
endl
;
}
msleep
(
askPause
);
}
}
...
...
extensions/tests/tests_with_sm.sh
View file @
54b685e2
...
...
@@ -10,4 +10,4 @@ cd ../../Utilities/Admin/
cd
-
./uniset2-start.sh
-f
./tests_with_sm
$*
--
--confile
tests_with_sm.xml
--e-startup-pause
10
--ulog-
levels
warn,crit
--dlog-levels
warn,crit
./uniset2-start.sh
-f
./tests_with_sm
$*
--
--confile
tests_with_sm.xml
--e-startup-pause
10
--ulog-
add-levels
system,
warn,crit
--dlog-levels
warn,crit
include/OmniThreadCreator.h
View file @
54b685e2
...
...
@@ -104,6 +104,8 @@ class OmniThreadCreator:
inline
void
stop
(){
exit
(
0
);
}
inline
pid_t
getTID
(){
return
id
();
}
inline
void
join
(){
omni_thread
::
join
(
NULL
);
}
protected
:
void
*
run_undetached
(
void
*
x
)
{
...
...
include/PassiveTimer.h
View file @
54b685e2
...
...
@@ -27,6 +27,10 @@
#include <signal.h>
#include <sys/time.h>
#include <cc++/socket.h>
#include <condition_variable>
#include <thread>
#include <mutex>
#include <atomic>
#include "Mutex.h"
//----------------------------------------------------------------------------------------
/*! \class UniSetTimer
...
...
@@ -111,53 +115,48 @@ private:
};
//----------------------------------------------------------------------------------------
class
omni_mutex
;
class
omni_condition
;
/*! \class ThrPassiveTimer
/*! \class PassiveCondTimer
* \brief Пассивный таймер с режимом засыпания (ожидания)
* \author Pavel Vainerman
* \par
* Позволяет заснуть на заданное время wait(timeout_t timeMS).
* Механизм работает на основе
взаимных блокировок потоков (mutex и condition).
* Механизм работает на основе
std::condition_variable
* \note Если таймер запущен в режиме ожидания (WaitUpTime), то он может быть выведен из него
* при помощи terminate().
*
ТОЛЬКО
при помощи terminate().
*/
class
ThrPassive
Timer
:
class
PassiveCond
Timer
:
public
PassiveTimer
{
public
:
ThrPassive
Timer
();
~
ThrPassive
Timer
();
PassiveCond
Timer
();
~
PassiveCond
Timer
();
virtual
bool
wait
(
timeout_t
timeMS
);
/*!< блокировать вызывающий поток на заданное время */
virtual
void
terminate
();
/*!< прервать работу таймера */
protected
:
bool
isTerminated
();
void
setTerminated
(
bool
set
);
private
:
bool
terminated
;
omni_mutex
*
tmutex
;
omni_condition
*
tcondx
;
UniSetTypes
::
uniset_mutex
term_mutex
;
std
::
atomic_bool
terminated
;
std
::
mutex
m_working
;
std
::
condition_variable
cv_working
;
};
//----------------------------------------------------------------------------------------
/*! \class PassiveS
ys
Timer
/*! \class PassiveS
ig
Timer
* \brief Пассивный таймер с режимом засыпания (ожидания)
* \author Pavel Vainerman
* \par
* Создан на основе сигнала (SIGALRM).
*/
class
PassiveS
ys
Timer
:
class
PassiveS
ig
Timer
:
public
PassiveTimer
{
public
:
PassiveS
ys
Timer
();
~
PassiveS
ys
Timer
();
PassiveS
ig
Timer
();
~
PassiveS
ig
Timer
();
virtual
bool
wait
(
timeout_t
timeMS
);
//throw(UniSetTypes::NotSetSignal);
virtual
void
terminate
();
...
...
include/ThreadCreator.h
View file @
54b685e2
...
...
@@ -137,6 +137,8 @@ class ThreadCreator:
{
if
(
finm
)
(
finm
->*
finact
)();
//delete this;
}
virtual
void
initial
()
...
...
include/UniSetActivator.h
View file @
54b685e2
...
...
@@ -110,12 +110,11 @@ class UniSetActivator:
static
std
::
shared_ptr
<
UniSetActivator
>
inst
;
private
:
friend
void
terminate_thread
();
friend
void
finished_thread
();
friend
std
::
shared_ptr
<
UniSetTypes
::
Configuration
>
UniSetTypes
::
uniset_init
(
int
argc
,
const
char
*
const
*
argv
,
const
std
::
string
&
xmlfile
);
static
void
terminated
(
int
signo
);
// static void finishterm(int signo);
static
void
normalexit
();
static
void
normalterminate
();
static
void
set_signals
(
bool
ask
);
...
...
include/UniSetObject.h
View file @
54b685e2
...
...
@@ -26,6 +26,10 @@
#ifndef UniSetObject_H_
#define UniSetObject_H_
//--------------------------------------------------------------------------
#include <condition_variable>
#include <thread>
#include <mutex>
#include <atomic>
#include <unistd.h>
#include <sys/time.h>
#include <queue>
...
...
@@ -135,7 +139,7 @@ class UniSetObject:
* Например переход в безопасное состояние.
* \warning В обработчике сигналов \b ЗАПРЕЩЕНО вызывать функции подобные exit(..), abort()!!!!
*/
virtual
void
sigterm
(
int
signo
)
{}
;
virtual
void
sigterm
(
int
signo
);
inline
void
terminate
(){
deactivate
();
}
...
...
@@ -249,7 +253,12 @@ class UniSetObject:
// статистическая информация
unsigned
long
stMaxQueueMessages
;
/*<! Максимальное число сообщений хранившихся в очереди */
unsigned
long
stCountOfQueueFull
;
/*! количество переполнений очереди сообщений */
unsigned
long
stCountOfQueueFull
;
/*!< количество переполнений очереди сообщений */
std
::
atomic_bool
a_working
;
std
::
mutex
m_working
;
std
::
condition_variable
cv_working
;
// timeout_t workingTerminateTimeout; /*!< время ожидания завершения потока */
};
//---------------------------------------------------------------------------
#endif
...
...
src/Interfaces/UInterface.cc
View file @
54b685e2
...
...
@@ -1929,7 +1929,16 @@ bool UInterface::waitReady( const ObjectId id, int msec, int pmsec, const Object
if
(
ready
)
break
;
}
catch
(...){}
catch
(
CORBA
::
OBJECT_NOT_EXIST
)
{
}
catch
(
CORBA
::
COMM_FAILURE
&
ex
)
{
}
catch
(...)
{
break
;
}
msleep
(
pmsec
);
}
...
...
src/ObjectRepository/UniSetActivator.cc
View file @
54b685e2
...
...
@@ -63,9 +63,12 @@ using namespace std;
- завершение CORBA-потока (если был создан) (функция work).
- orb destroy
Для защиты от "зависания" во время завершения, создаётся ещё один временный поток g_fini_thread,
который в течение TERMINATE_TIMEOUT секунд ждёт события 'g_finievent'. После чего происходит
"принудительное" отключение, обработчики сигналов восстанавливаются на умолчательные и процесс
Для защиты от "зависания" во время завершения, создаётся ещё один поток g_kill_thread, который ожидает завершения
в течение KILL_TIMEOUT и формирует сигнал SIGKILL если в течение этого времени не выставился флаг g_done = true;
Помимио этого в процессе завершения создаётся временный поток g_fini_thread,
который в течение TERMINATE_TIMEOUT секунд ждёт события 'g_finievent' (от процесса остановки котока для ORB).
После чего происходит "принудительное" отключение, обработчики сигналов восстанавливаются на умолчательные и процесс
завершается..
В случае, если для UniSetActivator был создан отдельный поток ( run(true) ) при завершении работы программы
...
...
@@ -89,7 +92,9 @@ static std::mutex g_donemutex;
static
std
::
condition_variable
g_doneevent
;
static
std
::
shared_ptr
<
std
::
thread
>
g_term_thread
;
static
std
::
shared_ptr
<
std
::
thread
>
g_fini_thread
;
static
std
::
shared_ptr
<
std
::
thread
>
g_kill_thread
;
static
const
int
TERMINATE_TIMEOUT
=
3
;
// время отведенное на завершение процесса [сек]
static
const
int
KILL_TIMEOUT
=
8
;
// ------------------------------------------------------------------------------------------
static
void
activator_terminate
(
int
signo
)
{
...
...
@@ -111,7 +116,7 @@ static void activator_terminate( int signo )
// ------------------------------------------------------------------------------------------
void
finished_thread
()
{
ulogsys
<<
"****** FINISHED
THREAD
START **** "
<<
endl
<<
flush
;
ulogsys
<<
"****** FINISHED START **** "
<<
endl
<<
flush
;
std
::
unique_lock
<
std
::
mutex
>
lk
(
g_finimutex
);
if
(
g_finished
)
...
...
@@ -121,7 +126,25 @@ void finished_thread()
std
::
unique_lock
<
std
::
mutex
>
lkw
(
g_workmutex
);
g_finievent
.
wait_for
(
lkw
,
std
::
chrono
::
milliseconds
(
TERMINATE_TIMEOUT
*
1000
),
[](){
return
(
g_work_stopped
==
true
);
}
);
ulogsys
<<
"****** FINISHED THREAD END.."
<<
endl
<<
flush
;
ulogsys
<<
"****** FINISHED END ****"
<<
endl
<<
flush
;
}
// ------------------------------------------------------------------------------------------
void
kill_thread
()
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
g_donemutex
);
if
(
g_done
)
return
;
g_doneevent
.
wait_for
(
lk
,
std
::
chrono
::
milliseconds
(
KILL_TIMEOUT
*
1000
),
[](){
return
(
g_done
==
true
);
}
);
if
(
!
g_done
)
{
ulogsys
<<
"****** KILL TIMEOUT.. *******"
<<
endl
<<
flush
;
raise
(
SIGKILL
);
}
ulogsys
<<
"KILL THREAD: ..bye.."
<<
endl
;
}
// ------------------------------------------------------------------------------------------
void
terminate_thread
()
...
...
@@ -138,49 +161,75 @@ void terminate_thread()
// g_termmutex надо отпустить, т.к. он будет проверяться в ~UniSetActvator
}
ulogsys
<<
"****** TERMINATE THREAD: event signo="
<<
g_signo
<<
endl
<<
flush
;
{
std
::
unique_lock
<
std
::
mutex
>
locker
(
g_finimutex
);
if
(
g_finished
)
return
;
}
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
g_donemutex
);
g_done
=
false
;
g_kill_thread
=
make_shared
<
std
::
thread
>
(
kill_thread
);
}
if
(
g_act
)
{
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
g_finimutex
);
if
(
g_finished
)
{
ulogsys
<<
"...FINISHED
TREAD
ALREADY STARTED..."
<<
endl
<<
flush
;
ulogsys
<<
"...FINISHED ALREADY STARTED..."
<<
endl
<<
flush
;
return
;
}
g_fini_thread
=
make_shared
<
std
::
thread
>
(
finished_thread
);
}
ulogsys
<<
"TERMINATE THREAD: call terminated.."
<<
endl
<<
flush
;
try
{
ulogsys
<<
"TERMINATE THREAD: destroy.."
<<
endl
;
g_act
->
orb
->
shutdown
(
true
);
ulogsys
<<
"TERMINATE THREAD: destroy ok.."
<<
endl
;
}
catch
(
omniORB
::
fatalException
&
fe
)
{
ulogsys
<<
"(TERMINATE THREAD): : поймали omniORB::fatalException:"
<<
endl
;
ulogsys
<<
"(TERMINATE THREAD): file: "
<<
fe
.
file
()
<<
endl
;
ulogsys
<<
"(TERMINATE THREAD): line: "
<<
fe
.
line
()
<<
endl
;
ulogsys
<<
"(TERMINATE THREAD): mesg: "
<<
fe
.
errmsg
()
<<
endl
;
}
catch
(
std
::
exception
&
ex
)
{
ulogsys
<<
"(TERMINATE THREAD): "
<<
ex
.
what
()
<<
endl
;
}
ulogsys
<<
"(TERMINATE THREAD): call terminated.."
<<
endl
<<
flush
;
g_act
->
terminated
(
g_signo
);
if
(
g_fini_thread
&&
g_fini_thread
->
joinable
()
)
g_fini_thread
->
join
();
ulogsys
<<
"
TERMINATE THREAD
: FINISHED OK.."
<<
endl
<<
flush
;
ulogsys
<<
"
(TERMINATE THREAD)
: FINISHED OK.."
<<
endl
<<
flush
;
if
(
g_act
&&
g_act
->
orb
)
{
try
{
ulogsys
<<
"
TERMINATE THREAD
: destroy.."
<<
endl
;
ulogsys
<<
"
(TERMINATE THREAD)
: destroy.."
<<
endl
;
g_act
->
orb
->
destroy
();
ulogsys
<<
"
TERMINATE THREAD
: destroy ok.."
<<
endl
;
ulogsys
<<
"
(TERMINATE THREAD)
: destroy ok.."
<<
endl
;
}
catch
(
omniORB
::
fatalException
&
fe
)
{
ulogsys
<<
"(
uaDestroy
): : поймали omniORB::fatalException:"
<<
endl
;
ulogsys
<<
"(
uaDestroy
): file: "
<<
fe
.
file
()
<<
endl
;
ulogsys
<<
"(
uaDestroy
): line: "
<<
fe
.
line
()
<<
endl
;
ulogsys
<<
"(
uaDestroy
): mesg: "
<<
fe
.
errmsg
()
<<
endl
;
ulogsys
<<
"(
TERMINATE THREAD
): : поймали omniORB::fatalException:"
<<
endl
;
ulogsys
<<
"(
TERMINATE THREAD
): file: "
<<
fe
.
file
()
<<
endl
;
ulogsys
<<
"(
TERMINATE THREAD
): line: "
<<
fe
.
line
()
<<
endl
;
ulogsys
<<
"(
TERMINATE THREAD
): mesg: "
<<
fe
.
errmsg
()
<<
endl
;
}
catch
(
std
::
exception
&
ex
)
{
ulogsys
<<
"(
destructor
): "
<<
ex
.
what
()
<<
endl
;
ulogsys
<<
"(
TERMINATE THREAD
): "
<<
ex
.
what
()
<<
endl
;
}
}
...
...
@@ -188,14 +237,14 @@ void terminate_thread()
UniSetActivator
::
set_signals
(
false
);
}
ulogsys
<<
"TERMINATE THREAD: ..bye.."
<<
endl
;
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
g_donemutex
);
g_done
=
true
;
}
g_doneevent
.
notify_all
();
g_kill_thread
->
join
();
ulogsys
<<
"(TERMINATE THREAD): ..bye.."
<<
endl
;
}
// ---------------------------------------------------------------------------
UniSetActivatorPtr
UniSetActivator
::
inst
;
...
...
@@ -204,7 +253,7 @@ UniSetActivatorPtr UniSetActivator::Instance( const UniSetTypes::ObjectId id )
{
if
(
inst
==
nullptr
)
{
inst
=
s
td
::
s
hared_ptr
<
UniSetActivator
>
(
new
UniSetActivator
(
id
)
);
inst
=
shared_ptr
<
UniSetActivator
>
(
new
UniSetActivator
(
id
)
);
g_act
=
inst
;
}
...
...
@@ -251,8 +300,10 @@ void UniSetActivator::init()
if
(
CORBA
::
is_nil
(
poa
)
)
ucrit
<<
myname
<<
"(init): init poa failed!!!"
<<
endl
;
atexit
(
UniSetActivator
::
normalexit
);
set_terminate
(
UniSetActivator
::
normalterminate
);
// ловушка для неизвестных исключений
// Чтобы подключиться к функциям завершения как можно раньше (раньше создания объектов)
// этот код перенесён в Configuration::uniset_init (в надежде, что uniset_init всегда вызывается одной из первых).
// atexit( UniSetActivator::normalexit );
// set_terminate( UniSetActivator::normalterminate ); // ловушка для неизвестных исключений
}
// ------------------------------------------------------------------------------------------
...
...
@@ -269,8 +320,8 @@ UniSetActivator::~UniSetActivator()
g_termevent
.
notify_one
();
ulogsys
<<
myname
<<
"(run): wait done.."
<<
endl
;
#if 1
if
(
g_term_thread
->
joinable
()
)
g_term_thread
->
join
();
//
if( g_term_thread->joinable() )
//
g_term_thread->join();
#else
std
::
unique_lock
<
std
::
mutex
>
locker
(
g_donemutex
);
while
(
!
g_done
)
...
...
@@ -360,6 +411,7 @@ void UniSetActivator::run( bool thread )
msleep
(
50
);
set_signals
(
true
);
if
(
thread
)
{
uinfo
<<
myname
<<
"(run): запускаемся с созданием отдельного потока... "
<<
endl
;
...
...
@@ -446,7 +498,6 @@ void UniSetActivator::work()
}
ulogsys
<<
myname
<<
"(work): orb thread stopped!"
<<
endl
<<
flush
;
// orbthr = nullptr;
{
std
::
unique_lock
<
std
::
mutex
>
lkw
(
g_workmutex
);
...
...
@@ -456,9 +507,8 @@ void UniSetActivator::work()
if
(
orbthr
)
{
// HACK: почему-то мы должны тут застрять, пока не завершится основной процесс
// (terminate_thread) иначе возникает double free corruption.. :(
// возможно что-то некорректно с уничтожением orbthr..
// HACK: почему-то мы должны тут застрять,
// где-то что-то некорректно с уничтожением потока..
pause
();
}
}
...
...
@@ -550,7 +600,6 @@ void UniSetActivator::terminated( int signo )
ulogsys
<<
"terminated ok.."
<<
endl
;
}
// ------------------------------------------------------------------------------------------
void
UniSetActivator
::
normalexit
()
{
if
(
g_act
)
...
...
@@ -570,12 +619,15 @@ void UniSetActivator::normalexit()
ulogsys
<<
"(default exit): wait done.."
<<
endl
<<
flush
;
#if 1
if
(
g_term_thread
->
joinable
()
)
if
(
g_term_thread
&&
g_term_thread
->
joinable
()
)
g_term_thread
->
join
();
#else
if
(
g_doneevent
)
{
std
::
unique_lock
<
std
::
mutex
>
locker
(
g_donemutex
);
while
(
!
g_done
)
g_doneevent
.
wait
(
locker
);
}
#endif
ulogsys
<<
"(default exit): wait done OK (good bye)"
<<
endl
<<
flush
;
...
...
@@ -601,12 +653,15 @@ void UniSetActivator::normalterminate()
ulogsys
<<
"(default terminate): wait done.."
<<
endl
<<
flush
;
#if 1
if
(
g_term_thread
->
joinable
()
)
if
(
g_term_thread
&&
g_term_thread
->
joinable
()
)
g_term_thread
->
join
();
#else
if
(
g_doneevent
)
{
std
::
unique_lock
<
std
::
mutex
>
locker
(
g_donemutex
);
while
(
!
g_done
)
g_doneevent
.
wait
(
locker
);
}
#endif
ulogsys
<<
"(default terminate): wait done OK (good bye)"
<<
endl
<<
flush
;
}
...
...
src/ObjectRepository/UniSetObject.cc
View file @
54b685e2
...
...
@@ -27,6 +27,7 @@
#include <pthread.h>
#include <sys/types.h>
#include <sstream>
#include <chrono>
#include "Exceptions.h"
#include "ORepHelpers.h"
...
...
@@ -40,7 +41,7 @@
using
namespace
std
;
using
namespace
UniSetTypes
;
#define CREATE_TIMER make_shared<
ThrPassive
Timer>();
#define CREATE_TIMER make_shared<
PassiveCond
Timer>();
// new PassiveSysTimer();
// ------------------------------------------------------------------------------------------
...
...
@@ -153,6 +154,9 @@ UniSetObject::~UniSetObject()
// ------------------------------------------------------------------------------------------
void
UniSetObject
::
init_object
()
{
a_working
=
ATOMIC_VAR_INIT
(
0
);
active
=
ATOMIC_VAR_INIT
(
0
);
qmutex
.
setName
(
myname
+
"_qmutex"
);
refmutex
.
setName
(
myname
+
"_refmutex"
);
// mutex_act.setName(myname + "_mutex_act");
...
...
@@ -160,11 +164,8 @@ void UniSetObject::init_object()
auto
conf
=
uniset_conf
();
SizeOfMessageQueue
=
conf
->
getArgPInt
(
"--uniset-object-size-message-queue"
,
conf
->
getField
(
"SizeOfMessageQueue"
),
1000
);
MaxCountRemoveOfMessage
=
conf
->
getArgInt
(
"--uniset-object-maxcount-remove-message"
,
conf
->
getField
(
"MaxCountRemoveOfMessage"
));
if
(
MaxCountRemoveOfMessage
<=
0
)
MaxCountRemoveOfMessage
=
SizeOfMessageQueue
/
4
;
if
(
MaxCountRemoveOfMessage
<=
0
)
MaxCountRemoveOfMessage
=
10
;
MaxCountRemoveOfMessage
=
conf
->
getArgPInt
(
"--uniset-object-maxcount-remove-message"
,
conf
->
getField
(
"MaxCountRemoveOfMessage"
),
SizeOfMessageQueue
/
4
);
// workingTerminateTimeout = conf->getArgPInt("--uniset-object-working-terminate-timeout",conf->getField("WorkingTerminateTimeout"),2000);
uinfo
<<
myname
<<
"(init): SizeOfMessageQueue="
<<
SizeOfMessageQueue
<<
" MaxCountRemoveOfMessage="
<<
MaxCountRemoveOfMessage
...
...
@@ -610,6 +611,10 @@ unsigned int UniSetObject::countMessages()
}
}
// ------------------------------------------------------------------------------------------
void
UniSetObject
::
sigterm
(
int
signo
)
{
}
// ------------------------------------------------------------------------------------------
bool
UniSetObject
::
deactivate
()
{
if
(
!
isActive
()
)
...
...
@@ -624,7 +629,17 @@ bool UniSetObject::deactivate()
setActive
(
false
);
// завершаем поток обработки сообщений
if
(
tmr
)
tmr
->
stop
();
tmr
->
terminate
();
if
(
thr
)
{
std
::
unique_lock
<
std
::
mutex
>
lk
(
m_working
);
// cv_working.wait_for(lk, std::chrono::milliseconds(workingTerminateTimeout), [&](){ return (a_working == false); } );
if
(
a_working
)
cv_working
.
wait
(
lk
);
if
(
a_working
)
thr
->
stop
();
}
// Очищаем очередь
{
// lock
...
...
@@ -745,6 +760,10 @@ bool UniSetObject::activate()
if
(
myid
!=
UniSetTypes
::
DefaultObjectId
&&
threadcreate
)
{
thr
=
make_shared
<
ThreadCreator
<
UniSetObject
>
>
(
this
,
&
UniSetObject
::
work
);
thr
->
setCancel
(
ost
::
Thread
::
cancelDeferred
);
std
::
unique_lock
<
std
::
mutex
>
locker
(
m_working
);
a_working
=
true
;
thr
->
start
();
}
else
...
...
@@ -767,10 +786,22 @@ void UniSetObject::work()
if
(
thr
)
msgpid
=
thr
->
getTID
();
{
std
::
unique_lock
<
std
::
mutex
>
locker
(
m_working
);
a_working
=
true
;
}
while
(
isActive
()
)
callback
();
uinfo
<<
myname
<<
": thread processing messages stopped..."
<<
endl
;
{
std
::
unique_lock
<
std
::
mutex
>
locker
(
m_working
);
a_working
=
false
;
}
cv_working
.
notify_all
();
}
// ------------------------------------------------------------------------------------------
void
UniSetObject
::
callback
()
...
...
src/Timers/Makefile.am
View file @
54b685e2
...
...
@@ -2,4 +2,4 @@
# This file is part of the UniSet library #
############################################################################
noinst_LTLIBRARIES
=
libTimers.la
libTimers_la_SOURCES
=
PassiveTimer.cc PassiveS
ysTimer.cc ThrPassive
Timer.cc
libTimers_la_SOURCES
=
PassiveTimer.cc PassiveS
igTimer.cc PassiveCond
Timer.cc
src/Timers/
ThrPassive
Timer.cc
→
src/Timers/
PassiveCond
Timer.cc
View file @
54b685e2
...
...
@@ -25,76 +25,45 @@
#include <unistd.h>
#include <sstream>
#include <time.h>
#include <omnithread.h>
#include "PassiveTimer.h"
// ------------------------------------------------------------------------------------------
using
namespace
std
;
// ------------------------------------------------------------------------------------------
ThrPassiveTimer
::
ThrPassive
Timer
()
:
terminated
(
1
)
PassiveCondTimer
::
PassiveCond
Timer
()
:
terminated
(
ATOMIC_VAR_INIT
(
1
)
)
{
// были сделаны указателями
// чтобы уйти от include в head-файле
tmutex
=
new
omni_mutex
();
tcondx
=
new
omni_condition
(
tmutex
);
}
// ------------------------------------------------------------------------------------------
ThrPassiveTimer
::~
ThrPassive
Timer
()
PassiveCondTimer
::~
PassiveCond
Timer
()
{
terminate
();
// while( !terminated ){};
delete
tcondx
;
delete
tmutex
;
}
// ------------------------------------------------------------------------------------------
bool
ThrPassiveTimer
::
isTerminated
()
{
UniSetTypes
::
uniset_mutex_lock
l
(
term_mutex
,
100
);
return
terminated
;
}
// ------------------------------------------------------------------------------------------
void
ThrPassiveTimer
::
setTerminated
(
bool
set
)
{
UniSetTypes
::
uniset_mutex_lock
l
(
term_mutex
,
200
);
terminated
=
set
;
}
// ------------------------------------------------------------------------------------------
void
ThrPassive
Timer
::
terminate
()
void
PassiveCond
Timer
::
terminate
()
{
if
(
!
isTerminated
()
)
{
s
etTerminated
(
true
);
t
condx
->
signal
()
;
s
td
::
unique_lock
<
std
::
mutex
>
lk
(
m_working
);
t
erminated
=
true
;
}
cv_working
.
notify_all
();
}
// ------------------------------------------------------------------------------------------
bool
ThrPassive
Timer
::
wait
(
timeout_t
time_msec
)
bool
PassiveCond
Timer
::
wait
(
timeout_t
time_msec
)
{
s
etTerminated
(
false
);
{
tmutex
->
lock
();
s
td
::
unique_lock
<
std
::
mutex
>
lk
(
m_working
);
terminated
=
false
;
timeout_t
t_msec
=
PassiveTimer
::
setTiming
(
time_msec
);
// вызываем для совместимости с обычным PassiveTimer-ом
if
(
time_msec
==
WaitUpTime
)
{
while
(
!
isTerminated
()
)
// на всякий, вдруг проснется по ошибке...
tcondx
->
wait
(
);
while
(
!
terminated
)
cv_working
.
wait
(
lk
);
}
else
{
unsigned
long
sec
,
msec
;
omni_thread
::
get_time
(
&
sec
,
&
msec
,
t_msec
/
1000
,
(
t_msec
%
1000
)
*
1000000
);
// cout <<"timer: спим "<< timeMS/1000 << "[сек] и " << (timeMS%1000)*1000000 <<"[мсек]" << endl;
tcondx
->
timedwait
(
sec
,
msec
);
}
cv_working
.
wait_for
(
lk
,
std
::
chrono
::
milliseconds
(
t_msec
),
[
&
](){
return
(
terminated
==
true
);
}
);
tmutex
->
unlock
();
}
setTerminated
(
true
);
terminated
=
true
;
return
true
;
}
// ------------------------------------------------------------------------------------------
src/Timers/PassiveS
ys
Timer.cc
→
src/Timers/PassiveS
ig
Timer.cc
View file @
54b685e2
...
...
@@ -34,30 +34,30 @@
using
namespace
std
;
//using namespace UniSetTypes;
// ------------------------------------------------------------------------------------------
void
PassiveS
ys
Timer
::
call
(
int
signo
,
siginfo_t
*
evp
,
void
*
ucontext
)
void
PassiveS
ig
Timer
::
call
(
int
signo
,
siginfo_t
*
evp
,
void
*
ucontext
)
{
cout
<<
"PassiveS
ys
Timer: callme time="
<<
evp
->
si_value
.
sival_int
<<
" ms"
<<
endl
;
cout
<<
"PassiveS
ig
Timer: callme time="
<<
evp
->
si_value
.
sival_int
<<
" ms"
<<
endl
;
}
void
PassiveS
ys
Timer
::
callalrm
(
int
signo
)
void
PassiveS
ig
Timer
::
callalrm
(
int
signo
)
{
// cout << "PassiveS
ys
Timer: callme signo "<< signo <<endl;
// cout << "PassiveS
ig
Timer: callme signo "<< signo <<endl;
}
// ------------------------------------------------------------------------------------------
PassiveS
ysTimer
::
PassiveSys
Timer
()
:
PassiveS
igTimer
::
PassiveSig
Timer
()
:
terminated
(
1
)
{
init
();
}
// ------------------------------------------------------------------------------------------
PassiveS
ysTimer
::~
PassiveSys
Timer
()
PassiveS
igTimer
::~
PassiveSig
Timer
()
{
terminate
();
}
// ------------------------------------------------------------------------------------------
void
PassiveS
ys
Timer
::
init
()
void
PassiveS
ig
Timer
::
init
()
{
/*
struct itimerval val;
...
...
@@ -69,13 +69,13 @@ void PassiveSysTimer::init()
if( sigaction(SIGALRM, &action, 0) == -1)
{
cerr << "PassiveS
ys
Timer: error sigaction" << endl;
cerr << "PassiveS
ig
Timer: error sigaction" << endl;
throw NotSetSignal("PassiveTimer: errir sigaction");
}
*/
}
// ------------------------------------------------------------------------------------------
void
PassiveS
ys
Timer
::
terminate
()
void
PassiveS
ig
Timer
::
terminate
()
{
if
(
!
terminated
)
{
...
...
@@ -86,7 +86,7 @@ void PassiveSysTimer::terminate()
}
}
// ------------------------------------------------------------------------------------------
bool
PassiveS
ys
Timer
::
wait
(
timeout_t
timeMS
)
bool
PassiveS
ig
Timer
::
wait
(
timeout_t
timeMS
)
{
pid
=
getpid
();
...
...
@@ -99,7 +99,7 @@ bool PassiveSysTimer::wait(timeout_t timeMS)
if
(
sigaction
(
SIGALRM
,
&
action
,
0
)
==
-
1
)
{
cerr
<<
"PassiveS
ys
Timer: error sigaction"
<<
endl
;
cerr
<<
"PassiveS
ig
Timer: error sigaction"
<<
endl
;
return
false
;
}
...
...
@@ -147,7 +147,7 @@ bool PassiveSysTimer::wait(timeout_t timeMS)
terminated
=
1
;
sigprocmask
(
SIG_UNBLOCK
,
&
mask
,
NULL
);
// cout << "PassiveS
ys
Timer: time ok"<< endl;
// cout << "PassiveS
ig
Timer: time ok"<< endl;
return
true
;
}
...
...
src/Various/Configuration.cc
View file @
54b685e2
...
...
@@ -37,6 +37,7 @@
#include "ObjectIndex_Array.h"
#include "ObjectIndex_XML.h"
#include "ObjectIndex_idXML.h"
#include "UniSetActivator.h"
// -------------------------------------------------------------------------
using
namespace
std
;
// -------------------------------------------------------------------------
...
...
@@ -1027,6 +1028,9 @@ std::shared_ptr<Configuration> uniset_init( int argc, const char* const* argv, c
return
UniSetTypes
::
uconf
;
}
atexit
(
UniSetActivator
::
normalexit
);
set_terminate
(
UniSetActivator
::
normalterminate
);
// ловушка для неизвестных исключений
string
confile
=
UniSetTypes
::
getArgParam
(
"--confile"
,
argc
,
argv
,
xmlfile
);
ulog
.
setLogName
(
"ulog"
);
UniSetTypes
::
uconf
=
make_shared
<
Configuration
>
(
argc
,
argv
,
confile
);
...
...
src/Various/SViewer.cc
View file @
54b685e2
tests/Makefile.am
View file @
54b685e2
...
...
@@ -11,6 +11,7 @@ tests_LDADD = $(top_builddir)/lib/libUniSet2.la $(SIGC_LIBS) $(COMCPP_LIBS) $(C
tests_CPPFLAGS
=
-I
$(top_builddir)
/include
$(SIGC_CFLAGS)
$(COMCPP_CFLAGS)
$(COV_CFLAGS)
tests_SOURCES
=
tests.cc
\
test_passivetimer.cc
\
test_passivecondtimer.cc
\
test_hourglass.cc
\
test_delaytimer.cc
\
test_unixml.cc
\
...
...
tests/test_hourglass.cc
View file @
54b685e2
...
...
@@ -81,7 +81,7 @@ TEST_CASE("HourGlass", "[HourGlass]" )
REQUIRE
(
hg
.
amount
()
>=
60
);
hg
.
rotate
(
false
);
// опять назад..
msleep
(
80
);
// по сути сигнал сбросился..(т.к. оставалось 70.. а прошло 8
0)
msleep
(
90
);
// по сути сигнал сбросился..(т.к. оставалось 70.. а прошло 9
0)
CHECK_FALSE
(
hg
.
check
()
);
REQUIRE
(
hg
.
amount
()
==
0
);
REQUIRE
(
hg
.
remain
()
==
100
);
...
...
tests/test_passivecondtimer.cc
0 → 100644
View file @
54b685e2
#include <catch.hpp>
#include "PassiveTimer.h"
#include "UniSetTypes.h"
using
namespace
std
;
// --------------------------------------------------------------------------
static
std
::
atomic_int
g_num
=
ATOMIC_VAR_INIT
(
0
);
static
std
::
mutex
g_mutex
;
static
std
::
shared_ptr
<
PassiveCondTimer
>
tmr
;
// --------------------------------------------------------------------------
void
thread_function
(
int
msec
)
{
try
{
msleep
(
msec
);
/*
std::chrono::milliseconds dura( msec );
mstd::sleep_for( dura );
*/
if
(
tmr
)
tmr
->
terminate
();
}
catch
(
std
::
exception
&
ex
)
{
FAIL
(
ex
.
what
()
);
}
}
TEST_CASE
(
"PassiveCondTimer: wait"
,
"[PassiveTimer][PassiveCondTimer]"
)
{
tmr
=
make_shared
<
PassiveCondTimer
>
();
PassiveTimer
ptTime
;
tmr
->
wait
(
300
);
REQUIRE
(
ptTime
.
getCurrent
()
>=
300
);
REQUIRE
(
ptTime
.
getCurrent
()
<=
340
);
tmr
.
reset
();
}
// --------------------------------------------------------------------------
TEST_CASE
(
"PassiveCondTimer: waitup"
,
"[PassiveTimer][PassiveCondTimer]"
)
{
tmr
=
make_shared
<
PassiveCondTimer
>
();
std
::
thread
thr
(
thread_function
,
500
);
PassiveTimer
ptTime
;
tmr
->
wait
(
UniSetTimer
::
WaitUpTime
);
REQUIRE
(
ptTime
.
getCurrent
()
>=
500
);
REQUIRE
(
ptTime
.
getCurrent
()
<=
540
);
thr
.
join
();
tmr
.
reset
();
}
// --------------------------------------------------------------------------
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