Linux kernel 之 rwlock_t semaphore初始化

來源:互聯網
上載者:User
一. rwlock_t

一直都以這種方式初始化讀寫鎖

rwlock_t my_rwlock = RW_LOCK_UNLOCKED

但是在核心 2.6.30 上不行了 ....

error: ‘RW_LOCK_UNLOCKED’ undeclared (first use in this function)

error: (Each undeclared identifier is reported only once

error: for each function it appears in.)

貌似是高版本核心不支援這種初始化方式了

需要:

rwlock_t mylock;rwlock_init(&mylock);

或者直接定義並初始化:

DEFINE_RWLOCK(x)

二. semaphore

另外,高版本核心訊號量的初始化方式也發生了變化

原來的初始化 DECLARE_MUTEX(receive_sem);

會出現:

warning: data definition has no type or storage class

warning: type defaults to ‘int’ in declaration of ‘DECLARE_MUTEX’

warning: parameter names (without types) in function declaration

原來在 include/linux/semaphore.h 中,先前的

#define __SEMAPHORE_INITIALIZER(name, n)                \{                                   \    .lock       = __SPIN_LOCK_UNLOCKED((name).lock),        \    .count      = n,                        \    .wait_list  = LIST_HEAD_INIT((name).wait_list),     \}#define DECLARE_MUTEX(name) \    struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)

變成了現在的

#define __SEMAPHORE_INITIALIZER(name, n)                                \{                                                                       \        .lock           = __SPIN_LOCK_UNLOCKED((name).lock),            \        .count          = n,                                            \        .wait_list      = LIST_HEAD_INIT((name).wait_list),             \}#define DEFINE_SEMAPHORE(name)  \        struct semaphore name = __SEMAPHORE_INITIALIZER(name, 1)

最後做了如下修改, 之後warning就消失了

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)DECLARE_MUTEX(receive_sem);#elseDEFINE_SEMAPHORE(reveive_sem);#endif

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.