mutex_owned(9F) 的语法如下:
int mutex_owned(kmutex_t *mp);
驱动程序开发过程中的一项重要工作涉及正确处理多个线程。获得了互斥锁时,应始终使用注释。在未获得明确需要的互斥锁时,注释将更有用。要确定线程是否持有互斥锁,请在 ASSERT(9F) 中使用 mutex_owned():
void helper(void) { /* this routine should always be called with xsp's mutex held */ ASSERT(mutex_owned(&xsp->mu)); /* ... */ }
mutex_owned() 只在 ASSERT() 宏内有效。应该使用 mutex_owned() 控制驱动程序的行为。