forked from RehabMan/OS-X-Generic-USB3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenericUSBXHCIEventSource.cpp
81 lines (72 loc) · 1.93 KB
/
GenericUSBXHCIEventSource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//
// GenericUSBXHCIEventSource.cpp
// GenericUSBXHCI
//
// Created by Zenith432 on October 27th 2013.
// Copyright (c) 2013 Zenith432. All rights reserved.
//
//
#include "GenericUSBXHCI.h"
class GenericUSBXHCIEventSource : public IOEventSource
{
OSDeclareFinalStructors(GenericUSBXHCIEventSource);
protected:
bool checkForWork();
public:
__attribute__((always_inline)) bool init(OSObject* owner) { return IOEventSource::init(owner, 0); }
};
OSDefineMetaClassAndFinalStructors(GenericUSBXHCIEventSource, IOEventSource);
bool GenericUSBXHCIEventSource::checkForWork()
{
GenericUSBXHCI* _owner = OSDynamicCast(GenericUSBXHCI, owner);
if (_owner && !_owner->isInactive())
_owner->_completer.Flush();
return false;
}
__attribute__((visibility("hidden")))
IOReturn GenericUSBXHCI::InitializeEventSource(void)
{
GenericUSBXHCIEventSource* es = OSTypeAlloc(GenericUSBXHCIEventSource);
if (!es)
return kIOReturnNoMemory;
if (!es->GenericUSBXHCIEventSource::init(this)) {
es->release();
return kIOReturnNoMemory;
}
if (_workLoop) {
IOReturn rc = _workLoop->addEventSource(es);
if (rc != kIOReturnSuccess) {
es->release();
return rc;
}
}
_eventSource = es;
return kIOReturnSuccess;
}
__attribute__((visibility("hidden")))
void GenericUSBXHCI::FinalizeEventSource(void)
{
if (!_eventSource)
return;
if (_workLoop)
_workLoop->removeEventSource(_eventSource);
_eventSource->release();
_eventSource = 0;
}
__attribute__((visibility("hidden")))
void GenericUSBXHCI::ScheduleEventSource(void)
{
if (!_eventSource)
return;
#if 1
/*
* Note: This optimization depends on implementation of IOWorkLoop.
* If we're executing inside InterruptHandler(), since _eventSource
* is added to WL after _filterInterruptSource,
* _eventSource->checkForWork() will execute even w/o reschedule.
*/
if (_workLoop && _workLoop->onThread())
return;
#endif
_eventSource->enable(); // Note: twisted way of calling signalWorkAvailable()
}