0

Have anyone tried porting windows driver code to Linux, and struck in replacing the WaitForMultipleObjects API to Linux.

WaitForSingleObject can be replaced with wait_event_interruptible..

But what about WaitForMultipleObjects.. I see post in which they are using pthread_cond_wait for user space application. What is the alternative for linux kernel space..

Thanks for your time..

md.jamal
  • 4,067
  • 8
  • 45
  • 108
  • Related, see [WaitForSingleObject and WaitForMultipleObjects equivalent in Linux](https://stackoverflow.com/q/2719580/608639). – jww Aug 13 '18 at 06:09
  • I need a solution for kernel space and not user space – md.jamal Aug 13 '18 at 06:10

1 Answers1

1

You arrange so that multiple code paths that represent events call wake_up() on same waitqueue. This will be equivalent of WaitForMultipleObjects with false WaitAll.

How to know which event occurred: one possibility is to use a wake-up variant with a little known "key" parameter: wake_up_poll() and its friends. See linux/wait.h. The "key" parameter should be unique for every event. Then, customize the wake handler function of the wait queue (of type wait_queue_func_t). It accepts four arguments; the "key" is the last one, unused by the default handler. "Subclass" it and use the "key" arg to identify who has waked.

For WaitAll=true, keep waiting until all events occur.

ddbug
  • 1,392
  • 1
  • 11
  • 25