Boost logo

Boost :

From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2007-10-19 14:06:20


Peter Dimov escribió:
> Ion Gaztañaga:
>> Peter Dimov escribió:
>>> Last I looked at the various implementations, most of the routines did
>>> not
>>> provide these guarantees, though.
>> Willing to help on these implementations? We also need to write our own
>> versions to avoid license issues with the original Apache implementation
>> (basically we need our implementation of gcc Intel & PowerPC asm
>> versions).
>
> There are various sp_counted_base implementations in boost/detail that can
> be used as a starting point. But if you want help for the implementation,
> you need to specify an interface first. I'm not particularly fond of
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2393.html
>
> preferring something along the lines of
>
> http://open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2195.html

I basically need to write (some) functions described here:

http://svn.boost.org/trac/boost/browser/trunk/boost/interprocess/detail/atomic.hpp

Not all functions are necessary (some are not used, so I'm going to
remove them). Full barrier semantics would be a safe bet for a
non-expert like me, although I'm not sure if they should be applied to
atomic_read or atomic_write:

//! Atomically increment an apr_uint32_t by 1
//! "mem": pointer to the object
//! Returns the old value pointed to by mem
inline boost::uint32_t atomic_inc32(volatile boost::uint32_t *mem);

//! Atomically decrement an boost::uint32_t by 1
//! "mem": pointer to the atomic value
//! Returns false if the value becomes zero on decrement, otherwise true
inline bool atomic_dec32(volatile boost::uint32_t *mem);

//! Atomically read an boost::uint32_t from memory
inline boost::uint32_t atomic_read32(volatile boost::uint32_t *mem);
//! Atomically set an boost::uint32_t in memory
//! "mem": pointer to the object
//! "param": val value that the object will assume
inline void atomic_write32(volatile boost::uint32_t *mem,
                            boost::uint32_t val);

//! Compare an boost::uint32_t's value with "cmp".
//! If they are the same swap the value with "with"
//! "mem": pointer to the value
//! "with": what to swap it with
//! "cmp": the value to compare it to
//! Returns the old value of *mem
inline boost::uint32_t atomic_cas32
    (volatile boost::uint32_t *mem,
     boost::uint32_t with, boost::uint32_t cmp);

> but no matter what (if any) style you choose to follow, you need to be
> explicit about the constraints. At the very least, the functions should
> contain the constraint as a suffix, i.e. atomic_add_acqrel instead of
> atomic_add.

If you prefer to change the names, there is no problem. This is an
internal header. Maybe it's better to place them somewhere in
boost/detail if someone wants to reuse them, but I think that would
require a review.

Regards,

Ion


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk