Init_mutex is abolished (resolves error:implicit declaration of function ' Init_mutex ')

Source: Internet
Author: User
Tags semaphore
CSDN GitHub
Init_mutex was abolished
Resolve Error:implicit declaration of function ' Init_mutex '
Ldd/problem/port/init_mutex



This work uses the Knowledge sharing signature-non-commercial use-the same way Shares 4.0 international License Agreement to authorize, reprint please indicate the source

1 Questions

The following error was prompted during the recent migration drive

Error:implicit declaration of function ' Init_mutex ' [-werror=implicit-function-declaration] 2 causal analysis

In the Linux kernel after 2.6.37, Init_mutex has been abolished and the new version uses the Sema_init function

Check out the definition of an earlier version, see Include/linux/semaphore.h, Version 2.6.36.4, line 42

static inline void Sema_init (struct semaphore *sem, int val)
{
    static struct lock_class_key;
    *sem = (struct semaphore) __semaphore_initializer (*sem, Val);
    Lockdep_init_map (&sem->lock.dep_map, "Semaphore->lock", &__key, 0);
}

#define INIT_MUTEX (SEM)     sema_init (SEM, 1)
#define INIT_MUTEX_LOCKED (SEM)  sema_init (SEM, 0)
3 Solutions

Modify the Init_mutex to Sema_init, or you can define Init_mutex modifications in the drive Init_mutex for Sema_init

#if linux_version_code > Kernel_version (2, 6,) &&!defined (Init_mutex)
    sema_init (&sem, 1);
#else
    Init_mutex (&sem);
#endif
Define Init_mutex as Sema_init
#if linux_version_code > Kernel_version (2, 6) &&!defined (Init_mutex)
#define INIT_MUTEX (SEM)     sema_init (SEM, 1)
#endif

In fact, in the early kernel, the definition of sema_init, so you can not need to add #if #endif macros, directly modify Init_mutex for Sema_init is not a problem.


This work/Bowen (aderstep-Purple night-Blue Ling Xiang Cao copyright©2013-2017), by Chengjian (gatieme) creation,

Use of knowledge-sharing signatures-non-commercial use-Share 4.0 International license agreements in the same way. Welcome to reprint, use, republish, but be sure to keep the article signed Chengjian Gatieme (including Links: http://blog.csdn.net/gatieme/article/details/71598127), not for commercial purposes,

Based on the modified works of this article must be issued with the same license. If you have any questions, please contact me.

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.