Search code examples
clinuxlinux-kernelspinlock

How to invert spin_lock_init


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?


Solution

  • 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.