From bc2b9fae4d09c7e5a58eb83e555ddda516034ba8 Mon Sep 17 00:00:00 2001 From: Kishor Prins Date: Thu, 19 Oct 2017 20:47:32 -0400 Subject: [PATCH] Add boolean checks to prevent unfairness --- .gitignore | 2 ++ VoodooI2CELAN/VoodooI2CELANTouchpadDriver.cpp | 25 +++++++++++++++---- VoodooI2CELAN/VoodooI2CELANTouchpadDriver.hpp | 1 + 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 37de8bb..29a948a 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ xcuserdata/ *.moved-aside *.xccheckout *.xcscmblueprint + +*.DS_Store diff --git a/VoodooI2CELAN/VoodooI2CELANTouchpadDriver.cpp b/VoodooI2CELAN/VoodooI2CELANTouchpadDriver.cpp index e773442..b774237 100644 --- a/VoodooI2CELAN/VoodooI2CELANTouchpadDriver.cpp +++ b/VoodooI2CELAN/VoodooI2CELANTouchpadDriver.cpp @@ -41,6 +41,7 @@ bool VoodooI2CELANTouchpadDriver::init(OSDictionary *properties) { awake = true; readyForInput = false; + readInProgress = false; return true; } @@ -321,13 +322,18 @@ bool VoodooI2CELANTouchpadDriver::initELANDevice() { } void VoodooI2CELANTouchpadDriver::interruptOccurred(OSObject* owner, IOInterruptEventSource* src, int intCount) { - // IOLog("ELAN: Interrupt occurred!\n"); + if(readInProgress) + return; + if (!awake) return; + readInProgress = true; + thread_t new_thread; kern_return_t ret = kernel_thread_start(OSMemberFunctionCast(thread_continue_t, this, &VoodooI2CELANTouchpadDriver::handleELANInput), this, &new_thread); if (ret != KERN_SUCCESS){ + readInProgress = false; IOLog("ELAN: Thread error while attempint to get input report\n"); } else { thread_deallocate(new_thread); @@ -514,6 +520,7 @@ void VoodooI2CELANTouchpadDriver::handleELANInput() { } commandGate->attemptAction(OSMemberFunctionCast(IOCommandGate::Action, this, &VoodooI2CELANTouchpadDriver::parseELANReport)); + readInProgress = false; } void VoodooI2CELANTouchpadDriver::setELANSleepStatus(bool enable) { @@ -598,12 +605,20 @@ void VoodooI2CELANTouchpadDriver::stop(IOService* provider) { } IOReturn VoodooI2CELANTouchpadDriver::setPowerState(unsigned long longpowerStateOrdinal, IOService* whatDevice) { - /*if (whatDevice != this) + if (whatDevice != this) return kIOReturnInvalid; if (longpowerStateOrdinal == 0){ if (awake){ awake = false; + for(;;) { + if(!readInProgress) { + break; + } + + IOSleep(10); + } + // Off setELANSleepStatus(false); @@ -617,8 +632,8 @@ IOReturn VoodooI2CELANTouchpadDriver::setPowerState(unsigned long longpowerState awake = true; IOLog("ELAN: Woke up\n"); } - } */ - IOLog("ELAN: set power state called\n"); - return super::setPowerState(longpowerStateOrdinal, whatDevice); + } + + return kIOPMAckImplied; } diff --git a/VoodooI2CELAN/VoodooI2CELANTouchpadDriver.hpp b/VoodooI2CELAN/VoodooI2CELANTouchpadDriver.hpp index a00c40c..013a2aa 100644 --- a/VoodooI2CELAN/VoodooI2CELANTouchpadDriver.hpp +++ b/VoodooI2CELAN/VoodooI2CELANTouchpadDriver.hpp @@ -25,6 +25,7 @@ class VoodooI2CELANTouchpadDriver : public IOService { bool awake; bool readyForInput; + bool readInProgress; // Hardware dimensions int maxHWResolutionX;