Commit 46c1e49f authored by Pavel Vainerman's avatar Pavel Vainerman

(optimization): Исправления по результатам тестирования valgrind

parent 785b6ca9
...@@ -229,15 +229,13 @@ void SharedMemory::sysCommand( SystemMessage *sm ) ...@@ -229,15 +229,13 @@ void SharedMemory::sysCommand( SystemMessage *sm )
case SystemMessage::StartUp: case SystemMessage::StartUp:
{ {
PassiveTimer ptAct(activateTimeout); PassiveTimer ptAct(activateTimeout);
while( !activated && !ptAct.checkTime() ) while( !isActivated() && !ptAct.checkTime() )
{ {
cout << myname << "(sysCommand): wait activate..." << endl; cout << myname << "(sysCommand): wait activate..." << endl;
msleep(100); msleep(100);
if( activated )
break;
} }
if( !activated ) if( !isActivated() )
dlog[Debug::CRIT] << myname << "(sysCommand): ************* don`t activate?! ************" << endl; dlog[Debug::CRIT] << myname << "(sysCommand): ************* don`t activate?! ************" << endl;
// подождать пока пройдёт инициализация // подождать пока пройдёт инициализация
...@@ -300,7 +298,11 @@ bool SharedMemory::activateObject() ...@@ -300,7 +298,11 @@ bool SharedMemory::activateObject()
// пока не пройдёт инициализация датчиков // пока не пройдёт инициализация датчиков
// см. sysCommand() // см. sysCommand()
{ {
activated = false; {
uniset_mutex_lock l(act_mutex,100);
activated = false;
}
UniSetTypes::uniset_mutex_lock l(mutex_start, 5000); UniSetTypes::uniset_mutex_lock l(mutex_start, 5000);
res = IONotifyController_LT::activateObject(); res = IONotifyController_LT::activateObject();
...@@ -324,7 +326,10 @@ bool SharedMemory::activateObject() ...@@ -324,7 +326,10 @@ bool SharedMemory::activateObject()
} }
} }
activated = true; {
uniset_mutex_lock l(act_mutex,100);
activated = true;
}
} }
cerr << "************************** activate: " << pt.getCurrent() << " msec " << endl; cerr << "************************** activate: " << pt.getCurrent() << " msec " << endl;
...@@ -883,3 +888,10 @@ std::ostream& operator<<( std::ostream& os, const SharedMemory::HistoryInfo& h ) ...@@ -883,3 +888,10 @@ std::ostream& operator<<( std::ostream& os, const SharedMemory::HistoryInfo& h )
return os; return os;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool SharedMemory::isActivated()
{
uniset_mutex_lock l(act_mutex,300);
return activated;
}
// ------------------------------------------------------------------------------------------
\ No newline at end of file
...@@ -391,12 +391,15 @@ class SharedMemory: ...@@ -391,12 +391,15 @@ class SharedMemory:
void buildHistoryList( xmlNode* cnode ); void buildHistoryList( xmlNode* cnode );
void checkHistoryFilter( UniXML_iterator& it ); void checkHistoryFilter( UniXML_iterator& it );
bool isActivated();
DIOStateList::iterator ditPulsar; DIOStateList::iterator ditPulsar;
IOController_i::SensorInfo siPulsar; IOController_i::SensorInfo siPulsar;
UniversalIO::IOTypes iotypePulsar; UniversalIO::IOTypes iotypePulsar;
int msecPulsar; int msecPulsar;
UniSetTypes::uniset_mutex act_mutex;
private: private:
HistorySlot m_historySignal; HistorySlot m_historySignal;
......
...@@ -27,9 +27,7 @@ ...@@ -27,9 +27,7 @@
#include <signal.h> #include <signal.h>
#include <sys/time.h> #include <sys/time.h>
#include <cc++/socket.h> #include <cc++/socket.h>
//#include "Exceptions.h" #include "Mutex.h"
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
/*! \class UniSetTimer /*! \class UniSetTimer
* \brief Базовый интерфейс пасивных таймеров * \brief Базовый интерфейс пасивных таймеров
...@@ -136,10 +134,14 @@ class ThrPassiveTimer: ...@@ -136,10 +134,14 @@ class ThrPassiveTimer:
virtual bool wait(timeout_t timeMS); /*!< блокировать вызывающий поток на заданное время */ virtual bool wait(timeout_t timeMS); /*!< блокировать вызывающий поток на заданное время */
virtual void terminate(); /*!< прервать работу таймера */ virtual void terminate(); /*!< прервать работу таймера */
protected: protected:
bool isTerminated();
void setTerminated( bool set );
private: private:
volatile sig_atomic_t terminated; bool terminated;
omni_mutex* tmutex; omni_mutex* tmutex;
omni_condition* tcondx; omni_condition* tcondx;
UniSetTypes::uniset_mutex term_mutex;
}; };
//---------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------
......
...@@ -186,6 +186,8 @@ class UniSetObject: ...@@ -186,6 +186,8 @@ class UniSetObject:
void setPushMutexTimeout( unsigned long msec ); void setPushMutexTimeout( unsigned long msec );
unsigned long getPushMutexTimeout(){ return pushMutexTimeout; } unsigned long getPushMutexTimeout(){ return pushMutexTimeout; }
bool isActive();
void setActive( bool set );
UniSetTypes::VoidMessage msg; UniSetTypes::VoidMessage msg;
ObjectsManager* mymngr; ObjectsManager* mymngr;
...@@ -216,6 +218,7 @@ class UniSetObject: ...@@ -216,6 +218,7 @@ class UniSetObject:
pid_t msgpid; // pid потока обработки сообщений pid_t msgpid; // pid потока обработки сообщений
bool reg; bool reg;
bool active; bool active;
UniSetTypes::uniset_mutex act_mutex;
bool threadcreate; bool threadcreate;
UniSetTimer* tmr; UniSetTimer* tmr;
UniSetTypes::ObjectId myid; UniSetTypes::ObjectId myid;
......
...@@ -72,7 +72,8 @@ namespace ORepHelpers ...@@ -72,7 +72,8 @@ namespace ORepHelpers
CosNaming::NamingContext_var ctx; CosNaming::NamingContext_var ctx;
try try
{ {
ctx = CosNaming::NamingContext::_narrow( rootC->resolve(ctxName) ); CORBA::Object_var o = rootC->resolve(ctxName);
ctx = CosNaming::NamingContext::_narrow(o);
if( CORBA::is_nil(ctx) ) if( CORBA::is_nil(ctx) )
{ {
const string err("OREPHELPER(getContext): не смог получить ссылку на контекст(is_nil) "+cname); const string err("OREPHELPER(getContext): не смог получить ссылку на контекст(is_nil) "+cname);
...@@ -142,7 +143,7 @@ namespace ORepHelpers ...@@ -142,7 +143,7 @@ namespace ORepHelpers
try try
{ {
// cout << "ORepHelpers(getRootNamingContext): nsName->" << nsName << endl; // cout << "ORepHelpers(getRootNamingContext): nsName->" << nsName << endl;
CORBA::Object_var initServ(orb->resolve_initial_references(nsName.c_str())); CORBA::Object_var initServ = orb->resolve_initial_references(nsName.c_str());
unideb[Debug::REPOSITORY] << "OREPHELP: get rootcontext...(nsName = "<< nsName << ")" <<endl; unideb[Debug::REPOSITORY] << "OREPHELP: get rootcontext...(nsName = "<< nsName << ")" <<endl;
rootContext = CosNaming::NamingContext::_narrow(initServ); rootContext = CosNaming::NamingContext::_narrow(initServ);
if (CORBA::is_nil(rootContext)) if (CORBA::is_nil(rootContext))
......
...@@ -119,10 +119,14 @@ unsigned int ObjectIndex_XML::read_section( UniXML& xml, const std::string sec, ...@@ -119,10 +119,14 @@ unsigned int ObjectIndex_XML::read_section( UniXML& xml, const std::string sec,
{ {
if( (unsigned)ind >= omap.size() ) if( (unsigned)ind >= omap.size() )
{ {
ostringstream msg; if( unideb.debugging(Debug::INFO) )
msg << "(ObjectIndex_XML::build): не хватило размера массива maxSize=" << omap.size(); {
// throw OutOfRange(msg.str()); ostringstream msg;
unideb[Debug::WARN] << msg.str() << "... Делаем resize + 100\n"; msg << "(ObjectIndex_XML::build): не хватило размера массива maxSize=" << omap.size();
// throw OutOfRange(msg.str());
unideb[Debug::WARN] << msg.str() << "... Делаем resize + 100\n";
}
omap.resize(omap.size()+100); omap.resize(omap.size()+100);
} }
...@@ -171,7 +175,7 @@ unsigned int ObjectIndex_XML::read_section( UniXML& xml, const std::string sec, ...@@ -171,7 +175,7 @@ unsigned int ObjectIndex_XML::read_section( UniXML& xml, const std::string sec,
omap[ind].id = ind; omap[ind].id = ind;
// name // name
string name(secname+xml.getProp(it,"name")); const string name(secname + xml.getProp(it,"name"));
delete[] omap[ind].repName; delete[] omap[ind].repName;
omap[ind].repName = new char[name.size()+1]; omap[ind].repName = new char[name.size()+1];
strcpy( omap[ind].repName, name.c_str() ); strcpy( omap[ind].repName, name.c_str() );
...@@ -195,10 +199,13 @@ unsigned int ObjectIndex_XML::read_section( UniXML& xml, const std::string sec, ...@@ -195,10 +199,13 @@ unsigned int ObjectIndex_XML::read_section( UniXML& xml, const std::string sec,
if( (unsigned)ind >= omap.size() ) if( (unsigned)ind >= omap.size() )
{ {
ostringstream msg; if( unideb.debugging(Debug::INFO) )
msg << "(ObjectIndex_XML::build): не хватило размера массива maxSize=" << omap.size(); {
// throw OutOfRange(msg.str()); ostringstream msg;
unideb[Debug::WARN] << msg.str() << "... Делаем resize + 100\n"; msg << "(ObjectIndex_XML::build): не хватило размера массива maxSize=" << omap.size();
// throw OutOfRange(msg.str());
unideb[Debug::INFO] << msg.str() << "... Делаем resize + 100\n";
}
omap.resize(omap.size()+100); omap.resize(omap.size()+100);
} }
} }
......
...@@ -380,6 +380,7 @@ void ObjectsActivator::set_signals(bool ask) ...@@ -380,6 +380,7 @@ void ObjectsActivator::set_signals(bool ask)
struct sigaction act, oact; struct sigaction act, oact;
sigemptyset(&act.sa_mask); sigemptyset(&act.sa_mask);
sigemptyset(&oact.sa_mask);
// добавляем сигналы, которые будут игнорироваться // добавляем сигналы, которые будут игнорироваться
// при обработке сигнала // при обработке сигнала
...@@ -416,7 +417,9 @@ void ObjectsActivator::finishterm( int signo ) ...@@ -416,7 +417,9 @@ void ObjectsActivator::finishterm( int signo )
unideb[Debug::SYSTEM] << gActivator->getName() unideb[Debug::SYSTEM] << gActivator->getName()
<< "(finishterm): прерываем процесс завершения...!" << endl<< flush; << "(finishterm): прерываем процесс завершения...!" << endl<< flush;
ObjectsActivator::set_signals(false); if( gActivator )
gActivator->set_signals(false);
sigset(SIGALRM, SIG_DFL); sigset(SIGALRM, SIG_DFL);
doneterm = 1; doneterm = 1;
raise(SIGKILL); raise(SIGKILL);
......
...@@ -675,7 +675,7 @@ unsigned int UniSetObject::countMessages() ...@@ -675,7 +675,7 @@ unsigned int UniSetObject::countMessages()
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool UniSetObject::disactivate() bool UniSetObject::disactivate()
{ {
if( !active ) if( !isActive() )
{ {
try try
{ {
...@@ -685,7 +685,7 @@ bool UniSetObject::disactivate() ...@@ -685,7 +685,7 @@ bool UniSetObject::disactivate()
return true; return true;
} }
active=false; // завершаем поток обработки сообщений setActive(false); // завершаем поток обработки сообщений
tmr->stop(); tmr->stop();
// Очищаем очередь // Очищаем очередь
...@@ -795,7 +795,7 @@ bool UniSetObject::activate() ...@@ -795,7 +795,7 @@ bool UniSetObject::activate()
registered(); registered();
// Запускаем поток обработки сообщений // Запускаем поток обработки сообщений
active=true; setActive(true);
if( myid!=UniSetTypes::DefaultObjectId && threadcreate ) if( myid!=UniSetTypes::DefaultObjectId && threadcreate )
{ {
...@@ -825,7 +825,7 @@ void UniSetObject::work() ...@@ -825,7 +825,7 @@ void UniSetObject::work()
unideb[Debug::INFO] << myname << ": thread processing messages run..." << endl; unideb[Debug::INFO] << myname << ": thread processing messages run..." << endl;
if( thr ) if( thr )
msgpid = thr->getTID(); msgpid = thr->getTID();
while( active ) while( isActive() )
{ {
callback(); callback();
} }
...@@ -899,5 +899,16 @@ bool UniSetObject::PriorVMsgCompare::operator()(const UniSetTypes::VoidMessage& ...@@ -899,5 +899,16 @@ bool UniSetObject::PriorVMsgCompare::operator()(const UniSetTypes::VoidMessage&
return lhs.priority < rhs.priority; return lhs.priority < rhs.priority;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
void UniSetObject::setActive( bool set )
{
uniset_mutex_lock l(act_mutex,300);
active = set;
}
// ------------------------------------------------------------------------------------------
bool UniSetObject::isActive()
{
uniset_mutex_lock l(act_mutex,200);
return active;
}
// ------------------------------------------------------------------------------------------
#undef CREATE_TIMER #undef CREATE_TIMER
...@@ -151,7 +151,9 @@ bool IOController::localGetState( IOController::DIOStateList::iterator& li, ...@@ -151,7 +151,9 @@ bool IOController::localGetState( IOController::DIOStateList::iterator& li,
ostringstream err; ostringstream err;
err << myname << "(localGetState): дискретный вход(выход) с именем " err << myname << "(localGetState): дискретный вход(выход) с именем "
<< conf->oind->getNameById(si.id) << " не найден"; << conf->oind->getNameById(si.id) << " не найден";
unideb[Debug::INFO] << err.str() << endl;
if( unideb.debugging(Debug::INFO) )
unideb[Debug::INFO] << err.str() << endl;
throw IOController_i::NameNotFound(err.str().c_str()); throw IOController_i::NameNotFound(err.str().c_str());
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -174,7 +176,8 @@ long IOController::localGetValue( IOController::AIOStateList::iterator& li, ...@@ -174,7 +176,8 @@ long IOController::localGetValue( IOController::AIOStateList::iterator& li,
ostringstream err; ostringstream err;
err << myname << "(localGetValue): аналоговый вход(выход) с именем " err << myname << "(localGetValue): аналоговый вход(выход) с именем "
<< conf->oind->getNameById(si.id) << " не найден"; << conf->oind->getNameById(si.id) << " не найден";
unideb[Debug::INFO] << err.str() << endl; if( unideb.debugging(Debug::INFO) )
unideb[Debug::INFO] << err.str() << endl;
throw IOController_i::NameNotFound(err.str().c_str()); throw IOController_i::NameNotFound(err.str().c_str());
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
......
...@@ -50,32 +50,42 @@ ThrPassiveTimer::~ThrPassiveTimer() ...@@ -50,32 +50,42 @@ ThrPassiveTimer::~ThrPassiveTimer()
delete tmutex; 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 ThrPassiveTimer::terminate() void ThrPassiveTimer::terminate()
{ {
if( !terminated ) if( !isTerminated() )
{ {
// tmutex->lock(); setTerminated(true);
terminated = 1;
tcondx->signal(); tcondx->signal();
// tmutex->unlock();
} }
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
bool ThrPassiveTimer::wait(timeout_t timeMS) bool ThrPassiveTimer::wait( timeout_t time_msec )
{ {
terminated = 0; setTerminated(false);
{ {
tmutex->lock(); tmutex->lock();
timeout_t tmMS = PassiveTimer::setTiming(timeMS); // вызываем для совместимости с обычным PassiveTimer-ом timeout_t t_msec = PassiveTimer::setTiming(time_msec); // вызываем для совместимости с обычным PassiveTimer-ом
if( timeMS == WaitUpTime ) if( time_msec == WaitUpTime )
{ {
while( !terminated ) // на всякий, вдруг проснется по ошибке... while( !isTerminated() ) // на всякий, вдруг проснется по ошибке...
tcondx->wait(); tcondx->wait();
} }
else else
{ {
unsigned long sec, msec; unsigned long sec, msec;
omni_thread::get_time(&sec,&msec, tmMS/1000, (tmMS%1000)*1000000 ); omni_thread::get_time(&sec,&msec, t_msec/1000, (t_msec%1000)*1000000 );
// cout <<"timer: спим "<< timeMS/1000 << "[сек] и " << (timeMS%1000)*1000000 <<"[мсек]" << endl; // cout <<"timer: спим "<< timeMS/1000 << "[сек] и " << (timeMS%1000)*1000000 <<"[мсек]" << endl;
tcondx->timedwait(sec, msec); tcondx->timedwait(sec, msec);
} }
...@@ -83,7 +93,7 @@ bool ThrPassiveTimer::wait(timeout_t timeMS) ...@@ -83,7 +93,7 @@ bool ThrPassiveTimer::wait(timeout_t timeMS)
tmutex->unlock(); tmutex->unlock();
} }
terminated = 1; setTerminated(true);
return true; return true;
} }
// ------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------
......
...@@ -122,7 +122,8 @@ string UniXML::getProp(const xmlNode* node, const string name) ...@@ -122,7 +122,8 @@ string UniXML::getProp(const xmlNode* node, const string name)
const char * text = (const char*)::xmlGetProp((xmlNode*)node, (const xmlChar*)name.c_str()); const char * text = (const char*)::xmlGetProp((xmlNode*)node, (const xmlChar*)name.c_str());
if (text == NULL) if (text == NULL)
return ""; return "";
return text;
return string(text);
} }
int UniXML::getIntProp(const xmlNode* node, const string name ) int UniXML::getIntProp(const xmlNode* node, const string name )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment