2014-08-29 07:52:33 -07:00
|
|
|
/**
|
|
|
|
* @file event_queue.h
|
|
|
|
*
|
|
|
|
* @date Apr 17, 2014
|
2015-01-12 15:04:10 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2015
|
2014-08-29 07:52:33 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "scheduler.h"
|
|
|
|
#include "utlist.h"
|
|
|
|
|
|
|
|
#ifndef EVENT_SCHEDULER_H_
|
|
|
|
#define EVENT_SCHEDULER_H_
|
|
|
|
|
|
|
|
#define EMPTY_QUEUE 0x0FFFFFFFFFFFFFFFLL
|
|
|
|
|
|
|
|
#define QUEUE_LENGTH_LIMIT 1000
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
bool assertNotInList(T *head, T*element) {
|
|
|
|
// this code is just to validate state, no functional load
|
|
|
|
T * current;
|
|
|
|
int counter = 0;
|
|
|
|
LL_FOREACH(head, current)
|
|
|
|
{
|
|
|
|
if (++counter > QUEUE_LENGTH_LIMIT) {
|
|
|
|
firmwareError("Looped queue?");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
if (current == element) {
|
2014-11-14 16:03:12 -08:00
|
|
|
/**
|
|
|
|
* for example, this might happen in case of sudden RPM change if event
|
|
|
|
* was not scheduled by angle but was scheduled by time. In case of scheduling
|
|
|
|
* by time with slow RPM the whole next fast revolution might be within the wait period
|
|
|
|
*/
|
2014-08-29 07:52:33 -07:00
|
|
|
warning(OBD_PCM_Processor_Fault, "re-adding element into event_queue: [%s]", element->name);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
class EventQueue {
|
|
|
|
public:
|
|
|
|
EventQueue();
|
|
|
|
|
2014-11-07 22:05:46 -08:00
|
|
|
void insertTask(scheduling_s *scheduling, uint64_t timeX, schfunc_t callback, void *param);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
2014-09-14 14:03:05 -07:00
|
|
|
bool executeAll(uint64_t now);
|
2014-08-29 07:52:33 -07:00
|
|
|
|
|
|
|
uint64_t getNextEventTime(uint64_t nowUs);
|
|
|
|
void clear(void);
|
|
|
|
int size(void);
|
|
|
|
scheduling_s *getForUnitText(int index);
|
2014-11-07 22:05:46 -08:00
|
|
|
void setLateDelay(int value);
|
2014-08-29 07:52:33 -07:00
|
|
|
private:
|
|
|
|
bool checkIfPending(scheduling_s *scheduling);
|
|
|
|
scheduling_s *head;
|
2014-11-07 22:05:46 -08:00
|
|
|
uint64_t lateDelay;
|
2014-08-29 07:52:33 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* EVENT_SCHEDULER_H_ */
|