Skip to content

Commit

Permalink
Try to fix scheduling sync
Browse files Browse the repository at this point in the history
  • Loading branch information
vit9696 committed Sep 30, 2020
1 parent 752fcc2 commit 813eff4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions Sensors/SMCSuperIO/SMCSuperIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,11 @@ bool ADDPR(debugEnabled) = false;
uint32_t ADDPR(debugPrintDelay) = 0;

void SMCSuperIO::timerCallback() {
auto time = getCurrentTimeNs();
auto timerDelta = time - timerEventLastTime;
dataSource->update();
// timerEventSource->setTimeoutMS calls thread_call_enter_delayed_with_leeway, which spins.
// If the previous one was too long ago, schedule another one for differential recalculation!
if (timerDelta > MaxDeltaForRescheduleNs)
timerEventScheduled = timerEventSource->setTimeoutMS(TimerTimeoutMs) == kIOReturnSuccess;
else
timerEventScheduled = false;
timerEventSource->setTimeoutMS(TimerTimeoutMs);
atomic_flag_clear_explicit(&timerEventScheduled, memory_order_release);
}

IOService *SMCSuperIO::probe(IOService *provider, SInt32 *score) {
Expand Down Expand Up @@ -101,9 +97,9 @@ bool SMCSuperIO::start(IOService *provider) {
}

void SMCSuperIO::quickReschedule() {
if (!timerEventScheduled) {
if (!atomic_flag_test_and_set_explicit(&timerEventScheduled, memory_order_acquire)) {
// Make it 10 times faster
timerEventScheduled = timerEventSource->setTimeoutMS(TimerTimeoutMs/10) == kIOReturnSuccess;
timerEventSource->setTimeoutMS(TimerTimeoutMs/10);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sensors/SMCSuperIO/SMCSuperIO.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class EXPORT SMCSuperIO : public IOService {
/**
* Timer scheduling status
*/
bool timerEventScheduled {false};
atomic_flag timerEventScheduled = {};

/**
* Refresh sensor state on timer basis
Expand Down

0 comments on commit 813eff4

Please sign in to comment.