como {} enquanto (0) trabalha na macro?
Embora este tópico tenha sido discutido várias vezes neste fórum e em todos os outros, ainda tenho dúvidas. Por favor ajude.
Como é quedo{} while(0)
no trabalho de macro no kernel do Linux? Por exemplo,
#define preempt_disable() do { } while (0)
Como ele desativa a preempção?
#define might_resched() do { } while (0)
Como reagendar?
Da mesma forma, vi macros para bloqueios de mutex e outros também. Como isso ajuda? Entendo o seguinte problema, mas não para os exemplos acima.
#define foo(x) do { do something } while(0)
Editar:
E o código a seguir parart_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);
}
}
Estou confuso porquert_mutex_deadlock_account_lock
é definido em dois lugares no kernel:
Nokernel/rtmutex-debug.c
:
void rt_mutex_deadlock_account_lock(struct rt_mutex *lock,
struct task_struct *task)
{
//....
}
Nokernel/rtmutex.h
:
#define rt_mutex_deadlock_account_lock(m, t) do { } while (0)
No novo kernel 2.6.35.4 no driver i2crt_mutex_lock(&adap->bus_lock);
substituiu omutex_lock()
. Como isso trava então?