Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Jan 2024 13:30:18 GMT
From:      Olivier Certner <olce@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 4d312aa05141 - main - libthr: thr_attr.c: More style and clarity fixes
Message-ID:  <202401091330.409DUIbv035748@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by olce:

URL: https://cgit.FreeBSD.org/src/commit/?id=4d312aa051414ad77d3515f258230d01ad11d6dc

commit 4d312aa051414ad77d3515f258230d01ad11d6dc
Author:     Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2024-01-04 15:10:40 +0000
Commit:     Olivier Certner <olce@FreeBSD.org>
CommitDate: 2024-01-09 13:29:25 +0000

    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
---
 lib/libthr/thread/thr_attr.c | 14 +++++++-------
 1 file 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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401091330.409DUIbv035748>