I have a question. Is DEFINE_SPINLOCK preferable over spin_lock_init? What are the advantages of former over latter, and what are the possible draw-backs?
If you have a static data structure, DEFINE_SPINLOCK lets you declare a spinlock variable and initialize it in one line. However for anything allocated at runtime, for example when a spinlock is embedded in a bigger structure, then you need to allocate the memory and then call spin_lock_init().
I guess I would say that I prefer DEFINE_SPINLOCK when it is possible to use it. The advantage is tiny (compile-time initialization vs. runtime initialization, a couple lines less of code) but there's no real drawback. As I mentioned above, it's often not possible to use DEFINE_SPINLOCK, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With