在新版本的linux内核中,init_mutex已经被废除了,新版本使用sema_init函数。查了一下早期版本的定义:
平台:X86 32位
内核:2.6.30
定义:
Linux/include/linux/semaphore.h
1 /*
2 * Copyright (c) 2008 Intel Corporation
3 * Author: Matthew Wilcox <willy@linux.intel.com>
4 *
5 * Distributed under the terms of the GNU GPL, version 2
6 *
7 * Please see kernel/semaphore.c for documentation of these functions
8 */
9 #ifndef __LINUX_SEMAPHORE_H
10 #define __LINUX_SEMAPHORE_H
11
12 #include <linux/list.h>
13 #include <linux/spinlock.h>
14
15 /* Please don't access any members of this structure directly */
16 struct semaphore {
17 spinlock_t lock;
18 unsigned int count;
19 struct list_head wait_list;
20 };
21
22 #define __SEMAPHORE_INITIALIZER(name, n) \
23 { \
24 .lock = __SPIN_LOCK_UNLOCKED((name).lock), \
25 .count = n, \
26 .wait_list = LIST_HEAD_INIT((name).wait_list), \
27 }
28
29 #define DECLARE_MUTEX(name) \
30 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
31
32 static inline void sema_init(struct semaphore *sem, int val)
33 {
34 static struct lock_class_key __key;
35 *sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
36 lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
37 }
38
39 #define init_MUTEX(sem) sema_init(sem, 1)//在最新的版本中没有这两个宏定义了
40 #define init_MUTEX_LOCKED(sem) sema_init(sem, 0)
41
42 extern void down(struct semaphore *sem);
43 extern int __must_check down_interruptible(struct semaphore *sem);
44 extern int __must_check down_killable(struct semaphore *sem);
45 extern int __must_check down_trylock(struct semaphore *sem);
46 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
47 extern void up(struct semaphore *sem);
48
49 #endif /* __LINUX_SEMAPHORE_H */
50
说明:Init_MUTEX()函数初始化信号量为互斥量。 互斥量为信号量的特例,它可以防止数据被两个不同系统调用读写。
sema_init (sem, 1) 定义为:
平台:X86 32位
内核:3.0.xx
定义:
Linux/include/linux/semaphore.h
1 /*
2 * Copyright (c) 2008 Intel Corporation
3 * Author: Matthew Wilcox <willy@linux.intel.com>
4 *
5 * Distributed under the terms of the GNU GPL, version 2
6 *
7 * Please see kernel/semaphore.c for documentation of these functions
8 */
9 #ifndef __LINUX_SEMAPHORE_H
10 #define __LINUX_SEMAPHORE_H
11
12 #include <linux/list.h>
13 #include <linux/spinlock.h>
14
15 /* Please don't access any members of this structure directly */
16 struct semaphore {
17 spinlock_t lock;
18 unsigned int count;
19 struct list_head wait_list;
20 };
21
22 #define __SEMAPHORE_INITIALIZER(name, n) \
23 { \
24 .lock = __SPIN_LOCK_UNLOCKED((name).lock), \
25 .count = n, \
26 .wait_list = LIST_HEAD_INIT((name).wait_list), \
27 }
28
29 #define DEFINE_SEMAPHORE(name) \
30 struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)
31
32 static inline void sema_init(struct semaphore *sem, int val)
33 {
34 static struct lock_class_key __key;
35 *sem = (struct semaphore) __SEMAPHORE_INITIALIZER(*sem, val);
36 lockdep_init_map(&sem->lock.dep_map, "semaphore->lock", &__key, 0);
37 }
38
39 extern void down(struct semaphore *sem);
40 extern int __must_check down_interruptible(struct semaphore *sem);
41 extern int __must_check down_killable(struct semaphore *sem);
42 extern int __must_check down_trylock(struct semaphore *sem);
43 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
44 extern void up(struct semaphore *sem);
45
46 #endif /* __LINUX_SEMAPHORE_H */
47
分享到:
相关推荐
编译qtcreator源码,在make过程中报错(我这里是qtcreator4.4.1,其他版本也会有同样的错误,解决方法相同) g++ -c -pipe -fPIC -fpermissive -finline-functions -Wno-long-long -O2 -std=gnu++1y -fvisibility=...
STAR vs HISAT2 vs Salmon的再分析1....mutex=4.5=1_gnu - _r-mutex=1.0.1=anacondar_1 - binutils_impl_linux-64=2.35.1=h193b22a_2 - binutils_linux-64=2.35=h67ddf6f_30 - bioconductor-annotationdbi=1.52
使用Snakemake进行STAR对齐1.conda环境 name: snakemake_mappingchannels: - conda-forge - bioconda - defaultsdependencies: - _libgcc_mutex=0.1=conda_forge - _openmp_mutex=4.5=1_gnu - aiohttp=3.7.4=py39h...
18:可睡眠锁-互斥量mutex_rec 19:可睡眠锁:信号量semaphore_rec 20:可睡眠锁:读写信号量rwsem_rec 21:可睡眠锁:完成变量completion_rec 22:可睡眠锁:SRCUsleepable_read-copy-update_rec 23:原子操作_rec ...
162 = LOCK_MUTEX_ERR : ZTE_EXTENED 建链时锁错误 163 = RGSTRDDLVRY_ERR : ZTE_EXTENED Registered_Delivery取值错误 164 = FEEUSERTYPE_ERR : ZTE_EXTENED FeeUserType取值错误 165 = TERMINALTYPE_ERR : ...
static int capture_frame(void* capture,int (*set_disp_addr)(int,int,unsigned int*),pthread_mutex_t* mutex) { capture_handle* cap = (capture_handle*)capture; int ret; int i; struct v4l2_buffer buf;...
#0 0x00002b9405ea1c38 in __lll_mutex_lock_wait () from /lib64/libc.so.6 #1 0x00002b9405e45e5f in _L_lock_4026 () from /lib64/libc.so.6 #2 0x00002b9405e42df1 in free () from /lib64/libc.so.6 #3 0x00002...
gcc demo_main.c thread_cond.c thread_mutex.c thread_pool.c -o demo_main -lpthread 运行 ➜ Nginx_-_- git:(main) ✗ ./demo_main Hello, this is 1th test.index=0 Hello, this is 2th test.index=0 Hello, ...
AUTOLOAD:=$(call AutoLoad,90,videobuf-core videobuf-dma-contig cci vfe_os vfe_subdev gc2145 vfe_v4l2) endef 5、直接使用了tinav1.0上调通ov5640后的sys_config.fex (请注意:这里修改的电源部分,其他...
videobuf_queue_dma_contig_init(&dev->vb_vidq, &vfe_video_qops, NULL, &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,//default format, can be changed by s_fmt sizeof(struct vfe...
videobuf_queue_dma_contig_init(&dev->vb_vidq, &vfe_video_qops, NULL, &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,//default format, can be changed by s_fmt sizeof(struct vfe...
NACHOS 线程与同步 将实验一中的线程改为安全的
Mutex 又称互斥量,C++ 11中与 Mutex 相关的类(包括锁类型)和函数都声明在 <mutex> 头文件中,所以如果你需要使用 std::mutex,就必须包含 <mutex> 头文件。 <mutex> 头文件介绍 Mutex 系列类(四种) std::mutex,...
ucos-ii中互斥信号mutex建立源码
12 aos_mutex_new 13 aos_mutex_free 14 aos_mutex_lock 15 aos_mutex_unlock 16 aos_mutex_is_valid 17 aos_sem_new 18 aos_sem_free 19 aos_sem_wait 20 aos_sem_signal 21 aos_sem_is_valid 22 aos_sem...
C++11中的各种mutex, lock对象,实际上都是对posix的mutex,condition的封装。不过里面也有很多细节值得学习。 std::mutex 先来看下std::mutex: 包增了一个pthread_mutex_t __m_,很简单,每个函数该干嘛...
32位android中bionic是32位的,其中的mutex只有一半也就是16位能够存储pid,当通过docker运行android时,大概率pid会超过16位的范围,就可能会导致android中mutex死锁,表现为应用卡住黑屏。 [32-bit ABI bugs]...
pthread_mutex_t mutex; pthread_mutex_init(&mutex,NULL); pthread_mutex_lock(&mutex); pthread_mutex_unlock(&mutex); pthread_mutex_destroy(&mutex);
int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restric attr); int pthread_mutex_destroy(pthread_mutex_t *mutex); 头文件: 返回值: 成功则返回0, 出错则返回错误编号....
AudioPlayer