首页 > 代码库 > spinlock

spinlock

  Spinlock usually used in code that cannot sleep, thus has higher performance than semaphores.

  Spinlock is implemented as a bit in an integer value.

  Before using, a spinlock must be initialized as follows:

1 spinlock_t my_lock = SPIN_LOCK_UNLOCKED;
2 void spin_lock_init(spinlock_t *lock);

  Beforing entering the critical section, code must obtain the requisite lock with:

1 void spin_lock(spinlock_t *lock);

  Note that all spinlock are uninterruptible, whick means once you call spin_lock, you will spin until the lock become available.

  To release a lock that you have obtained, pass it to:

1 void spin_unlock(spinlock_t *lock);

 

spinlock