- 论坛徽章:
- 0
|
10可用积分
今天学习pthread_mutex机制的时候,看到pthread_mutex_lock最后调用到了lll_futex_wait(i386版本),就是无法锁定时排队等待的部分,code是C的内嵌汇编。
语法(Output,Input,Modifier)我基本上能够看懂,就是不知道内核是如何保存当前的线程信息,供lll_futex_wake来唤醒被阻塞的线程的?
下面的offsetof(tcbhead_t, sysinfo)仅仅是得到一个常数的偏移值
#define lll_futex_wait(futex, val) \ futex是一个int*,指向mutex成员中的lock
({ \
int __status; \
register __typeof (val) _val asm ("edx") = (val); \
__asm __volatile (LLL_EBX_LOAD \
LLL_ENTER_KERNEL \
LLL_EBX_LOAD \
: "=a" (__status) \
: "0" (SYS_futex), LLL_EBX_REG (futex), "S" (0), \
"c" (FUTEX_WAIT), "d" (_val), \
"i" (offsetof (tcbhead_t, sysinfo)) \
: "memory"); \
__status; \
})
#ifdef PIC
# define LLL_EBX_LOAD "xchgl %2, %%ebx\n"
# define LLL_EBX_REG "D"
#else
# define LLL_EBX_LOAD
# define LLL_EBX_REG "b"
#endif
#ifdef I386_USE_SYSENTER
# ifdef SHARED
# define LLL_ENTER_KERNEL "call *%%gs:%P6\n\t"
# else
# define LLL_ENTER_KERNEL "call *_dl_sysinfo\n\t"
# endif
#else
# define LLL_ENTER_KERNEL "int $0x80\n\t"
#endif
[ 本帖最后由 yausrnm 于 2007-2-9 23:59 编辑 ] |
|