[openib-general] [PATCH] Encapsulate finding of id in sa_query.c
Krishna Kumar
krkumar at us.ibm.com
Mon Nov 8 10:50:44 PST 2004
On Fri, 5 Nov 2004, Roland Dreier wrote:
> Thanks but I'm not going to apply this. I prefer to have the locking
> and the idr lookup be explicit (and it's only done in two places so
> the cleanup is pretty minimal).
Actually three places ... And IMO, it does make the locking code look
cleaner, eg, the original code (with multiple unlocks) :
void ib_sa_cancel_query(int id, struct ib_sa_query *query)
{
unsigned long flags;
spin_lock_irqsave(&idr_lock, flags);
if (idr_find(&query_idr, query->id) != query) {
spin_unlock_irqrestore(&idr_lock, flags);
return;
}
spin_unlock_irqrestore(&idr_lock, flags);
ib_cancel_mad(query->port->agent, query->id);
}
now becomes :
void ib_sa_cancel_query(int id, struct ib_sa_query *query)
{
if (ib_sa_find_idr(id) == query)
ib_cancel_mad(query->port->agent, query->id);
}
with the find:
static inline struct ib_sa_query *ib_sa_find_idr(int id)
{
struct ib_sa_query *query
unsigned long flags;
spin_lock_irqsave(&idr_lock, flags);
query = idr_find(&query_idr, id);
spin_unlock_irqrestore(&idr_lock, flags);
return query;
}
thx,
- KK
More information about the general
mailing list