+
+void CAdapterEepromWriteThread::Stop(void)
+{
+ StopThread(-1);
+ {
+ CLockObject lock(m_mutex);
+ if (m_iScheduleEepromWrite > 0)
+ m_com->LIB_CEC->AddLog(CEC_LOG_WARNING, "write thread stopped while a write was queued");
+ m_bWrite = true;
+ m_condition.Signal();
+ }
+ StopThread();
+}
+
+void *CAdapterEepromWriteThread::Process(void)
+{
+ while (!IsStopped())
+ {
+ CLockObject lock(m_mutex);
+ if ((m_iScheduleEepromWrite > 0 && m_iScheduleEepromWrite < GetTimeMs()) ||
+ m_condition.Wait(m_mutex, m_bWrite, 100))
+ {
+ if (IsStopped())
+ break;
+ m_bWrite = false;
+ if (m_com->m_commands->WriteEEPROM())
+ {
+ m_iLastEepromWrite = GetTimeMs();
+ m_iScheduleEepromWrite = 0;
+ }
+ else
+ {
+ m_iScheduleEepromWrite = GetTimeMs() + CEC_ADAPTER_EEPROM_WRITE_RETRY;
+ }
+ }
+ }
+ return NULL;
+}
+
+bool CAdapterEepromWriteThread::Write(void)
+{
+ CLockObject lock(m_mutex);
+ if (m_iScheduleEepromWrite == 0)
+ {
+ int64_t iNow = GetTimeMs();
+ if (m_iLastEepromWrite + CEC_ADAPTER_EEPROM_WRITE_INTERVAL > iNow)
+ {
+ m_com->LIB_CEC->AddLog(CEC_LOG_DEBUG, "delaying eeprom write by %ld ms", m_iLastEepromWrite + CEC_ADAPTER_EEPROM_WRITE_INTERVAL - iNow);
+ m_iScheduleEepromWrite = m_iLastEepromWrite + CEC_ADAPTER_EEPROM_WRITE_INTERVAL;
+ }
+ else
+ {
+ m_bWrite = true;
+ m_condition.Signal();
+ }
+ }
+ return true;
+}