diff options
author | Florian Weimer <fweimer@redhat.com> | 2020-06-02 10:33:30 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-06-02 11:54:58 +0200 |
commit | 7538d461134bf306e31b40e4032f0c225bb40d51 (patch) | |
tree | 34c4ceb7c6565864dfc62d8e23dd8f37e24944af /sysdeps | |
parent | 6993670b52daa413717e840dfb17b5322e7f4a88 (diff) | |
download | glibc-7538d461134bf306e31b40e4032f0c225bb40d51.tar glibc-7538d461134bf306e31b40e4032f0c225bb40d51.tar.gz glibc-7538d461134bf306e31b40e4032f0c225bb40d51.tar.bz2 glibc-7538d461134bf306e31b40e4032f0c225bb40d51.zip |
nptl: Make pthread_attr_t dynamically extensible
This introduces the function __pthread_attr_extension to allocate the
extension space, which is freed by pthread_attr_destroy.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/nptl/internaltypes.h | 16 | ||||
-rw-r--r-- | sysdeps/unix/sysv/linux/createthread.c | 9 |
2 files changed, 19 insertions, 6 deletions
diff --git a/sysdeps/nptl/internaltypes.h b/sysdeps/nptl/internaltypes.h index 6d06a76baf..ca57c315d4 100644 --- a/sysdeps/nptl/internaltypes.h +++ b/sysdeps/nptl/internaltypes.h @@ -36,9 +36,10 @@ struct pthread_attr /* Stack handling. */ void *stackaddr; size_t stacksize; - /* Affinity map. */ - cpu_set_t *cpuset; - size_t cpusetsize; + + /* Allocated via a call to __pthread_attr_extension once needed. */ + struct pthread_attr_extension *extension; + void *unused; }; #define ATTR_FLAG_DETACHSTATE 0x0001 @@ -57,6 +58,15 @@ union pthread_attr_transparent struct pthread_attr internal; }; +/* Extension space for pthread attributes. Referenced by the + extension member of struct pthread_attr. */ +struct pthread_attr_extension +{ + /* Affinity map. */ + cpu_set_t *cpuset; + size_t cpusetsize; +}; + /* Mutex attribute data structure. */ struct pthread_mutexattr { diff --git a/sysdeps/unix/sysv/linux/createthread.c b/sysdeps/unix/sysv/linux/createthread.c index 21f9d24f2d..6588893ba5 100644 --- a/sysdeps/unix/sysv/linux/createthread.c +++ b/sysdeps/unix/sysv/linux/createthread.c @@ -52,8 +52,10 @@ create_thread (struct pthread *pd, const struct pthread_attr *attr, /* Determine whether the newly created threads has to be started stopped since we have to set the scheduling parameters or set the affinity. */ + bool need_setaffinity = (attr != NULL && attr->extension != NULL + && attr->extension->cpuset != 0); if (attr != NULL - && (__glibc_unlikely (attr->cpuset != NULL) + && (__glibc_unlikely (need_setaffinity) || __glibc_unlikely ((attr->flags & ATTR_FLAG_NOTINHERITSCHED) != 0))) *stopped_start = true; @@ -113,12 +115,13 @@ create_thread (struct pthread *pd, const struct pthread_attr *attr, int res; /* Set the affinity mask if necessary. */ - if (attr->cpuset != NULL) + if (need_setaffinity) { assert (*stopped_start); res = INTERNAL_SYSCALL_CALL (sched_setaffinity, pd->tid, - attr->cpusetsize, attr->cpuset); + attr->extension->cpusetsize, + attr->extension->cpuset); if (__glibc_unlikely (INTERNAL_SYSCALL_ERROR_P (res))) err_out: |