linux互斥与同步 之 互斥锁

来源:互联网 发布:java socket实例 编辑:程序博客网 时间:2024/06/06 01:53

1、互斥锁的定义

互斥缩mutex是在semaphore的基础上将struct semaphore中的count设为1而演化而来的。

在此基础上做了优化。

struct mutex {
 ____/* 1: unlocked, 0: locked, negative: locked, possible waiters */
 ____atomic_t________count;
 ____spinlock_t______wait_lock;
 ____struct list_head____wait_list;
 #if defined(CONFIG_DEBUG_MUTEXES) || defined(CONFIG_SMP)
 ____struct thread_info__*owner;
 #endif
 #ifdef CONFIG_DEBUG_MUTEXES
 ____const char _____*name;
 ____void____________*magic;
 #endif
 #ifdef CONFIG_DEBUG_LOCK_ALLOC
 ____struct lockdep_map__dep_map;
 #endif
 };


2、mutex的初始化

DEFINE_MUTEX(mutexname) : 静态定义初始化

mutex_init : 动态初始化


3、mutex的DOWN操作

void __sched mutex_lock(struct mutex * lock)


4、mutex的UP操作

void __sched mutex_unlock(struct mutex *lock)


TODO:后续要更详细的分析


原创粉丝点击