Message ID | 97d4eaaccdee458f469942064acb202b09a82df4.1589884403.git.fweimer@redhat.com |
---|---|
State | Committed |
Headers | show |
Series | Signal mask for timer helper thread | expand |
On 5/19/20 6:44 AM, Florian Weimer via Libc-alpha wrote: > This avoids duplicating the code for the affinity mask allocation > handling. OK for master. Reviewed-by: Carlos O'Donell <carlos@redhat.com> > --- > nptl/pthread_getattr_np.c | 30 ++++++++++++++---------------- > 1 file changed, 14 insertions(+), 16 deletions(-) > > diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c > index 0e8911346d..ce437205e4 100644 > --- a/nptl/pthread_getattr_np.c > +++ b/nptl/pthread_getattr_np.c > @@ -33,8 +33,13 @@ int > __pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr) > { > struct pthread *thread = (struct pthread *) thread_id; > + > + /* Prepare the new thread attribute. */ > + int ret = __pthread_attr_init (attr); > + if (ret != 0) > + return ret; > + OK. > struct pthread_attr *iattr = (struct pthread_attr *) attr; > - int ret = 0; > > lll_lock (thread->lock, LLL_PRIVATE); > > @@ -187,25 +192,18 @@ __pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr) > while (ret == EINVAL && size < 1024 * 1024); > > if (ret == 0) > - { > - iattr->cpuset = cpuset; > - iattr->cpusetsize = size; > - } > - else > - { > - free (cpuset); > - if (ret == ENOSYS) > - { > - /* There is no such functionality. */ > - ret = 0; > - iattr->cpuset = NULL; > - iattr->cpusetsize = 0; > - } > - } > + ret = __pthread_attr_setaffinity_np (attr, size, cpuset); OK. Handled all in pthread_attr_setaffinity_np. > + else if (ret == ENOSYS) > + /* There is no such functionality. */ > + ret = 0; > + free (cpuset); OK. > } > > lll_unlock (thread->lock, LLL_PRIVATE); > > + if (ret != 0) > + __pthread_attr_destroy (attr); OK. Destory the attribute if things failed. > + > return ret; > } > versioned_symbol (libc, __pthread_getattr_np, pthread_getattr_np, GLIBC_2_32); >
diff --git a/nptl/pthread_getattr_np.c b/nptl/pthread_getattr_np.c index 0e8911346d..ce437205e4 100644 --- a/nptl/pthread_getattr_np.c +++ b/nptl/pthread_getattr_np.c @@ -33,8 +33,13 @@ int __pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr) { struct pthread *thread = (struct pthread *) thread_id; + + /* Prepare the new thread attribute. */ + int ret = __pthread_attr_init (attr); + if (ret != 0) + return ret; + struct pthread_attr *iattr = (struct pthread_attr *) attr; - int ret = 0; lll_lock (thread->lock, LLL_PRIVATE); @@ -187,25 +192,18 @@ __pthread_getattr_np (pthread_t thread_id, pthread_attr_t *attr) while (ret == EINVAL && size < 1024 * 1024); if (ret == 0) - { - iattr->cpuset = cpuset; - iattr->cpusetsize = size; - } - else - { - free (cpuset); - if (ret == ENOSYS) - { - /* There is no such functionality. */ - ret = 0; - iattr->cpuset = NULL; - iattr->cpusetsize = 0; - } - } + ret = __pthread_attr_setaffinity_np (attr, size, cpuset); + else if (ret == ENOSYS) + /* There is no such functionality. */ + ret = 0; + free (cpuset); } lll_unlock (thread->lock, LLL_PRIVATE); + if (ret != 0) + __pthread_attr_destroy (attr); + return ret; } versioned_symbol (libc, __pthread_getattr_np, pthread_getattr_np, GLIBC_2_32);