このトピックは、このフォーラムや他のすべてのフォーラムで何度も議論されてきましたが、それでも私には疑問があります. 助けてください。
do{} while(0)
in マクロは Linux カーネルでどのように機能しますか? 例えば、
#define preempt_disable() do { } while (0)
どのようにプリエンプションを無効にしますか?
#define might_resched() do { } while (0)
再スケジュールはどのように行われますか?
同様に、mutex ロックなどのマクロも見てきました。これはどのように役立ちますか? 次の問題については理解していますが、上記の例については理解していません。
#define foo(x) do { do something } while(0)
編集:
の次のコードはrt_mutex_lock
どうですか?
/**
* rt_mutex_lock - lock a rt_mutex
*
* @lock: the rt_mutex to be locked
*/
void __sched rt_mutex_lock(struct rt_mutex *lock)
{
might_sleep();
rt_mutex_fastlock(lock, TASK_UNINTERRUPTIBLE, 0, rt_mutex_slowlock);
}
EXPORT_SYMBOL_GPL(rt_mutex_lock);
/*
* debug aware fast / slowpath lock,trylock,unlock
*
* The atomic acquire/release ops are compiled away, when either the
* architecture does not support cmpxchg or when debugging is enabled.
*/
static inline int rt_mutex_fastlock(struct rt_mutex *lock,
int state, int detect_deadlock, int (*slowfn)(struct rt_mutex *lock,
int state, struct hrtimer_sleeper *timeout, int detect_deadlock))
{
if (!detect_deadlock && likely(rt_mutex_cmpxchg(lock, NULL, current))) {
rt_mutex_deadlock_account_lock(lock, current);
return 0;
} else{
return slowfn(lock, state, NULL, detect_deadlock);
}
}
rt_mutex_deadlock_account_lock
カーネル内の 2 つの場所で定義されているため、混乱しています。
でkernel/rtmutex-debug.c
:
void rt_mutex_deadlock_account_lock(struct rt_mutex *lock,
struct task_struct *task)
{
//....
}
でkernel/rtmutex.h
:
#define rt_mutex_deadlock_account_lock(m, t) do { } while (0)
i2c ドライバーの新しいカーネル 2.6.35.4 ではrt_mutex_lock(&adap->bus_lock);
、mutex_lock()
. これはどのようにロックしますか?