> rbb 01/08/31 22:10:23 > > Modified: include/arch/win32 threadproc.h > threadproc/win32 thread.c > Log: > Implement apr_thread_once for Windows. > > +APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control, > + void (*func)(void)) > +{ > + InterlockedIncrement(&control->value); > + if (control->value == 1) { > + func(); > + } > + return APR_SUCCESS; > +}
This looks like a possible bug - control->value -could- someday wrap (especially if it wasn't called once per thread, but once per some operation!) What if we if (control->value) return APR_SUCCESS; first, which will start null, so several folks might fall in (incrementing to perhaps 2, possibly 10, doubtfully 100). But everyone hitting that line afterwards gets a fast escape, we're assured it was done without the kernel call and without the chance for wrapping.