GLib: atomic integer operations

  I would like to propose that a set of "atomic integer operations" be
included in a future glib. Something like this:

  These functions are very useful for threaded programs. Advantages:
	1. These operations do not require any locking/mutexes, so they are
super fast!;
	2. Thread-safe reference counting of objects without any performance
	3. They're very simple to implement; It takes only a few asm
instructions. Example (from NSPR):

/ PRInt32 _PR_x86_AtomicIncrement(PRInt32 *val)
/ Atomically increment the integer pointed to by 'val' and return
/ the result of the increment.
    .globl _PR_x86_AtomicIncrement
    .align 4
    movl 4(%esp), %ecx
    movl $1, %eax
    xaddl %eax, (%ecx)
    incl %eax

  For unsupported platforms, the behaviour can be emulated with mutexes, of course.

  Let me know what you think.

Gustavo João Alves Marques Carneiro
<gjc inescporto pt> <gustavo users sourceforge net>

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