博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
读写锁总结
阅读量:4216 次
发布时间:2019-05-26

本文共 1585 字,大约阅读时间需要 5 分钟。

读写锁分为spinlock 类型和信号量类型首先看spinlock类型其中spinlock类型的读写锁定义在include/linux/rwlock_types.h其结构定义如下:typedef struct {	arch_rwlock_t raw_lock;#ifdef CONFIG_DEBUG_SPINLOCK	unsigned int magic, owner_cpu;	void *owner;#endif#ifdef CONFIG_DEBUG_LOCK_ALLOC	struct lockdep_map dep_map;#endif} rwlock_t;可以看出出去debug的config 后rwlock_t就等于下面的结构typedef struct {	arch_rwlock_t raw_lock;} rwlock_t;读写spinlock的API 都定义在include/linux/rwlock.h 中例如在使用读写spinlock锁时候,首先初始化# define rwlock_init(lock)					\do {								\	static struct lock_class_key __key;			\								\	__rwlock_init((lock), #lock, &__key);			\} while (0)然后是读锁的lock 和 unlockread_lock()read_unlock()其次是写锁的lock 和 unlockwrite_lock()write_unlock剩下就是spinlock锁有的API在rwlock这边都会有,例如read_lock_irq/write_lock_irq等其次是读写信号量锁其定义在include/linux/rwsem.h中#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK#include 
/* use a generic implementation */#define __RWSEM_INIT_COUNT(name) .count = RWSEM_UNLOCKED_VALUE#else/* All arch specific implementations share the same struct */struct rw_semaphore { atomic_long_t count; struct list_head wait_list; raw_spinlock_t wait_lock;#ifdef CONFIG_RWSEM_SPIN_ON_OWNER struct optimistic_spin_queue osq; /* spinner MCS lock */ /* * Write owner. Used as a speculative check to see * if the owner is running on the cpu. */ struct task_struct *owner;#endif#ifdef CONFIG_DEBUG_LOCK_ALLOC struct lockdep_map dep_map;#endif};其初始化为#define init_rwsem(sem) \do { \ static struct lock_class_key __key; \ \ __init_rwsem((sem), #sem, &__key); \} while (0)对应的读锁的lock和unlockdown_read ()up_read()写锁的lock和unlockdown_write()up_write()

转载地址:http://vnnmi.baihongyu.com/

你可能感兴趣的文章
【屌丝程序的口才逆袭演讲稿50篇】第八篇:坚持的力量 【张振华.Jack】
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第九篇:春节那些事-过年回家不需要理由【张振华.Jack】
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第十篇:程序员们请看看外面的世界吧【张振华.Jack】
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第十一篇:马云乌镇40分钟演讲实录【张振华.Jack】
查看>>
Java并发编程从入门到精通 张振华.Jack --我的书
查看>>
【屌丝程序的口才逆袭演讲稿50篇】第十二篇:世界上最快的捷径【张振华.Jack】
查看>>
Android中Java代码和XML布局效率问题
查看>>
android TextView属性大全(转)
查看>>
Conclusion for Resource Management
查看>>
Conclusion for Constructors,Destructors,and Assignment Operators
查看>>
Conclusion for Accustoming Yourself to C++
查看>>
面试题1:赋值运算函数(offer)
查看>>
Mark : MessagePack简介及使用
查看>>
Mark : Hadoop Raid-实战经验总结
查看>>
Structured Streaming 实现思路与实现概述
查看>>
Apache Spark 2.2.0 中文文档 - Structured Streaming 编程指南 | ApacheCN
查看>>
Mark:大数据最佳学习路线
查看>>
Spark 多线程模型
查看>>
编程第一性原则
查看>>
Mark : SpringBoot核心-非关系型数据库NoSQL
查看>>