免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1860 | 回复: 2
打印 上一主题 下一主题

关于spin_lock的作用和实现 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-06-14 14:40 |只看该作者 |倒序浏览
本人在学习内核源代码内存模块(2。4。2)时,发现spin_lock有多种实现。
其中一种:
#define DEBUG_SPINLOCKS        0        /* 0 == no debugging, 1 == maintain lock state, 2 == full debug */
#if (DEBUG_SPINLOCKS < 1)
  #define spin_lock(lock)                (void)(lock) /* Not "unused variable". */
#elif (DEBUG_SPINLOCKS < 2)
  #define spin_lock(x)                do { (x)->;lock = 1; } while (0)
#else /* (DEBUG_SPINLOCKS >;= 2) */
  #define spin_lock(x)               
       do {unsigned long __spinflags; save_flags(__spinflags); cli(); if ((x)->;lock&&(x)->;babble) {printk("%s:%d: spin_lock(%s:%p) already locked\n", __BASE_FILE__,__LINE__, (x)->;module, (x));(x)->;babble--;} (x)->;lock = 1; restore_flags(__spinflags);} while (0)
#endif

理解如下:
    随着DEBUG_SPINLOCKS取植不同,函数有不同定义。好象只在其为2时,才调用cli关中断。其余情况
    没有实际用途。请问我理解正确?

另外一种:
include\asm-i386\spinlock.h
   static inline void spin_lock(spinlock_t *lock)
   {
#if SPINLOCK_DEBUG
        __label__ here;
here:
        if (lock->;magic != SPINLOCK_MAGIC) {
printk("eip: %p\n", &&here);
                BUG();
        }
#endif
        __asm__ __volatile__(
                spin_lock_string
                :"=m" (lock->;lock) : : "memory";
  }
  不太理解,请指教!

论坛徽章:
0
2 [报告]
发表于 2004-07-12 12:51 |只看该作者

关于spin_lock的作用和实现

你的理解是错的,
0 == no debugging, 1 == maintain lock state, 2 == full debug

论坛徽章:
0
3 [报告]
发表于 2004-07-14 13:38 |只看该作者

关于spin_lock的作用和实现

自旋锁据说效率特别高。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP