Messages in this thread | ![/](/images/icornerl.gif) | | Date | Mon, 29 Nov 2010 14:09:35 -0600 (CST) | From | Christoph Lameter <> | Subject | Re: [thisops uV2 04/10] x86: Support for this_cpu_add,sub,dec,inc_return |
| |
On Mon, 29 Nov 2010, Mathieu Desnoyers wrote:
> Ah, ok, so you don't mind if var and val have different types. You just want > the compiler to be able to cast one into the other without complaining. > > Isn't it already checked by "typeof(var) pfo_ret__ = val;" ?
Right. I will drop that strange fragment.
> But at the end, you return : > > pfo_ret__ + (val); > > So if pfo_ret has a type smaller than val (e.g. unsigned short vs unsigned int), > unless I'm mistakened, the type returned by percpu_add_return_op will be an > unsigned int (the larger of the two), but the atomic operation is performed on > an unsigned short. This might cause confusion for the caller. Casting > > pfo_ret__ + (typeof(var)) (val); > > might be appropriate.
The return needs to be constrained to pfo_ret__. If the value wraps around then we do not want a value larger than the variable returned.
pfo_ret__ += val; pfo_ret;
will do I think.
| ![\](/images/icornerr.gif) |