auto-sync

This commit is contained in:
rusEfi 2014-09-14 15:04:20 -05:00
parent 44cc21bcfd
commit 0326f641c0
2 changed files with 11 additions and 7 deletions

View File

@ -28,7 +28,7 @@ static Executor instance;
extern schfunc_t globalTimerCallback; extern schfunc_t globalTimerCallback;
static void executorCallback(void *arg) { static void executorCallback(void *arg) {
instance.onTimerCallback(getTimeNowUs()); instance.onTimerCallback();
} }
Executor::Executor() { Executor::Executor() {
@ -58,7 +58,7 @@ void Executor::schedule2(const char *prefix, scheduling_s *scheduling, uint64_t
} }
queue.insertTask(scheduling, timeUs, callback, param); queue.insertTask(scheduling, timeUs, callback, param);
if (!reentrantLock) { if (!reentrantLock) {
doExecute(getTimeNowUs()); doExecute();
unlock(); unlock();
} }
} }
@ -68,16 +68,16 @@ void Executor::schedule(const char *prefix, scheduling_s *scheduling, uint64_t n
schedule2(prefix, scheduling, nowUs + delayUs, callback, param); schedule2(prefix, scheduling, nowUs + delayUs, callback, param);
} }
void Executor::onTimerCallback(uint64_t nowUs) { void Executor::onTimerCallback() {
lock(); lock();
doExecute(nowUs); doExecute();
unlock(); unlock();
} }
/* /*
* this private method is executed under lock * this private method is executed under lock
*/ */
void Executor::doExecute(uint64_t nowUs) { void Executor::doExecute() {
/** /**
* Let's execute actions we should execute at this point. * Let's execute actions we should execute at this point.
* reentrantLock takes care of the use case where the actions we are executing are scheduling * reentrantLock takes care of the use case where the actions we are executing are scheduling
@ -87,12 +87,16 @@ void Executor::doExecute(uint64_t nowUs) {
/** /**
* It's worth noting that that the actions might be adding new actions into the queue * It's worth noting that that the actions might be adding new actions into the queue
*/ */
uint64_t nowUs = getTimeNowUs();
queue.executeAll(nowUs); queue.executeAll(nowUs);
if (!isLocked()) { if (!isLocked()) {
firmwareError("Someone has stolen my lock"); firmwareError("Someone has stolen my lock");
return; return;
} }
reentrantLock = false; reentrantLock = false;
/**
* 'executeAll' is potentially invoking heavy callbacks, let's grab fresh time value?
*/
/** /**
* Let's set up the timer for the next execution * Let's set up the timer for the next execution
*/ */

View File

@ -16,11 +16,11 @@ public:
Executor(); Executor();
void schedule(const char *prefix, scheduling_s *scheduling, uint64_t nowUs, int delayUs, schfunc_t callback, void *param); void schedule(const char *prefix, scheduling_s *scheduling, uint64_t nowUs, int delayUs, schfunc_t callback, void *param);
void schedule2(const char *prefix, scheduling_s *scheduling, uint64_t timeUs, schfunc_t callback, void *param); void schedule2(const char *prefix, scheduling_s *scheduling, uint64_t timeUs, schfunc_t callback, void *param);
void onTimerCallback(uint64_t nowUs); void onTimerCallback();
private: private:
EventQueue queue; EventQueue queue;
bool reentrantLock; bool reentrantLock;
void doExecute(uint64_t nowUs); void doExecute();
void lock(void); void lock(void);
void unlock(void); void unlock(void);
}; };