From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Mikheev, Vadim" <vmikheev(at)SECTORBASE(dot)COM> |
Cc: | pgsql-hackers(at)postgreSQL(dot)org |
Subject: | Re: Assuming that TAS() will succeed the first time is verboten |
Date: | 2000-12-28 22:06:55 |
Message-ID: | 6185.978041215@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
"Mikheev, Vadim" <vmikheev(at)SECTORBASE(dot)COM> writes:
> Anyway I don't object if it bothers you -:)
> But please do not use S_LOCK - as you see WAL code try to do other
> things if slock of "primary interest" is busy.
In some places, yes. But I also saw a number of places where S_LOCK is
sufficient, and I think it's clearer to code that way whenever there's
not useful work to do before acquiring the lock. For example, is
if (updrqst)
{
unsigned i = 0;
for (;;)
{
if (!TAS(&(XLogCtl->info_lck)))
{
if (XLByteLT(XLogCtl->LgwrRqst.Write, LgwrRqst.Write))
XLogCtl->LgwrRqst.Write = LgwrRqst.Write;
S_UNLOCK(&(XLogCtl->info_lck));
break;
}
s_lock_sleep(i++);
}
}
really better than
if (updrqst)
{
S_LOCK(&(XLogCtl->info_lck));
if (XLByteLT(XLogCtl->LgwrRqst.Write, LgwrRqst.Write))
XLogCtl->LgwrRqst.Write = LgwrRqst.Write;
S_UNLOCK(&(XLogCtl->info_lck));
}
? I don't think so...
What I'm thinking of doing for the places where there is useful work
to do while waiting is
spins = 0;
while (TAS(lock))
{
/* do useful work here */
S_LOCK_SLEEP(spins++);
}
where S_LOCK_SLEEP() expands to do the same things as the body of the
existing loop in s_lock().
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Mikheev, Vadim | 2000-12-28 22:11:46 | RE: Assuming that TAS() will succeed the first time is verboten |
Previous Message | Mikheev, Vadim | 2000-12-28 21:56:39 | RE: Assuming that TAS() will succeed the first time is verboten |