On Feb 7, 2013, at 11:00 AM, Marshall Clow <[email protected]> wrote:
> > On Feb 7, 2013, at 10:54 AM, Dave Zarzycki <[email protected]> > wrote: > >> Marshall, >> >> FYI — While safe in this specific example, this is not a correct transform >> to make in the general case. POSIX very clearly specifies that -1 is the >> error code for this and similar APIs. This matters for APIs like mmap() >> which can return "negative" values that not an error. > > I understand, and this was not meant to be a general solution. > > But, if by some weird circumstances we get handed a negative number of cores, > we want to return a "not insane" value like 2^32-2. Let me try that again - we want to NOT return an insane value like 2^32 -2. The rationale behind this case was that we have to return a non-negative # - we can't just blindly pass back the return value from sysconf. -- Marshall >> On Feb 7, 2013, at 1:48 PM, Marshall Clow <[email protected]> wrote: >> >>> Author: marshall >>> Date: Thu Feb 7 12:48:09 2013 >>> New Revision: 174642 >>> >>> URL: http://llvm.org/viewvc/llvm-project?rev=174642&view=rev >>> Log: >>> Belt and suspenders when calling sysconf >>> >>> Modified: >>> libcxx/trunk/src/thread.cpp >>> >>> Modified: libcxx/trunk/src/thread.cpp >>> URL: >>> http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.cpp?rev=174642&r1=174641&r2=174642&view=diff >>> ============================================================================== >>> --- libcxx/trunk/src/thread.cpp (original) >>> +++ libcxx/trunk/src/thread.cpp Thu Feb 7 12:48:09 2013 >>> @@ -69,7 +69,9 @@ thread::hardware_concurrency() _NOEXCEPT >>> long result = sysconf(_SC_NPROCESSORS_ONLN); >>> // sysconf returns -1 if the name is invalid, the option does not exist or >>> // does not have a definite limit. >>> - if (result == -1) >>> + // if sysconf returns some other negative number, we have no idea >>> + // what is going on. Default to something safe. >>> + if (result < 0) >>> return 0; >>> return static_cast<unsigned>(result); >>> #else // defined(CTL_HW) && defined(HW_NCPU) >>> >>> >>> _______________________________________________ >>> cfe-commits mailing list >>> [email protected] >>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits >> > -- Marshall Marshall Clow Idio Software <mailto:[email protected]> A.D. 1517: Martin Luther nails his 95 Theses to the church door and is promptly moderated down to (-1, Flamebait). -- Yu Suzuki _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
