Commit 77c0bc37 authored by Pavel Vainerman's avatar Pavel Vainerman

(Mutex): убрал паузу при блокировке mutex-а..

parent 55985b08
...@@ -73,11 +73,6 @@ SharedMemory::SharedMemory( ObjectId id, string datafile, std::string confname ) ...@@ -73,11 +73,6 @@ SharedMemory::SharedMemory( ObjectId id, string datafile, std::string confname )
string t_field = conf->getArgParam("--t-filter-field"); string t_field = conf->getArgParam("--t-filter-field");
string t_fvalue = conf->getArgParam("--t-filter-value"); string t_fvalue = conf->getArgParam("--t-filter-value");
int lock_msec = conf->getArgPInt("--lock-rvalue-pause-msec",5);
if( lock_msec < 0 )
lock_msec = 0;
setCheckLockValuePause(lock_msec);
heartbeat_node = conf->getArgParam("--heartbeat-node"); heartbeat_node = conf->getArgParam("--heartbeat-node");
if( heartbeat_node.empty() ) if( heartbeat_node.empty() )
dlog[Debug::WARN] << myname << "(init): --heartbeat-node NULL ===> heartbeat NOT USED..." << endl; dlog[Debug::WARN] << myname << "(init): --heartbeat-node NULL ===> heartbeat NOT USED..." << endl;
......
...@@ -368,9 +368,6 @@ class IOController: ...@@ -368,9 +368,6 @@ class IOController:
void updateDepends( IOController::DependsList& lst, bool undefined, bool& lock ); void updateDepends( IOController::DependsList& lst, bool undefined, bool& lock );
void updateBlockDepends( IOController::DependsList& lst, bool blk_state, bool& lock ); void updateBlockDepends( IOController::DependsList& lst, bool blk_state, bool& lock );
void setCheckLockValuePause( int msec );
inline int getCheckLockValuePause(){ return checkLockValuePause; }
private: private:
friend class AskDumper; friend class AskDumper;
...@@ -387,7 +384,6 @@ class IOController: ...@@ -387,7 +384,6 @@ class IOController:
DependsSlot dslot; /*!< undefined depends slot */ DependsSlot dslot; /*!< undefined depends slot */
DependsSlot bslot; /*!< block depends slot */ DependsSlot bslot; /*!< block depends slot */
int checkLockValuePause;
UniSetTypes::uniset_rwmutex loggingMutex; /*!< logging info mutex */ UniSetTypes::uniset_rwmutex loggingMutex; /*!< logging info mutex */
}; };
......
...@@ -100,11 +100,14 @@ namespace UniSetTypes ...@@ -100,11 +100,14 @@ namespace UniSetTypes
uniset_rwmutex(); uniset_rwmutex();
~uniset_rwmutex(); ~uniset_rwmutex();
void lock( int check_pause_msec=1 ); void lock();
void unlock(); void unlock();
void wrlock( int check_pause_msec=1 ); void wrlock();
void rlock( int check_pause_msec=1 ); void rlock();
bool tryrlock();
bool trywrlock();
uniset_rwmutex (const uniset_rwmutex& r); uniset_rwmutex (const uniset_rwmutex& r);
const uniset_rwmutex &operator=(const uniset_rwmutex& r); const uniset_rwmutex &operator=(const uniset_rwmutex& r);
...@@ -123,7 +126,7 @@ namespace UniSetTypes ...@@ -123,7 +126,7 @@ namespace UniSetTypes
class uniset_rwmutex_wrlock class uniset_rwmutex_wrlock
{ {
public: public:
uniset_rwmutex_wrlock( uniset_rwmutex& m, int check_pause_msec=1 ); uniset_rwmutex_wrlock( uniset_rwmutex& m );
~uniset_rwmutex_wrlock(); ~uniset_rwmutex_wrlock();
private: private:
...@@ -135,7 +138,7 @@ namespace UniSetTypes ...@@ -135,7 +138,7 @@ namespace UniSetTypes
class uniset_rwmutex_rlock class uniset_rwmutex_rlock
{ {
public: public:
uniset_rwmutex_rlock( uniset_rwmutex& m, int check_pause_msec=5 ); uniset_rwmutex_rlock( uniset_rwmutex& m );
~uniset_rwmutex_rlock(); ~uniset_rwmutex_rlock();
private: private:
......
...@@ -44,8 +44,7 @@ IOController::IOController(const string name, const string section): ...@@ -44,8 +44,7 @@ IOController::IOController(const string name, const string section):
ObjectsManager(name, section), ObjectsManager(name, section),
dioMutex(name+"_dioMutex"), dioMutex(name+"_dioMutex"),
aioMutex(name+"_aioMutex"), aioMutex(name+"_aioMutex"),
isPingDBServer(true), isPingDBServer(true)
checkLockValuePause(5)
{ {
} }
...@@ -53,8 +52,7 @@ IOController::IOController(ObjectId id): ...@@ -53,8 +52,7 @@ IOController::IOController(ObjectId id):
ObjectsManager(id), ObjectsManager(id),
dioMutex(string(conf->oind->getMapName(id))+"_dioMutex"), dioMutex(string(conf->oind->getMapName(id))+"_dioMutex"),
aioMutex(string(conf->oind->getMapName(id))+"_aioMutex"), aioMutex(string(conf->oind->getMapName(id))+"_aioMutex"),
isPingDBServer(true), isPingDBServer(true)
checkLockValuePause(5)
{ {
} }
...@@ -151,7 +149,7 @@ bool IOController::localGetState( IOController::DIOStateList::iterator& li, ...@@ -151,7 +149,7 @@ bool IOController::localGetState( IOController::DIOStateList::iterator& li,
if( li->second.undefined ) if( li->second.undefined )
throw IOController_i::Undefined(); throw IOController_i::Undefined();
uniset_rwmutex_rlock lock(li->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(li->second.val_lock);
return li->second.state; return li->second.state;
} }
...@@ -176,7 +174,7 @@ long IOController::localGetValue( IOController::AIOStateList::iterator& li, ...@@ -176,7 +174,7 @@ long IOController::localGetValue( IOController::AIOStateList::iterator& li,
if( li->second.undefined ) if( li->second.undefined )
throw IOController_i::Undefined(); throw IOController_i::Undefined();
uniset_rwmutex_rlock lock(li->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(li->second.val_lock);
return li->second.value; return li->second.value;
} }
...@@ -812,7 +810,7 @@ void IOController::dumpToDB() ...@@ -812,7 +810,7 @@ void IOController::dumpToDB()
// uniset_mutex_lock lock(dioMutex, 100); // uniset_mutex_lock lock(dioMutex, 100);
for( DIOStateList::iterator li = dioList.begin(); li!=dioList.end(); ++li ) for( DIOStateList::iterator li = dioList.begin(); li!=dioList.end(); ++li )
{ {
uniset_rwmutex_rlock lock(li->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(li->second.val_lock);
SensorMessage sm; SensorMessage sm;
sm.id = li->second.si.id; sm.id = li->second.si.id;
sm.node = li->second.si.node; sm.node = li->second.si.node;
...@@ -833,7 +831,7 @@ void IOController::dumpToDB() ...@@ -833,7 +831,7 @@ void IOController::dumpToDB()
// uniset_mutex_lock lock(aioMutex, 100); // uniset_mutex_lock lock(aioMutex, 100);
for( AIOStateList::iterator li = aioList.begin(); li!=aioList.end(); ++li ) for( AIOStateList::iterator li = aioList.begin(); li!=aioList.end(); ++li )
{ {
uniset_rwmutex_rlock lock(li->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(li->second.val_lock);
SensorMessage sm; SensorMessage sm;
sm.id = li->second.si.id; sm.id = li->second.si.id;
sm.node = li->second.si.node; sm.node = li->second.si.node;
...@@ -863,7 +861,7 @@ IOController_i::ASensorInfoSeq* IOController::getAnalogSensorsMap() ...@@ -863,7 +861,7 @@ IOController_i::ASensorInfoSeq* IOController::getAnalogSensorsMap()
int i=0; int i=0;
for( AIOStateList::iterator it=aioList.begin(); it!=aioList.end(); ++it) for( AIOStateList::iterator it=aioList.begin(); it!=aioList.end(); ++it)
{ {
uniset_rwmutex_rlock lock(it->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(it->second.val_lock);
(*res)[i] = it->second; (*res)[i] = it->second;
i++; i++;
} }
...@@ -884,7 +882,7 @@ IOController_i::DSensorInfoSeq* IOController::getDigitalSensorsMap() ...@@ -884,7 +882,7 @@ IOController_i::DSensorInfoSeq* IOController::getDigitalSensorsMap()
int i=0; int i=0;
for( DIOStateList::iterator it= dioList.begin(); it!=dioList.end(); ++it) for( DIOStateList::iterator it= dioList.begin(); it!=dioList.end(); ++it)
{ {
uniset_rwmutex_rlock lock(it->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(it->second.val_lock);
(*res)[i].si = it->second.si; (*res)[i].si = it->second.si;
(*res)[i].type = it->second.type; (*res)[i].type = it->second.type;
(*res)[i].state = it->second.state; (*res)[i].state = it->second.state;
...@@ -941,7 +939,7 @@ IOController_i::DigitalIOInfo IOController::getDInfo(const IOController_i::Senso ...@@ -941,7 +939,7 @@ IOController_i::DigitalIOInfo IOController::getDInfo(const IOController_i::Senso
DIOStateList::iterator it = dioList.find( key(si.id, si.node) ); DIOStateList::iterator it = dioList.find( key(si.id, si.node) );
if( it!=dioList.end() ) if( it!=dioList.end() )
{ {
uniset_rwmutex_rlock lock(it->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(it->second.val_lock);
return it->second; return it->second;
} }
...@@ -961,7 +959,7 @@ IOController_i::AnalogIOInfo IOController::getAInfo(const IOController_i::Sensor ...@@ -961,7 +959,7 @@ IOController_i::AnalogIOInfo IOController::getAInfo(const IOController_i::Sensor
AIOStateList::iterator it = aioList.find( key(si.id, si.node) ); AIOStateList::iterator it = aioList.find( key(si.id, si.node) );
if( it!=aioList.end() ) if( it!=aioList.end() )
{ {
uniset_rwmutex_rlock lock(it->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(it->second.val_lock);
return it->second; return it->second;
} }
...@@ -1322,11 +1320,6 @@ void IOController::setBlockDependsSlot( DependsSlot sl ) ...@@ -1322,11 +1320,6 @@ void IOController::setBlockDependsSlot( DependsSlot sl )
bslot = sl; bslot = sl;
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void IOController::setCheckLockValuePause( int msec )
{
checkLockValuePause = msec;
}
// -----------------------------------------------------------------------------
IOController_i::ASensorInfoSeq* IOController::getSensorSeq( const IDSeq& lst ) IOController_i::ASensorInfoSeq* IOController::getSensorSeq( const IDSeq& lst )
{ {
int size = lst.length(); int size = lst.length();
...@@ -1340,7 +1333,7 @@ IOController_i::ASensorInfoSeq* IOController::getSensorSeq( const IDSeq& lst ) ...@@ -1340,7 +1333,7 @@ IOController_i::ASensorInfoSeq* IOController::getSensorSeq( const IDSeq& lst )
DIOStateList::iterator it = dioList.find( UniSetTypes::key(lst[i],conf->getLocalNode()) ); DIOStateList::iterator it = dioList.find( UniSetTypes::key(lst[i],conf->getLocalNode()) );
if( it!=dioList.end() ) if( it!=dioList.end() )
{ {
uniset_rwmutex_rlock lock(it->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(it->second.val_lock);
(*res)[i].si = it->second.si; (*res)[i].si = it->second.si;
(*res)[i].type = it->second.type; (*res)[i].type = it->second.type;
(*res)[i].real_value= it->second.real_state ? 1 : 0; (*res)[i].real_value= it->second.real_state ? 1 : 0;
...@@ -1360,7 +1353,7 @@ IOController_i::ASensorInfoSeq* IOController::getSensorSeq( const IDSeq& lst ) ...@@ -1360,7 +1353,7 @@ IOController_i::ASensorInfoSeq* IOController::getSensorSeq( const IDSeq& lst )
AIOStateList::iterator it = aioList.find( UniSetTypes::key(lst[i],conf->getLocalNode()) ); AIOStateList::iterator it = aioList.find( UniSetTypes::key(lst[i],conf->getLocalNode()) );
if( it!=aioList.end() ) if( it!=aioList.end() )
{ {
uniset_rwmutex_rlock lock(it->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(it->second.val_lock);
(*res)[i] = it->second; (*res)[i] = it->second;
continue; continue;
} }
...@@ -1421,7 +1414,7 @@ IOController_i::ShortIOInfo IOController::getChangedTime( const IOController_i:: ...@@ -1421,7 +1414,7 @@ IOController_i::ShortIOInfo IOController::getChangedTime( const IOController_i::
if( dit!=dioList.end() ) if( dit!=dioList.end() )
{ {
IOController_i::ShortIOInfo i; IOController_i::ShortIOInfo i;
uniset_rwmutex_rlock lock(dit->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(dit->second.val_lock);
i.value = dit->second.state ? 1 : 0; i.value = dit->second.state ? 1 : 0;
i.tv_sec = dit->second.tv_sec; i.tv_sec = dit->second.tv_sec;
i.tv_usec = dit->second.tv_usec; i.tv_usec = dit->second.tv_usec;
...@@ -1432,7 +1425,7 @@ IOController_i::ShortIOInfo IOController::getChangedTime( const IOController_i:: ...@@ -1432,7 +1425,7 @@ IOController_i::ShortIOInfo IOController::getChangedTime( const IOController_i::
if( ait!=aioList.end() ) if( ait!=aioList.end() )
{ {
IOController_i::ShortIOInfo i; IOController_i::ShortIOInfo i;
uniset_rwmutex_rlock lock(ait->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(ait->second.val_lock);
i.value = ait->second.value; i.value = ait->second.value;
i.tv_sec = ait->second.tv_sec; i.tv_sec = ait->second.tv_sec;
i.tv_usec = ait->second.tv_usec; i.tv_usec = ait->second.tv_usec;
...@@ -1459,7 +1452,7 @@ IOController_i::ShortMapSeq* IOController::getSensors() ...@@ -1459,7 +1452,7 @@ IOController_i::ShortMapSeq* IOController::getSensors()
{ {
IOController_i::ShortMap m; IOController_i::ShortMap m;
{ {
uniset_rwmutex_rlock lock(it->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(it->second.val_lock);
m.id = it->second.si.id; m.id = it->second.si.id;
m.value = it->second.value; m.value = it->second.value;
m.type = it->second.type; m.type = it->second.type;
...@@ -1470,7 +1463,7 @@ IOController_i::ShortMapSeq* IOController::getSensors() ...@@ -1470,7 +1463,7 @@ IOController_i::ShortMapSeq* IOController::getSensors()
{ {
IOController_i::ShortMap m; IOController_i::ShortMap m;
{ {
uniset_rwmutex_rlock lock(it->second.val_lock,checkLockValuePause); uniset_rwmutex_rlock lock(it->second.val_lock);
m.id = it->second.si.id; m.id = it->second.si.id;
m.value = it->second.state ? 1 : 0; m.value = it->second.state ? 1 : 0;
m.type = it->second.type; m.type = it->second.type;
......
...@@ -242,7 +242,7 @@ void IONotifyController::askState( const IOController_i::SensorInfo& si, ...@@ -242,7 +242,7 @@ void IONotifyController::askState( const IOController_i::SensorInfo& si,
smsg.priority = (Message::Priority)li->second.priority; smsg.priority = (Message::Priority)li->second.priority;
smsg.supplier = getId(); smsg.supplier = getId();
{ {
uniset_rwmutex_rlock lock(li->second.val_lock,getCheckLockValuePause()); uniset_rwmutex_rlock lock(li->second.val_lock);
smsg.state = li->second.state; smsg.state = li->second.state;
smsg.value = li->second.state ? 1:0; smsg.value = li->second.state ? 1:0;
smsg.undefined = li->second.undefined; smsg.undefined = li->second.undefined;
...@@ -324,7 +324,7 @@ void IONotifyController::askValue(const IOController_i::SensorInfo& si, ...@@ -324,7 +324,7 @@ void IONotifyController::askValue(const IOController_i::SensorInfo& si,
smsg.sm_tv_usec = li->second.tv_usec; smsg.sm_tv_usec = li->second.tv_usec;
smsg.ci = li->second.ci; smsg.ci = li->second.ci;
{ {
uniset_rwmutex_rlock lock(li->second.val_lock,getCheckLockValuePause()); uniset_rwmutex_rlock lock(li->second.val_lock);
smsg.value = li->second.value; smsg.value = li->second.value;
smsg.state = li->second.value ? true:false; smsg.state = li->second.value ? true:false;
smsg.undefined = li->second.undefined; smsg.undefined = li->second.undefined;
...@@ -475,7 +475,7 @@ void IONotifyController::localSaveState( IOController::DIOStateList::iterator& i ...@@ -475,7 +475,7 @@ void IONotifyController::localSaveState( IOController::DIOStateList::iterator& i
// фильтрами или блокировками.. // фильтрами или блокировками..
SensorMessage sm(si.id, state); SensorMessage sm(si.id, state);
{ // lock { // lock
uniset_rwmutex_rlock lock(it->second.val_lock,getCheckLockValuePause()); uniset_rwmutex_rlock lock(it->second.val_lock);
if( prevState == it->second.state ) if( prevState == it->second.state )
return; return;
...@@ -539,7 +539,7 @@ void IONotifyController::localSaveValue( IOController::AIOStateList::iterator& l ...@@ -539,7 +539,7 @@ void IONotifyController::localSaveValue( IOController::AIOStateList::iterator& l
// фильтрами или блокировками.. // фильтрами или блокировками..
SensorMessage sm(si.id,li->second.value); SensorMessage sm(si.id,li->second.value);
{ // lock { // lock
uniset_rwmutex_rlock lock(li->second.val_lock,getCheckLockValuePause()); uniset_rwmutex_rlock lock(li->second.val_lock);
if( prevValue == li->second.value ) if( prevValue == li->second.value )
return; return;
...@@ -975,7 +975,7 @@ void IONotifyController::checkThreshold( AIOStateList::iterator& li, ...@@ -975,7 +975,7 @@ void IONotifyController::checkThreshold( AIOStateList::iterator& li,
sm.priority = (Message::Priority)li->second.priority; sm.priority = (Message::Priority)li->second.priority;
sm.ci = li->second.ci; sm.ci = li->second.ci;
{ {
uniset_rwmutex_rlock lock(li->second.val_lock,getCheckLockValuePause()); uniset_rwmutex_rlock lock(li->second.val_lock);
sm.value = li->second.value; sm.value = li->second.value;
sm.state = li->second.value!=0 ? true:false; sm.state = li->second.value!=0 ? true:false;
sm.undefined = li->second.undefined; sm.undefined = li->second.undefined;
...@@ -1191,7 +1191,7 @@ void IONotifyController::localSetState( IOController::DIOStateList::iterator& it ...@@ -1191,7 +1191,7 @@ void IONotifyController::localSetState( IOController::DIOStateList::iterator& it
// Рассылаем уведомления только если значение изменилось... // Рассылаем уведомления только если значение изменилось...
SensorMessage sm(si.id, state); SensorMessage sm(si.id, state);
{ // lock { // lock
uniset_rwmutex_rlock lock(it->second.val_lock,getCheckLockValuePause()); uniset_rwmutex_rlock lock(it->second.val_lock);
if( prevState == it->second.state ) if( prevState == it->second.state )
return; return;
sm.id = si.id; sm.id = si.id;
...@@ -1247,7 +1247,7 @@ void IONotifyController::localSetValue( IOController::AIOStateList::iterator& li ...@@ -1247,7 +1247,7 @@ void IONotifyController::localSetValue( IOController::AIOStateList::iterator& li
// Рассылаем уведомления только если значение изменилось... // Рассылаем уведомления только если значение изменилось...
SensorMessage sm; SensorMessage sm;
{ // lock { // lock
uniset_rwmutex_rlock lock(li->second.val_lock,getCheckLockValuePause()); uniset_rwmutex_rlock lock(li->second.val_lock);
if( prevValue == li->second.value ) if( prevValue == li->second.value )
return; return;
......
...@@ -33,6 +33,7 @@ using namespace UniSetTypes; ...@@ -33,6 +33,7 @@ using namespace UniSetTypes;
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
LT_Object::LT_Object(): LT_Object::LT_Object():
lstMutex("LT_Object::lstMutex"),
sleepTime(UniSetTimer::WaitUpTime) sleepTime(UniSetTimer::WaitUpTime)
{ {
tmLast.setTiming(UniSetTimer::WaitUpTime); tmLast.setTiming(UniSetTimer::WaitUpTime);
...@@ -48,7 +49,7 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj ) ...@@ -48,7 +49,7 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj )
try try
{ {
{ // lock { // lock
uniset_mutex_lock lock(lstMutex, 5000); uniset_rwmutex_rlock lock(lstMutex);
if( tlst.empty() ) if( tlst.empty() )
{ {
...@@ -70,7 +71,7 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj ) ...@@ -70,7 +71,7 @@ timeout_t LT_Object::checkTimers( UniSetObject* obj )
} }
{ // lock { // lock
uniset_mutex_lock lock(lstMutex, 5000); uniset_rwmutex_wrlock lock(lstMutex);
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)
{ {
...@@ -130,10 +131,7 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c ...@@ -130,10 +131,7 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c
} }
{ // lock { // lock
if( unideb.debugging(Debug::INFO) && !lstMutex.isRelease() ) uniset_rwmutex_wrlock lock(lstMutex);
unideb[Debug::INFO] << "(LT_askTimer): придется подождать освобождения lstMutex-а" << endl;
uniset_mutex_lock lock(lstMutex, 2000);
// поищем а может уж такой есть // поищем а может уж такой есть
if( !tlst.empty() ) if( !tlst.empty() )
{ {
...@@ -166,20 +164,13 @@ timeout_t LT_Object::askTimer( UniSetTypes::TimerId timerid, timeout_t timeMS, c ...@@ -166,20 +164,13 @@ 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( unideb.debugging(Debug::INFO) && !lstMutex.isRelease() ) uniset_rwmutex_wrlock lock(lstMutex);
unideb[Debug::INFO] << "(LT_askTimer): придется подождать освобождения lstMutex-а\n";
uniset_mutex_lock lock(lstMutex, 2000);
tlst.remove_if(Timer_eq(timerid)); // STL - способ tlst.remove_if(Timer_eq(timerid)); // STL - способ
} // unlock } // unlock
} }
{ // lock { // lock
if( unideb.debugging(Debug::INFO) && !lstMutex.isRelease() ) uniset_rwmutex_rlock lock(lstMutex);
unideb[Debug::INFO] << "(LT_askTimer): придется подождать освобождения lstMutex-а\n";
uniset_mutex_lock lock(lstMutex, 2000);
if( tlst.empty() ) if( tlst.empty() )
sleepTime = UniSetTimer::WaitUpTime; sleepTime = UniSetTimer::WaitUpTime;
......
...@@ -183,39 +183,26 @@ uniset_rwmutex::uniset_rwmutex( const uniset_rwmutex& r ) ...@@ -183,39 +183,26 @@ uniset_rwmutex::uniset_rwmutex( const uniset_rwmutex& r )
//unlock(); //unlock();
} }
void uniset_rwmutex::lock( int check_pause_msec ) void uniset_rwmutex::lock()
{ {
wr_wait += 1; wr_wait += 1;
while( !m.tryWriteLock() ) m.writeLock();
{
if( check_pause_msec > 0 )
msleep(check_pause_msec);
}
wr_wait -= 1; wr_wait -= 1;
MUTEX_DEBUG(cerr << nm << " Locked.." << endl;) MUTEX_DEBUG(cerr << nm << " Locked.." << endl;)
} }
void uniset_rwmutex::wrlock( int check_pause_msec ) void uniset_rwmutex::wrlock()
{ {
wr_wait += 1; wr_wait += 1;
while( !m.tryWriteLock() ) m.writeLock();
{
if( check_pause_msec > 0 )
msleep(check_pause_msec);
}
wr_wait -= 1; wr_wait -= 1;
MUTEX_DEBUG(cerr << nm << " WRLocked.." << endl;) MUTEX_DEBUG(cerr << nm << " WRLocked.." << endl;)
} }
void uniset_rwmutex::rlock( int check_pause_msec ) void uniset_rwmutex::rlock()
{ {
while( wr_wait > 0 ) while( wr_wait > 0 )
msleep(check_pause_msec); msleep(2);
while( !m.tryReadLock() )
{
if( check_pause_msec > 0 )
msleep(check_pause_msec);
}
m.readLock();
MUTEX_DEBUG(cerr << nm << " RLocked.." << endl;) MUTEX_DEBUG(cerr << nm << " RLocked.." << endl;)
} }
...@@ -224,11 +211,21 @@ void uniset_rwmutex::unlock() ...@@ -224,11 +211,21 @@ void uniset_rwmutex::unlock()
m.unlock(); m.unlock();
MUTEX_DEBUG(cerr << nm << " Unlocked.." << endl;) MUTEX_DEBUG(cerr << nm << " Unlocked.." << endl;)
} }
bool uniset_rwmutex::tryrlock()
{
return m.tryReadLock();
}
bool uniset_rwmutex::trywrlock()
{
return m.tryWriteLock();
}
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
uniset_rwmutex_wrlock::uniset_rwmutex_wrlock( uniset_rwmutex& _m, int check_pause_msec ): uniset_rwmutex_wrlock::uniset_rwmutex_wrlock( uniset_rwmutex& _m ):
m(_m) m(_m)
{ {
m.wrlock(check_pause_msec); m.wrlock();
} }
uniset_rwmutex_wrlock::~uniset_rwmutex_wrlock() uniset_rwmutex_wrlock::~uniset_rwmutex_wrlock()
...@@ -250,10 +247,10 @@ uniset_rwmutex_wrlock& uniset_rwmutex_wrlock::operator=(const uniset_rwmutex_wrl ...@@ -250,10 +247,10 @@ uniset_rwmutex_wrlock& uniset_rwmutex_wrlock::operator=(const uniset_rwmutex_wrl
return *this; return *this;
} }
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------
uniset_rwmutex_rlock::uniset_rwmutex_rlock( uniset_rwmutex& _m, int check_pause_msec ): uniset_rwmutex_rlock::uniset_rwmutex_rlock( uniset_rwmutex& _m ):
m(_m) m(_m)
{ {
m.rlock(check_pause_msec); m.rlock();
} }
uniset_rwmutex_rlock::~uniset_rwmutex_rlock() uniset_rwmutex_rlock::~uniset_rwmutex_rlock()
......
...@@ -89,7 +89,7 @@ class MyClassSpin ...@@ -89,7 +89,7 @@ class MyClassSpin
if( !readLock ) if( !readLock )
{ {
// cerr << nm << ": before RWlock.." << endl; // cerr << nm << ": before RWlock.." << endl;
uniset_rwmutex_wrlock l(m_spin,5); uniset_rwmutex_wrlock l(m_spin);
count++; count++;
msleep(30); msleep(30);
// cerr << nm << ": after RWlock.." << endl; // cerr << nm << ": after RWlock.." << endl;
...@@ -246,7 +246,7 @@ int main( int argc, const char **argv ) ...@@ -246,7 +246,7 @@ int main( int argc, const char **argv )
} }
#endif #endif
#if 0 #if 1
typedef std::vector<MyClassSpin*> TSpinVec; typedef std::vector<MyClassSpin*> TSpinVec;
TSpinVec tsvec(max); TSpinVec tsvec(max);
for( int i=0; i<max; i++ ) for( int i=0; i<max; i++ )
......
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