Mirek Fidler said:
Well, before going into details....
Have you found a way how to implement lock-free reference counting
usable e.g. for COW string? (with "weak" guarantee for string itself)?
If yes, what is the idea, if you are willing to share?
http://groups.google.com/group/comp.lang.c++.moderated/msg/a08aa9fe4d0d823e
In order for this to work I have to add CAS to the library... Humm, Well,
here is the source code for the CAS functions:
(mingw-gas)
--------------
..align 16
# int refcount_ia32_cas(
# refcount_ia32_t* volatile*,
# refcount_ia32_t*,
# refcount_ia32_t*)
..globl _refcount_ia32_cas
_refcount_ia32_cas:
MOVL 4(%ESP), %ECX
TESTL %ECX, %ECX
JE refcount_ia32_cas_failed
MOVL 8(%ESP), %EAX
MOVL 12(%ESP), %EDX
LOCK CMPXCHGL %EDX, (%ECX)
CMPL %EAX, 8(%ESP)
JNE refcount_ia32_cas_failed
MOVL $1, %EAX
RETL
refcount_ia32_cas_failed:
XORl %EAX, %EAX
RETL
..align 16
# int refcount_ia32_add_cas_weak(
# refcount_ia32_t* volatile*,
# refcount_ia32_t*,
# refcount_ia32_t*,
# int)
..globl _refcount_ia32_add_cas_weak
_refcount_ia32_add_cas_weak:
MOVL 4(%ESP), %ECX
TESTL %ECX, %ECX
JE refcount_ia32_cas_failed
MOVL 12(%ESP), %EDX
TESTL %EDX, %EDX
JE refcount_ia32_add_cas_weak_execute
MOVL 16(%ESP), %EAX
CMPL $0, %EAX
JLE refcount_ia32_add_cas_weak_execute
LOCK XADDL %EAX, (%EDX)
refcount_ia32_add_cas_weak_execute:
MOVL 8(%ESP), %EAX
LOCK CMPXCHG %EDX, (%ECX)
CMPL %EAX, 8(%ESP)
JNE refcount_ia32_add_cas_weak_dec
MOVL $1, %EAX
RETL
refcount_ia32_add_cas_weak_dec:
TESTL %EDX, %EDX
JE refcount_ia32_add_cas_weak_failed
CMPL $0, 16(%ESP)
JLE refcount_ia32_add_cas_weak_failed
LOCK DECL (%EDX)
refcount_ia32_add_cas_weak_failed:
XORL %EAX, %EAX
RETL
If you want to use CAS with my refcount library now, just stick the posted
source code in the refcount-ia32-mingw.asm file and assemble... Then create
the declarations in the refcount-ia32.h file, and add the proper member
functions to the refcount-sys.hpp and refcount.hpp files... Simple...
;^)
I am going to add the CAS to my library very soon, I will definitely keep
you posted. Okay?
:^)