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

Tom Ivar Helbekkmo <tih@hamartun.priv.no>

From: Tom Ivar Helbekkmo <tih@Hamartun.Priv.NO>
To: dg@illustra.com (David Gould)
Cc: maillist@candle.pha.pa.us, scrappy@hub.org, dz@cs.unitn.it, hackers@postgreSQL.org
Date: 1998-03-31T21:20:40Z
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
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
-- 
Popularity is the hallmark of mediocrity.  --Niles Crane, "Frasier"