kernel - Fix lwp_tid ranging error
* We intended for lwp_tid's to range from 1..INT_MAX, but we
had the following code in the kernel and unfortunately GCC
optimizes out the conditional entirely.
if (++lp->lwp_tid <= 0)
lp->lwp_tid = 1;
* In addition, the pthreads library actually would like to use
a few high bits for flags, so fix the limit while we are
here to 0x3FFFFFFF. This saves us a pthreads assertion in
the mutex code if an application is actually able to wind
the thread id up this high over its life. Since the TID
allocation mechanism is pretty simplistic, it is entirely
possible to do this given heavy thread creation / deletion
rates and enough time.
* Change the conditional such that GCC does not optimize it out.
We do not want to depend on -fwrapv for the kernel code to
compile properly, so we don't use it.
if (lp->lwp_tid == 0 || lp->lwp_tid == 0x3FFFFFFF)
lp->lwp_tid = 1;
else
++lp->lwp_tid;
UnifiedSplitRaw