2

I'm trying to understand how to use the Linux kernel spinlocks. From reading the header, I think I have to first declare one and initialize it like this with spin_lock_init:

spinlock_t xxx_lock;
spin_lock_init(&xxx_lock);

and then I can lock and unlock it with spin_lock and spin_unlock.

I hope what I understood until here is correct. But what do I have to do to "invert" the spin_lock_init? How do I destroy the spinlock?

memememe
  • 663
  • 6
  • 21
  • Look up the type. Maybe it's just a plain, ordinary data struct and so does not need an explicit destructor function? 'Init' probably just initializes it's fields. – Martin James Jun 30 '20 at 14:32
  • Not an answer to the question but I see that they can also be defined with a macro: `DEFINE_SPINLOCK(xxx_lock)`. – eftshift0 Mar 28 '21 at 14:03

1 Answers1

3

A spinlock doesn't require special finalization function (destructor).

When a spinlock is unlocked, it isn't used by the kernel internally. So, if you don't intend to use an unlocked spinlock anymore, just forget about it.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153