Re: [HACKERS] Re: [PATCHES] patches for 6.2.1p6

David Gould <dg@illustra.com>

From: dg@illustra.com (David Gould)
To: tih@Hamartun.Priv.NO (Tom Ivar Helbekkmo)
Cc: maillist@candle.pha.pa.us, scrappy@hub.org, dz@cs.unitn.it, pgsql-hackers@postgreSQL.org
Date: 1998-04-01T19:56:56Z
Lists: pgsql-hackers
> David Gould wrote:
> 
> >Seriously, if you want to, please create a function to emulate the following:
> > 
> > /*
> >  * tas(lock)
> >  *
> >  * Access to platform specific test_and_set functionality. Given pointer to
> >  * lock attempts to acquire the lock atomically.
> >  *
> >  * Returns 0 for success, nonzero for failure.
> >  */
> > typedef slock_t unsigned char;		/* or whatever works on the platform */
> > 
> > int tas(slock_t *lock)
> > {
> >     slock_t	tmp;
> > 
> >     /* atomic, interlocked */
> >     tmp = *lock;
> >     *lock = -1; 			/* any nonzero will do here */
> > 
> >     return (tmp != 0);
> > }
> > 
> > Given this, I can fold the VAX right into the grand scheme, just like a
> > normal computer (;-)).
> 
> Hmpf!  The true worth of a computer is a function of its weight!  :-)
> 
> Sorry this took a while, but anyway, this should do it for the VAX (in
> fact, it's more or less the version of the code that I figured I'd use
> until Bruce asked me to bum it down maximally for performance, only
> now with the return values from tas() swapped).  I include the macros

What do you mean "now with the return values from tas() swapped"? I think
your code looks ok, but just want to be sure we are following the same
grand plan...

> that would fit the current (6.3) locking scheme:
> 
> typedef unsigned char slock_t;
> 
> int tas(slock_t *lock) {
> 	register ret;
> 
> asm("	movl $1, r0
> 	bbssi $0,(%1),1f
> 	clrl r0
> 1:	movl r0,%0"
> 	: "=r"(ret)	/* return value, in register */
> 	: "r"(lock)	/* argument, 'lock pointer', in register */
> 	: "r0");	/* inline code uses this register */
> 
> 	return ret;
> }
> 
> #define	S_LOCK(addr)		do { while (tas(addr)) ; } while (0)
> #define	S_UNLOCK(addr)		(*(addr) = 0)
> #define	S_INIT_LOCK(addr)	(*(addr) = 0)
> 
> -tih
> -- 

Thanks, this is just what I was looking for. I will fold it in to my changes.
I have gotten a little snowed under with other tasks, but I expect to finalize
my patch next week and will post it.

-dg

David Gould            dg@illustra.com           510.628.3783 or 510.305.9468 
Informix Software  (No, really)         300 Lakeside Drive  Oakland, CA 94612
 - Linux. Not because it is free. Because it is better.