[CRIU] [PATCH 5/5] x86: atomic -- Adopt code from linux kernel

Pavel Emelyanov xemul at parallels.com
Fri Feb 15 08:54:01 EST 2013


On 02/15/2013 05:48 PM, Cyrill Gorcunov wrote:
> On Fri, Feb 15, 2013 at 05:28:42PM +0400, Pavel Emelyanov wrote:
>> On 02/06/2013 12:04 AM, Cyrill Gorcunov wrote:
>>>
>>> This allow us to eliminate "asm/types.h" inclusion as well,
>>> together with simplifying the code.
>>>
>>> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
>>> ---
>>>  arch/x86/include/asm/atomic.h | 92 +++++++++++++++++++------------------------
>>>  include/lock.h                |  3 +-
>>>  2 files changed, 43 insertions(+), 52 deletions(-)
>>>
>>
>>
>>> @@ -119,7 +119,8 @@ static void inline mutex_lock(mutex_t *m)
>>>  	u32 c;
>>>  	int ret;
>>>  
>>> -	while ((c = atomic_inc(&m->raw))) {
>>> +	while ((c = atomic_read(&m->raw))) {
>>> +		atomic_inc(&m->raw);
>>
>> This is not equal change. It was while (atomic_get_and_inc) now its while (atomic_get) atomic_inc.
> 
> Which actually doesn't change much. Look, atomic_inc was incrementing value and
> returning its previous meaning, now we do the same but this looks as "two"
> operations from C code, but the cycle below is constructed to be lockless so you will
> not get any harm in such transition. I rather feel sorry that I wrote it in
> "lock xchg" manner earlier.

Cyrill,

if (atomic_get_and_inc())

and

if (atomic_get())
	atomic_inc();

_do_ _work_ _differently_.

> .
> 




More information about the CRIU mailing list