Page MenuHomeFreeBSD

D60487.diff
No OneTemporary

D60487.diff

diff --git a/lib/libthr/libthr.3 b/lib/libthr/libthr.3
--- a/lib/libthr/libthr.3
+++ b/lib/libthr/libthr.3
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd October 1, 2021
+.Dd October 8, 2026
.Dt LIBTHR 3
.Os
.Sh NAME
@@ -199,7 +199,7 @@
The integer value of the variable specifies how often blocked
threads are inserted at the head of the sleep queue, instead of its tail.
Bigger values reduce the frequency of the FIFO discipline.
-The value must be between 0 and 255.
+The value must be between 0 and 31.
.It Dv LIBPTHREAD_UMTX_MIN_TIMEOUT
The minimal amount of time, in nanoseconds, the thread is required to sleep
for pthread operations specifying a timeout.
diff --git a/lib/libthr/thread/thr_init.c b/lib/libthr/thread/thr_init.c
--- a/lib/libthr/thread/thr_init.c
+++ b/lib/libthr/thread/thr_init.c
@@ -475,6 +475,30 @@
return (false);
}
+static bool
+getenv_int(const char *name, int mn, int mx, int *result)
+{
+ const char *env;
+ char *endptr;
+ long val;
+ int saved_errno;
+
+ env = getenv(name);
+ if (env == NULL || *env == '\0')
+ return (false);
+ /* atoi doesn't affect errno, emulate the behavior*/
+ saved_errno = errno;
+ errno = 0;
+ val = strtol(env, &endptr, 10);
+ if (*endptr != '\0' || errno != 0 || val < mn || val > mx) {
+ errno = saved_errno;
+ return (false);
+ }
+ errno = saved_errno;
+ *result = val;
+ return (true);
+}
+
static void
init_private(void)
{
@@ -519,15 +543,12 @@
_thr_guard_default = _thr_page_size;
_pthread_attr_default.guardsize_attr = _thr_guard_default;
_pthread_attr_default.stacksize_attr = _thr_stack_default;
- env = getenv("LIBPTHREAD_SPINLOOPS");
- if (env)
- _thr_spinloops = atoi(env);
- env = getenv("LIBPTHREAD_YIELDLOOPS");
- if (env)
- _thr_yieldloops = atoi(env);
- env = getenv("LIBPTHREAD_QUEUE_FIFO");
- if (env)
- _thr_queuefifo = atoi(env);
+ (void)getenv_int("LIBPTHREAD_SPINLOOPS", 0, INT_MAX,
+ &_thr_spinloops);
+ (void)getenv_int("LIBPTHREAD_YIELDLOOPS", 0, INT_MAX,
+ &_thr_yieldloops);
+ (void)getenv_int("LIBPTHREAD_QUEUE_FIFO", 0, 31,
+ &_thr_queuefifo);
env = getenv("LIBPTHREAD_UMTX_MIN_TIMEOUT");
if (env) {
char *endptr;

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 10, 12:44 AM (31 m, 9 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
40514820
Default Alt Text
D60487.diff (2 KB)

Event Timeline