ImageCache: improve file handle limits under heavy thread contention. (#3515)
ImageCache: improve file handle limits under heavy thread contention. (#3515)

When enforcing the max open files limit, there's a heuristic where we
only "try" to get the lock, and if we can't, rather than block, we
just defer the cleanup step until the next time around. So what if we
go slightly over the limit temporarily?

Interesting edge case: what if max_open_files is relatively low, but
the number of threads is very high and you have a high contention rate?

Then you can end up *significantly* over the limit, because almost all
the threads say "somebody else has the lock, I'll leave it to them to
clean up" and blithely open new handles.

So this patch modifies the logic so we do the defer trick only if
we're only a little over the limit. If we've exceeded the limit by
16 handles, grab the lock unconditionally and do the cleanup.
OpenImageIO/oiio,OpenImageIO/oiio,lgritz/oiio,OpenImageIO/oiio,lgritz/oiio,OpenImageIO/oiio,lgritz/oiio,lgritz/oiio