How do I implement a recursive mutex with a timeout in the OS X kernel?

I am porting a Windows device driver to Mac OS X. The Windows code uses KMUTEX. This is a recursive lock that can be acquired multiple times by the same thread. Other threads have to wait to receive it, but receiving will fail if a timeout occurs.

The I / O set IORecursiveLock does not timeout. I can use BSD locks or Mach locks. Part of the BSD kernel offers variable conditions using msleep () and wakeup ().

I don't understand if the condition variable will do what I want.

sem_timedwait (3) in BSD is in user space.

Keith Shortridge provides a custom set_timedwait space for implementation . One thread calls sem_wait () and the other thread, which sends a signal to the first one if a timeout occurs.

I can pipe the Shortridge code to the core, but I don't want to risk it. Google doesn't provide any other insight. Can you give me a key?

+3


source to share


1 answer


This link might be helpful, according to the documentation you have what you need, maybe wait_result_tlck_mtx_sleep_deadline method: https://developer.apple.com/library/content/documentation/Darwin/Conceptual/KernelProgramming/synchronization/synchronization.html# // apple_ref / doc / uid / TP30000905-CH218-BEHJDFCA



+2


source







All Articles