This chapter has introduced many symbols for concurrent management. The most important of these are summarized here:
-
# Include <ASM/semaphore. h> // defines the semaphore and the contained files operated on it.
-
Definition and initialization of semaphores
(1) static definition and initialization
-
Declare_mutex (name );
-
Declare_mutex_locked (name );
-
(2) dynamic definition and initialization
Struct semaphore SEM
-
Void init_mutex (struct semaphore * SEM );
-
Void init_mutex_locked (struct semaphore * SEM );
Acquisition and release of semaphores
-
Void down (struct semaphore * SEM );
-
Int down_interruptible (struct semaphore * SEM );
-
Int down_trylock (struct semaphore * SEM );
-
Void up (struct semaphore * SEM );
-
The down operation causes the calling process to enter an uninterrupted sleep. down_interruptible, on the contrary, can be interrupted by signals. Generally, this operation should be used. down_trylock does not sleep; instead, it immediately returns if the flag is unavailable. after obtaining the semaphore and completing related operations, you must use up to release it.
-
-
Struct rw_semaphore;
-
Init_rwsem (struct rw_semaphore * SEM );
-
The reader/writer version of the flag and the function for initializing it.
-
Void down_read (struct rw_semaphore * SEM );
-
Int down_read_trylock (struct rw_semaphore * SEM );
-
Void up_read (struct rw_semaphore * SEM );
-
Obtain and release the Read access function for the reader/writer flag.
-
Void down_write (struct rw_semaphore * SEM );
-
Int down_write_trylock (struct rw_semaphore * SEM );
-
Void up_write (struct rw_semaphore * SEM );
-
Void downgrade_write (struct rw_semaphore * SEM );
-
Manage the function for accessing the reader/writer flag writing.
-
# Include <Linux/completion. h>
-
Declare_completion (name );
-
Init_completion (struct completion * C );
-
Init_completion (struct completion C );
-
Describes the inclusion file of the Linux completion mechanism, which is the normal method for initializing the completion. init_completion should only be used to reinitialize a previously used completion.
-
Void wait_for_completion (struct completion * C );
-
Wait for a completion event to be triggered.
-
Void complete (struct completion * C );
-
Void complete_all (struct completion * C );
-
Trigger a completion event. Completion wake up. At most, a waiting thread, while complete_all wake up all waiting parties.
-
Void complete_and_exit (struct completion * C, long retval );
-
Call complete to issue a completion event and call exit for the current thread.
Spin lock
-
# Include <Linux/spinlock. h>
-
Spinlock_t lock = spin_lock_unlocked;
-
Spin_lock_init (spinlock_t * Lock );
-
Defines the contained file of the spin lock interface and the two methods for initializing the lock.
-
Void spin_lock (spinlock_t * Lock );
-
Void spin_lock_irqsave (spinlock_t * Lock, unsigned long flags );
-
Void spin_lock_irq (spinlock_t * Lock );
-
Void spin_lock_bh (spinlock_t * Lock );
-
Various methods for locking a spin lock, and, possibly, disallow interruption.
-
Int spin_trylock (spinlock_t * Lock );
-
Int spin_trylock_bh (spinlock_t * Lock );
-
The non-spin version of the above function; 0 is returned when the lock fails to be obtained; otherwise, it is not zero.
-
Void spin_unlock (spinlock_t * Lock );
-
Void spin_unlock_irqrestore (spinlock_t * Lock, unsigned long flags );
-
Void spin_unlock_irq (spinlock_t * Lock );
-
Void spin_unlock_bh (spinlock_t * Lock );
-
Release a spin lock.
-
Rwlock_t lock = rw_lock_unlocked
-
Rwlock_init (rwlock_t * Lock );
-
Initialize two methods of Reader/writer lock.
-
Void read_lock (rwlock_t * Lock );
-
Void read_lock_irqsave (rwlock_t * Lock, unsigned long flags );
-
Void read_lock_irq (rwlock_t * Lock );
-
Void read_lock_bh (rwlock_t * Lock );
-
Obtain the Read access function of a reader/writer lock.
-
Void read_unlock (rwlock_t * Lock );
-
Void read_unlock_irqrestore (rwlock_t * Lock, unsigned long flags );
-
Void read_unlock_irq (rwlock_t * Lock );
-
Void read_unlock_bh (rwlock_t * Lock );
-
Releases read access to a reader/writer spin lock.
-
Void write_lock (rwlock_t * Lock );
-
Void write_lock_irqsave (rwlock_t * Lock, unsigned long flags );
-
Void write_lock_irq (rwlock_t * Lock );
-
Void write_lock_bh (rwlock_t * Lock );
-
Obtain the write access function of a reader/writer lock.
-
Void write_unlock (rwlock_t * Lock );
-
Void write_unlock_irqrestore (rwlock_t * Lock, unsigned long flags );
-
Void write_unlock_irq (rwlock_t * Lock );
-
Void write_unlock_bh (rwlock_t * Lock );
-
Releases a write access function for the reader/writer spin lock.
-
# Include <ASM/Atomic. h>
-
Atomic_t v = atomic_init (value );
-
Void atomic_set (atomic_t * V, int I );
-
Int atomic_read (atomic_t * V );
-
Void atomic_add (int I, atomic_t * V );
-
Void atomic_sub (int I, atomic_t * V );
-
Void atomic_inc (atomic_t * V );
-
Void atomic_dec (atomic_t * V );
-
Int atomic_inc_and_test (atomic_t * V );
-
Int atomic_dec_and_test (atomic_t * V );
-
Int atomic_sub_and_test (int I, atomic_t * V );
-
Int atomic_add_negative (int I, atomic_t * V );
-
Int atomic_add_return (int I, atomic_t * V );
-
Int atomic_sub_return (int I, atomic_t * V );
-
Int atomic_inc_return (atomic_t * V );
-
Int atomic_dec_return (atomic_t * V );
-
Atomic access to integer variables. atomic_t variables must be accessed only through these functions.
-
# Include <ASM/bitops. h>
-
Void set_bit (NR, void * ADDR );
-
Void clear_bit (NR, void * ADDR );
-
Void change_bit (NR, void * ADDR );
-
Test_bit (NR, void * ADDR );
-
Int test_and_set_bit (NR, void * ADDR );
-
Int test_and_clear_bit (NR, void * ADDR );
-
Int test_and_change_bit (NR, void * ADDR );
-
Atomic access bit values; they can be used as signs or lock variables. Use these functions to prevent any competition related to concurrent access.
-
# Include <Linux/seqlock. h>
-
Seqlock_t lock = seqlock_unlocked;
-
Seqlock_init (seqlock_t * Lock );
-
Defines the seqlock inclusion files and has initialized two methods for them.
-
Unsigned int read_seqbegin (seqlock_t * Lock );
-
Unsigned int read_seqbegin_irqsave (seqlock_t * Lock, unsigned long flags );
-
Int read_seqretry (seqlock_t * Lock, unsigned int SEQ );
-
Int read_seqretry_irqrestore (seqlock_t * Lock, unsigned int seq, unsigned long flags );
-
A function that obtains the read permission of a seqlock-protected resource.
-
Void write_seqlock (seqlock_t * Lock );
-
Void write_seqlock_irqsave (seqlock_t * Lock, unsigned long flags );
-
Void write_seqlock_irq (seqlock_t * Lock );
-
Void write_seqlock_bh (seqlock_t * Lock );
-
Obtain the write permission of a seqlock-protected resource.
-
Void write_sequnlock (seqlock_t * Lock );
-
Void write_sequnlock_irqrestore (seqlock_t * Lock, unsigned long flags );
-
Void write_sequnlock_irq (seqlock_t * Lock );
-
Void write_sequnlock_bh (seqlock_t * Lock );
-
Releases the write permission of a seqlock-protected resource.
-
# Include <Linux/rcupdate. h>
-
You need to use the read-copy-Update (RCU) mechanism to include files.
-
Void rcu_read_lock;
-
Void rcu_read_unlock;
-
Gets the macro definition of the atomic read permission on resources protected by RCU.
-
Void call_rcu (struct rcu_head * head, void (* func) (void * Arg), void * Arg );
-
Schedule a callback to run after all processors have been scheduled and a RCU-protected resource can be safely released.