0

I'm writing a linux kernel driver and I have a function which MUST be called under lock, and I want to make sure no one will use it without acquiring the lock. This function is called many times from different functions which acquire the lock prior to calling the function.

I'm wondering if there is a way of telling the compiler to verify that all calls to that function are done under a lock? something like function attributes or something similar.

thanks.

  • You don't say what language? Assuming c++, you could insist that one argument is a reference to the RAII object wrapping the lock. If caller don't have that RAII object they can't have locked? If the fn is deeply nested vs the locker, passing it round will be a pain. Another option is to put all the methods that need the lock in an internal class, and only by calling a lock method on the public class can you get back an RAII object which both releases the lock and exposes the inner interface. The public class can also have helper methods that hold the lock and call the inner method one-off. – Gem Taylor Nov 21 '18 at 23:31
  • sorry, it's for linux kernel driver, language is C. – Idan Emergi Nov 22 '18 at 09:18
  • No. There is none of my knowledge. I know the opposite, but it’s still for runtime, and not for compile time. Use comment block for that. – 0andriy Dec 01 '18 at 10:24

0 Answers0