Page MenuHomeFreeBSD

D60487.1794689279.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D60487.1794689279.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,24 @@
return (false);
}
+static bool
+getenv_int(const char *name, int mn, int mx, int *result)
+{
+ const char *env;
+ char *endptr;
+ long val;
+
+ env = getenv(name);
+ if (env == NULL || *env == '\0')
+ return (false);
+ val = strtol(env, &endptr, 10);
+ if (*endptr != '\0' || errno != 0 || val < mn || val > mx) {
+ return (false);
+ }
+ *result = val;
+ return (true);
+}
+
static void
init_private(void)
{
@@ -519,15 +537,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, Nov 14, 8:47 PM (15 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41731993
Default Alt Text
D60487.1794689279.diff (2 KB)

Event Timeline