錯誤: 隱式聲明函數‘init_MUTEX’ [-Werror=implicit-function-declaration]

來源:互聯網
上載者:User

在新版本的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  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.