此处是用 Critical Section lock 来保护 data.handling
EnterCriticalSection(&lock); if (data.handling) { tick64_t start = get_tick64(); do { SleepConditionVariableCS(&lock_wake, &lock, 10*1000); if (!data.handling) break; if (get_tick64() - start > TIMEOUT) { LeaveCriticalSection(&lock); return -EBUSY; } }while(1); } data.handling = 1; LeaveCriticalSection(&ioctl_lock);
...
if (/* Some condition */) {
EnterCriticalSection(&lock);
data.handling = 0;
SleepConditionVariableCS(&lock_wake);
LeaveCriticalSection(&lock);
}