Re: Code review request: small optimization to localtime.c
- From: Daniel Eischen <deischen@xxxxxxxxxxx>
- Date: Wed, 28 Nov 2007 17:19:42 -0500 (EST)
On Wed, 28 Nov 2007, M. Warner Losh wrote:
Please find enclosed some small optimizations. I know they make a
couple lines too long, I'll correct that before I commit. They make
the time functions do less redundant locking.
However, in many places we do the following:
pthread_mutex_lock();
if (!is_set) {
is_set = true;
// do something
}
pthread_mutex_unlock();
This is wasteful. We get locks ALL the time for every time operation,
when in fact we need it more rarely. If we can tolerate losing a
race, we can eliminate the locking in all but the startup case and
those threads racing the startup:
if (!is_set) {
pthread_mutex_lock();
if (!is_set) {
is_set = true;
// do something
}
pthread_mutex_unlock();
}
here, we know that is_set only ever changes from false to true. If it
is already true, there's nothing to do. If it is false, we may need
to do something, so we lock, check to see if we really need to do it,
etc.
Can anybody see a flaw in this logic?
Is this not a good place to use pthread_once() instead?
--
DE
_______________________________________________
freebsd-arch@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-arch
To unsubscribe, send any mail to "freebsd-arch-unsubscribe@xxxxxxxxxxx"
- References:
- Code review request: small optimization to localtime.c
- From: M. Warner Losh
- Code review request: small optimization to localtime.c
- Prev by Date: Re: RFC: libkse*.a in 7.0
- Next by Date: Re: RFC: libkse*.a in 7.0
- Previous by thread: Re: Code review request: small optimization to localtime.c
- Next by thread: Re: Code review request: small optimization to localtime.c
- Index(es):
Relevant Pages
- Re: Code review request: small optimization to localtime.c
... We get locks ALL the time for every time operation, ... those threads racing
the startup: ... struct tm *p_tm; ... #ifdef ALL_STATE ...
(freebsd-arch) - WMP crashes and gives CooD11CD error message
... After I rip a CD into WMA format, WMP crashes - locks up whole system. ... shut
down then startup - reboot doesn't fix it. ... (microsoft.public.windowsmedia.player) - Re: [PATCHSET #master] sysfs: make sysfs disconnect immediately on deletion, take 2
... I get the following on startup: ... [BUG: bad unlock balance detected!
... no locks held by start_udev/197. ... More majordomo info at http://vger.kernel.org/majordomo-info.html
... (Linux-Kernel) - Windows XP Urgent Help needed
... During startup it gives me an error of "C0000218 registry file corrupt or missing
... it then locks up. ... (microsoft.public.windows.inetexplorer.ie6.browser)