From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-11-20 07:05:30
From: "Rene Jager" <renej_at_[hidden]>
> I think that in order to keep shared_ptr useable (at least in my work
> ;-) is to use inline assembly for
> atomic counters as much as possible; If you have a linux box, check out
> that will show the basic atomic counting code; otherwise I can mail you
> a copy
> I use these in my own smart/ref-count pointers and the overhead is minimal
> also, to keep the needed (assembly) code minimal, it should be checked
> what "most common platforms"
> provide for things like this
I agree in general. I can easily make MSVC generate the relevant
lock xadd [eax], edx
code by simply renaming 'InterlockedIncrement' to '_InterlockedIncrement',
which is an intrinsic. But I'm not sure what is the proper, compiler and
platform friendly way to achieve this in other cases.
Using the functions is portable to everything Win32 and is more efficient
than a generic mutex-protected implementation.
Consider the proposed implementation as a starting point that, I expect,
will be enhanced by others.
-- Peter Dimov Multi Media Ltd.
Boost list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk