Commit 99dc6b5d authored by Pavel Vainerman's avatar Pavel Vainerman

(Local timers): Оптимизировал код. Убрал не нужную сортировку

(всё-равно по всему списку таймеров проходим)
parent cb5350a6
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Name: libuniset Name: libuniset
Version: 1.0 Version: 1.0
Release: alt4 Release: alt5
Summary: UniSet - library for building distributed industrial control systems Summary: UniSet - library for building distributed industrial control systems
License: GPL License: GPL
Group: Development/C++ Group: Development/C++
...@@ -187,6 +187,12 @@ rm -f %buildroot%_libdir/*.la ...@@ -187,6 +187,12 @@ rm -f %buildroot%_libdir/*.la
%exclude %_pkgconfigdir/libUniSet.pc %exclude %_pkgconfigdir/libUniSet.pc
%changelog %changelog
* Thu Feb 24 2011 Pavel Vainerman <pv@server> 1.0-alt5
- new build (optimization local timers)
* Thu Feb 24 2011 Pavel Vainerman <pv@server> 1.0-alt4
- new build
* Mon Feb 14 2011 Pavel Vainerman <pv@server> 1.0-alt3 * Mon Feb 14 2011 Pavel Vainerman <pv@server> 1.0-alt3
- fixed bug in ModbusTCPMaster - fixed bug in ModbusTCPMaster
......
...@@ -27,22 +27,22 @@ ...@@ -27,22 +27,22 @@
#include "LT_Object.h" #include "LT_Object.h"
#include "Debug.h" #include "Debug.h"
// ------------------------------------------------------------------------------------------ // -----------------------------------------------------------------------------
using namespace std; using namespace std;
using namespace UniSetTypes; using namespace UniSetTypes;
// ------------------------------------------------------------------------------------------ // -----------------------------------------------------------------------------
LT_Object::LT_Object(): LT_Object::LT_Object():
sleepTime(UniSetTimer::WaitUpTime) sleepTime(UniSetTimer::WaitUpTime)
{ {
tmLast.setTiming(UniSetTimer::WaitUpTime); tmLast.setTiming(UniSetTimer::WaitUpTime);
} }
// ------------------------------------------------------------------------------------------ // -----------------------------------------------------------------------------
LT_Object::~LT_Object() LT_Object::~LT_Object()
{ {
} }
// ------------------------------------------------------------------------------------------ // -----------------------------------------------------------------------------
timeout_t LT_Object::checkTimers( UniSetObject* obj ) timeout_t LT_Object::checkTimers( UniSetObject* obj )
{ {
try try
...@@ -71,7 +71,6 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj ) ...@@ -71,7 +71,6 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj )
{ // lock { // lock
uniset_mutex_lock lock(lstMutex, 5000); uniset_mutex_lock lock(lstMutex, 5000);
bool resort(false);
sleepTime = UniSetTimer::WaitUpTime; sleepTime = UniSetTimer::WaitUpTime;
for( TimersList::iterator li=tlst.begin();li!=tlst.end();++li) for( TimersList::iterator li=tlst.begin();li!=tlst.end();++li)
{ {
...@@ -93,7 +92,6 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj ) ...@@ -93,7 +92,6 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj )
li->curTick--; li->curTick--;
li->reset(); li->reset();
resort = true;
} }
else else
{ {
...@@ -105,9 +103,6 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj ) ...@@ -105,9 +103,6 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj )
sleepTime = li->curTimeMS; sleepTime = li->curTimeMS;
} }
if( resort ) // пересортировываем в связи с обновлением списка
tlst.sort();
if( sleepTime < UniSetTimer::MinQuantityTime ) if( sleepTime < UniSetTimer::MinQuantityTime )
sleepTime=UniSetTimer::MinQuantityTime; sleepTime=UniSetTimer::MinQuantityTime;
} // unlock } // unlock
...@@ -135,7 +130,7 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c ...@@ -135,7 +130,7 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c
} }
{ // lock { // lock
if( !lstMutex.isRelease() && unideb.debugging(Debug::INFO) ) if( unideb.debugging(Debug::INFO) && !lstMutex.isRelease() )
unideb[Debug::INFO] << "(LT_askTimer): придется подождать освобождения lstMutex-а" << endl; unideb[Debug::INFO] << "(LT_askTimer): придется подождать освобождения lstMutex-а" << endl;
uniset_mutex_lock lock(lstMutex, 2000); uniset_mutex_lock lock(lstMutex, 2000);
...@@ -148,8 +143,11 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c ...@@ -148,8 +143,11 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c
{ {
li->curTick = ticks; li->curTick = ticks;
li->tmr.setTiming(timeMS); li->tmr.setTiming(timeMS);
unideb[Debug::INFO] << "(LT_askTimer): заказ на таймер(id=" if( unideb.debugging(Debug::INFO) )
<< timerid << ") " << timeMS << " [мс] уже есть...\n"; {
unideb[Debug::INFO] << "(LT_askTimer): заказ на таймер(id="
<< timerid << ") " << timeMS << " [мс] уже есть..." << endl;
}
return sleepTime; return sleepTime;
} }
} }
...@@ -157,7 +155,6 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c ...@@ -157,7 +155,6 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c
TimerInfo newti(timerid, timeMS, ticks, p); TimerInfo newti(timerid, timeMS, ticks, p);
tlst.push_back(newti); tlst.push_back(newti);
tlst.sort();
newti.reset(); newti.reset();
} // unlock } // unlock
...@@ -169,17 +166,17 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c ...@@ -169,17 +166,17 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c
if( unideb.debugging(Debug::INFO) ) if( unideb.debugging(Debug::INFO) )
unideb[Debug::INFO] << "(LT_askTimer): поступил отказ по таймеру id="<< timerid << endl; unideb[Debug::INFO] << "(LT_askTimer): поступил отказ по таймеру id="<< timerid << endl;
{ // lock { // lock
if( !lstMutex.isRelease() && unideb.debugging(Debug::INFO) ) if( unideb.debugging(Debug::INFO) && !lstMutex.isRelease() )
unideb[Debug::INFO] << "(LT_askTimer): придется подождать освобождения lstMutex-а\n"; unideb[Debug::INFO] << "(LT_askTimer): придется подождать освобождения lstMutex-а\n";
uniset_mutex_lock lock(lstMutex, 2000); uniset_mutex_lock lock(lstMutex, 2000);
tlst.remove_if(Timer_eq(timerid)); // STL - способ tlst.remove_if(Timer_eq(timerid)); // STL - способ
tlst.sort();
} // unlock } // unlock
} }
{ // lock { // lock
if( !lstMutex.isRelease() && unideb.debugging(Debug::INFO) ) if( unideb.debugging(Debug::INFO) && !lstMutex.isRelease() )
unideb[Debug::INFO] << "(LT_askTimer): придется подождать освобождения lstMutex-а\n"; unideb[Debug::INFO] << "(LT_askTimer): придется подождать освобождения lstMutex-а\n";
uniset_mutex_lock lock(lstMutex, 2000); uniset_mutex_lock lock(lstMutex, 2000);
...@@ -192,4 +189,4 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c ...@@ -192,4 +189,4 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c
return sleepTime; return sleepTime;
} }
// ------------------------------------------------------------------------------------------ // -----------------------------------------------------------------------------
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