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

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

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