RE: Assuming that TAS() will succeed the first time is verboten
От | Mikheev, Vadim |
---|---|
Тема | RE: Assuming that TAS() will succeed the first time is verboten |
Дата | |
Msg-id | 8F4C99C66D04D4118F580090272A7A234D321E@sectorbase1.sectorbase.com обсуждение исходный текст |
Ответ на | Assuming that TAS() will succeed the first time is verboten (Tom Lane <tgl@sss.pgh.pa.us>) |
Список | pgsql-hackers |
Ok. > -----Original Message----- > From: Tom Lane [mailto:tgl@sss.pgh.pa.us] > Sent: Thursday, December 28, 2000 2:07 PM > To: Mikheev, Vadim > Cc: pgsql-hackers@postgreSQL.org > Subject: Re: Assuming that TAS() will succeed the first time > is verboten > > > > "Mikheev, Vadim" <vmikheev@SECTORBASE.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 >
В списке pgsql-hackers по дате отправления: