aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Certner <olce@FreeBSD.org>2024-01-04 15:10:40 +0000
committerOlivier Certner <olce@FreeBSD.org>2024-01-09 13:29:25 +0000
commit4d312aa051414ad77d3515f258230d01ad11d6dc (patch)
tree820de5ecfd2b72a0eff309133aba9d494266c7d6
parent45486372ca8da6385bee3eaed2f0279c94db0476 (diff)
downloadsrc-4d312aa051414ad77d3515f258230d01ad11d6dc.tar.gz
src-4d312aa051414ad77d3515f258230d01ad11d6dc.zip
libthr: thr_attr.c: More style and clarity fixes
The change of argument for sizeof() (from a type to an object) is to be consistent with the change done for the malloc() code just above in the preceding commit touching this file. Consider bit flags as integers and test whether they are set with an explicit comparison with 0. Use an explicit flag value (PTHREAD_SCOPE_SYSTEM) in place of a variable that has this value at point of substitution. All other changes are straightforward. Suggested by: kib Reviewed by: kib Approved by: emaste (mentor) MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D43327
-rw-r--r--lib/libthr/thread/thr_attr.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/libthr/thread/thr_attr.c b/lib/libthr/thread/thr_attr.c
index 0ccc31b22c13..bbb143da1a7d 100644
--- a/lib/libthr/thread/thr_attr.c
+++ b/lib/libthr/thread/thr_attr.c
@@ -117,8 +117,7 @@ _thr_attr_destroy(pthread_attr_t *attr)
if (attr == NULL || *attr == NULL)
return (EINVAL);
- if ((*attr)->cpuset != NULL)
- free((*attr)->cpuset);
+ free((*attr)->cpuset);
free(*attr);
*attr = NULL;
return (0);
@@ -151,7 +150,7 @@ _thr_attr_get_np(pthread_t pthread, pthread_attr_t *dstattr)
return (error);
attr = pthread->attr;
- if (pthread->flags & THR_FLAGS_DETACHED)
+ if ((pthread->flags & THR_FLAGS_DETACHED) != 0)
attr.flags |= PTHREAD_DETACHED;
error = cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, TID(pthread),
@@ -180,7 +179,7 @@ _thr_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
if (attr == NULL || *attr == NULL || detachstate == NULL)
return (EINVAL);
- if ((*attr)->flags & PTHREAD_DETACHED)
+ if (((*attr)->flags & PTHREAD_DETACHED) != 0)
*detachstate = PTHREAD_CREATE_DETACHED;
else
*detachstate = PTHREAD_CREATE_JOINABLE;
@@ -258,7 +257,7 @@ _thr_attr_getscope(const pthread_attr_t * __restrict attr,
if (attr == NULL || *attr == NULL || contentionscope == NULL)
return (EINVAL);
- *contentionscope = (*attr)->flags & PTHREAD_SCOPE_SYSTEM ?
+ *contentionscope = ((*attr)->flags & PTHREAD_SCOPE_SYSTEM) != 0 ?
PTHREAD_SCOPE_SYSTEM : PTHREAD_SCOPE_PROCESS;
return (0);
}
@@ -321,7 +320,7 @@ _thr_attr_init(pthread_attr_t *attr)
if ((pattr = malloc(sizeof(*pattr))) == NULL)
return (ENOMEM);
- memcpy(pattr, &_pthread_attr_default, sizeof(struct pthread_attr));
+ memcpy(pattr, &_pthread_attr_default, sizeof(*pattr));
*attr = pattr;
return (0);
}
@@ -449,7 +448,7 @@ _thr_attr_setscope(pthread_attr_t *attr, int contentionscope)
return (EINVAL);
if (contentionscope == PTHREAD_SCOPE_SYSTEM)
- (*attr)->flags |= contentionscope;
+ (*attr)->flags |= PTHREAD_SCOPE_SYSTEM;
else
(*attr)->flags &= ~PTHREAD_SCOPE_SYSTEM;
return (0);
@@ -546,6 +545,7 @@ _pthread_attr_setaffinity_np(pthread_attr_t *pattr, size_t cpusetsize,
if (cpusetsize > kern_size) {
/* Kernel checks invalid bits, we check it here too. */
size_t i;
+
for (i = kern_size; i < cpusetsize; ++i)
if (((const char *)cpusetp)[i] != 0)
return (EINVAL);