This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Atomic operations


Mark Kettenis <kettenis@wins.uva.nl> writes:

> At the end of this message you'll find how these operations can be
> implemented for the i386.  The idea is that the `if'-statements will
> all be optimized away.  The only `problem' is the fact that the lock
> will always be present, even if it is not used.  I would be interested
> in a way to eleminate the lock when possible.  However, I don't think
> wasting a few bytes is going tobe a big problem.

It's an interesting concept.  But I don't think we have to be that
general.  Why should be allow atomic objects of other than the natual
sizes?  The only possible motivation is size but then, with the
spinlock, this is more than nullified (on platforms which don't need
them).

I think defining types atomic_t and uatomic_t (latter is unsigned)
which are guaranteed to have at least 32 bits should be enough.  Do
you know about situations where this is not the case?

The only problem I could see is that you want to have longer types
also on 32bit platforms.  Then I'd suggest

	atomic_least32_t
	uatomic_least32_t
	atomic_least64_t
	uatomic_least64_t

Of course we need then something like your macros since modifying the
64 bit object does not work without it on a 32 bit platform.  Maybe we
can even define atomic_least8_t etc and on platforms like x86 we can
define these with the minimal amount of bits.  So maybe:


#define atomic_object(class, name, size, oper) \
  atomic_object_##oper (class, name, size)

#define atomic_object_INC(class, name, size) \
  class int##size##_t name

#define atomic_object_DEC(class, name, size) \
  class int##size##_t name

#define atomic_object_INC_DEC(class, name, size) \
  class int##size##_t name

#define atomic_object_XADD(class, name, size) \
  class int##size##_t name; \
  __libc_lock_define_initialized (class, __atomic_lock_##name)

#define atomic_object_INC_XADD(class, name, size) \
  class int##size##_t name; \
  __libc_lock_define_initialized (class, __atomic_lock_##name)


The `oper' parameter to atomic_object would then have to be one of

			XADD		CMPX		XADD_CMPX
	INC		INC_XADD	INC_CMPX	INC_XADD_CMPX
	DEC		DEC_XADD	DEC_CMPX	DEC_XADD_CMPX
	INC_DEC		INC_DEC_XADD	INC_DEC_CMPX	INC_DEC_XADD_CMPX


Which shouldn't be too bad.


>     __asm__ __volatile__ ("lock; incl %0" : : "m" (NAME) : "memory")

This does not work.  `lock' only works on

	bt, bts, btr, btc, xchg, add, adc, and


-- 
---------------.      drepper at gnu.org  ,-.   1325 Chesapeake Terrace
Ulrich Drepper  \    ,-------------------'   \  Sunnyvale, CA 94089 USA
Cygnus Solutions `--' drepper at cygnus.com   `------------------------

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]