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

From: Tom Ivar Helbekkmo <tih(at)Hamartun(dot)Priv(dot)NO>
To: dg(at)illustra(dot)com (David Gould)
Cc: maillist(at)candle(dot)pha(dot)pa(dot)us, scrappy(at)hub(dot)org, dz(at)cs(dot)unitn(dot)it, hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] Re: [PATCHES] patches for 6.2.1p6
Date: 1998-03-31 21:20:40
Message-ID: 86ra3iblqv.fsf@barsoom.Hamartun.Priv.NO
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
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"

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1998-03-31 21:54:08 Re: [PORTS] Port Bug Report: int2 negative numbers not parsed correctly
Previous Message Bruce Momjian 1998-03-31 16:42:45 Re: [HACKERS] StrNCpy