Error: Implicit declaration function 'init _ mutex '[-werror = implicit-function-Declaration]

Source: Internet
Author: User

In the new Linux kernel, init_mutex has been abolished, and the new version uses the sema_init function. I checked the definitions of earlier versions:

Platform: x86 32-bit

Kernel: 2.6.30

Definition:

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) // In the latest version, none of the two macros define 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

Note: The init_mutex () function initializes the semaphores as mutex. Mutex is a special case of semaphores. It can prevent data from being read and written by two different systems.

Sema_init (SEM, 1) is defined:

Platform: x86 32-bit

Kernel: 3.0.xx

Definition:

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  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.