rcinput: use mutex, suggested by Seife

This commit is contained in:
Jacek Jendrzej
2019-10-14 15:45:01 +02:00
parent 980dee5622
commit 2a161a1246
2 changed files with 10 additions and 3 deletions

View File

@@ -471,15 +471,18 @@ int CRCInput::addTimer(uint64_t Interval, bool oneshot, bool correct_time )
_newtimer.times_out = Interval; _newtimer.times_out = Interval;
_newtimer.correct_time = correct_time; _newtimer.correct_time = correct_time;
//printf("adding timer %d (0x%" PRIx64 ", 0x%" PRIx64 ")\n", _newtimer.id, _newtimer.times_out, Interval); //printf("adding timer %d (0x%" PRIx64 ", 0x%" PRIx64 ")\n", _newtimer.id, _newtimer.times_out, Interval);
timer_mutex.lock();
std::vector<timer>::iterator e; std::vector<timer>::iterator e;
for ( e= timers.begin(); e!= timers.end(); ++e ) for ( e= timers.begin(); e!= timers.end(); ++e )
if ( e->times_out> _newtimer.times_out ) if ( e->times_out> _newtimer.times_out )
break; break;
timers.insert(e, _newtimer); timers.insert(e, _newtimer);
timer_mutex.unlock();
return _newtimer.id; return _newtimer.id;
} }
@@ -489,6 +492,7 @@ void CRCInput::killTimer(uint32_t &id)
if(id == 0) if(id == 0)
return; return;
timer_mutex.lock();
std::vector<timer>::iterator e; std::vector<timer>::iterator e;
for ( e= timers.begin(); e!= timers.end(); ++e ) for ( e= timers.begin(); e!= timers.end(); ++e )
if ( e->id == id ) if ( e->id == id )
@@ -497,12 +501,14 @@ void CRCInput::killTimer(uint32_t &id)
break; break;
} }
id = 0; id = 0;
timer_mutex.unlock();
} }
int CRCInput::checkTimers() int CRCInput::checkTimers()
{ {
int _id = 0; int _id = 0;
uint64_t timeNow = time_monotonic_us(); uint64_t timeNow = time_monotonic_us();
timer_mutex.lock();
std::vector<timer>::iterator e; std::vector<timer>::iterator e;
for ( e= timers.begin(); e!= timers.end(); ++e ) for ( e= timers.begin(); e!= timers.end(); ++e )
if ( e->times_out< timeNow+ 2000 ) if ( e->times_out< timeNow+ 2000 )
@@ -525,8 +531,7 @@ int CRCInput::checkTimers()
if ( e->times_out> _newtimer.times_out ) if ( e->times_out> _newtimer.times_out )
break; break;
if(e != timers.end()) timers.insert(e, _newtimer);
timers.insert(e, _newtimer);
} }
else else
timers.erase(e); timers.erase(e);
@@ -536,6 +541,7 @@ int CRCInput::checkTimers()
// else // else
// printf("skipped timer %d %llx %llx\n",e->id,e->times_out, timeNow ); // printf("skipped timer %d %llx %llx\n",e->id,e->times_out, timeNow );
//printf("checkTimers: return %d\n", _id); //printf("checkTimers: return %d\n", _id);
timer_mutex.unlock();
return _id; return _id;
} }

View File

@@ -158,6 +158,7 @@ class CRCInput
int fd_max; int fd_max;
__u16 rc_last_key; __u16 rc_last_key;
OpenThreads::Mutex mutex; OpenThreads::Mutex mutex;
OpenThreads::Mutex timer_mutex;
void open(bool recheck = false); void open(bool recheck = false);
bool checkpath(in_dev id); bool checkpath(in_dev id);