User space atomic operation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I want to do the atomic operation ( such as i++ ) in user space, can I copy
and include include/XXX/atomic.h directly?

========================================================
The following is my test code:

/*   atomic.c */
#include "atomic.h"    /* copy from include/asm-sparc/atomic.h */

int main(int argc, char *argv[])
{
        atomic_t atom;
        atomic_set(&atom, 1);
        return 0;
}
========================================================
After I compile it with gcc and disassemble with gdb, I get the following
code:

(gdb) disas main
Dump of assembler code for function main:
0x106c8 <main>: save  %sp, -120, %sp
0x106cc <main+4>:       st  %i0, [ %fp + 0x44 ]
0x106d0 <main+8>:       st  %i1, [ %fp + 0x48 ]
0x106d4 <main+12>:      mov  1, %o0                 ==> (1)
0x106d8 <main+16>:      st  %o0, [ %fp + -20 ]      ==> (2)
0x106dc <main+20>:      clr  %i0
0x106e0 <main+24>:      b  0x106e8 <main+32>
0x106e4 <main+28>:      nop
0x106e8 <main+32>:      ret
0x106ec <main+36>:      restore
End of assembler dump.
(gdb) quit
========================================================

I think line (1)&(2) do the atomic_set(&atom, 1) work, is it a atomic
operation?

Thanks,
Richard

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux