This question is a continuation of a previously asked question:
Slow communication using shared memory between user mode and kernel
I am running a thread in the Windows kernel communicating with an application over shared memory. I am wondering if the current way to loop and wait for a change in the BOOLEAN variable is the most efficient? Requirement is to get it down to 50-100 microseconds or lower if possible.
KERNEL CODE
typedef struct _SHARED_MEMORY
{
BOOLEAN mutex;
CHAR data[BUFFER_SIZE];
} SHARED_MEMORY, *PSHARED_MEMORY;
ZwCreateSection(...)
ZwMapViewOfSection(...)
while (TRUE) {
if (((PSHARED_MEMORY)SharedSection)->mutex == TRUE) {
//... do work...
((PSHARED_MEMORY)SharedSection)->mutex = FALSE;
}
KeDelayExecutionThread(KernelMode, FALSE, &PollingInterval);
}
I have considered KeStallExecutionProcessor since its supposed to be used for less than 50 microseconds loops but in my understanding it still hogs the processor's resources.
Also since the BOOLEAN is used in volatile way do you see any short comings or problems with the current read/write procedure? Perhaps changing the thread priority to low?