int res_counter_write(struct res_counter *counter, int member,
const char *buffer, write_strategy_fn write_strategy);
+void res_counter_write_u64(struct res_counter *counter, int member, u64 val);
+
/*
* the field descriptors. one for each member of res_counter
*/
return 0;
}
+void res_counter_write_u64(struct res_counter *counter, int member, u64 val)
+{
+ unsigned long long *target;
+ unsigned long flags;
+
+ /*
+ * We need the lock to protect against concurrent add/dec on 32 bits.
+ * No need to ifdef it's seldom used.
+ */
+ spin_lock_irqsave(&counter->lock, flags);
+ target = res_counter_member(counter, member);
+ *target = val;
+ spin_unlock_irqrestore(&counter->lock, flags);
+}
+
int res_counter_write(struct res_counter *counter, int member,
const char *buf, write_strategy_fn write_strategy)
{
char *end;
- unsigned long flags;
- unsigned long long tmp, *val;
+ unsigned long long tmp;
if (write_strategy) {
if (write_strategy(buf, &tmp))
if (*end != '\0')
return -EINVAL;
}
- spin_lock_irqsave(&counter->lock, flags);
- val = res_counter_member(counter, member);
- *val = tmp;
- spin_unlock_irqrestore(&counter->lock, flags);
+
+ res_counter_write_u64(counter, member, tmp);
+
return 0;
}