Condition variable implementation in WDM driver

Hi,
I am relatively new to WDM driver development. I am implementing a work queue. The producer threads insert the work item into the queue and in some cases they have to wait till the work queue becomes empty. I could not find any CV kernel objects in WDM. Is CV to be custom implemented or any sample code/alternative available?

Why are you writing a driver in WDM in 2022? Don’t you want to use WDF??

Peter

I am doing small enhancement in a legacy driver.

Your primary choices are KMUTEX (KeInitializeMutex), KSEMAPHORE (KeInitializeSemaphore), and KEVENT (KeInitializeEvent). I’ve rarely encountered a driver synchronization issue that couldn’t be handled by one of those.

I may be dense, but I have never found condition variables useful for anything in UM or KM

based on your question though, I think that you are either worried about how to shutdown cleanly, or what you want to do is not a ‘work queue’ but a way to parallelize a work load across multiple CPUs

whatever you want to do, you will certainly need to implement the correct synchronization yourself from first principals and the CPU or scheduler constructs available to you.