timerd: prevent events from being deleted while sending them to neutrino

in neutrino's timer list sometimes appears an entry with random values
after deleting one because thread safety is not guaranteed for timerd's
event list while sending items to neutrino, so let's lock the mutex
earlier and unlock it later

Signed-off-by: Christian Schuett <Gaucho316@hotmail.com>
Signed-off-by: Thilo Graf <dbt@novatux.de>
This commit is contained in:
Christian Schuett
2014-02-14 18:40:22 +01:00
committed by Jacek Jendrzej
parent 7f9dcb64b0
commit a96fb7b7f0
3 changed files with 21 additions and 2 deletions

View File

@@ -277,12 +277,24 @@ bool CTimerManager::stopEvent(int peventID)
}
//------------------------------------------------------------
int CTimerManager::lockEvents()
{
return pthread_mutex_lock(&tm_eventsMutex);
}
//------------------------------------------------------------
int CTimerManager::unlockEvents()
{
return pthread_mutex_unlock(&tm_eventsMutex);
}
//------------------------------------------------------------
bool CTimerManager::listEvents(CTimerEventMap &Events)
{
if(!&Events)
return false;
pthread_mutex_lock(&tm_eventsMutex);
Events.clear();
for (CTimerEventMap::iterator pos = events.begin(); pos != events.end(); ++pos)
@@ -290,7 +302,6 @@ bool CTimerManager::listEvents(CTimerEventMap &Events)
pos->second->Refresh();
Events[pos->second->eventID] = pos->second;
}
pthread_mutex_unlock(&tm_eventsMutex);
return true;
}
//------------------------------------------------------------