diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2019-10-16 22:35:24 -0400 |
---|---|---|
committer | Eric Sandeen <sandeen@sandeen.net> | 2019-10-16 22:35:24 -0400 |
commit | 336c482472c2c65249b069d910c3255224b3a0d8 (patch) | |
tree | c0a8fc35b7cc3ef55e08900beccd6a5d5825921a | |
parent | cb321a3959a5a234e8d107966861ad36f68eee6a (diff) | |
download | xfsprogs-dev-336c482472c2c65249b069d910c3255224b3a0d8.tar.gz |
libfrog: add missing per-thread variable error handling
Add missing return value checks for everything that the per-thread
variable code calls.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
-rw-r--r-- | libfrog/ptvar.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/libfrog/ptvar.c b/libfrog/ptvar.c index b8e4d4f0e8..f375df3aec 100644 --- a/libfrog/ptvar.c +++ b/libfrog/ptvar.c @@ -44,8 +44,12 @@ ptvar_alloc( int ret; #ifdef _SC_LEVEL1_DCACHE_LINESIZE + long l1_dcache; + /* Try to prevent cache pingpong by aligning to cacheline size. */ - size = max(size, sysconf(_SC_LEVEL1_DCACHE_LINESIZE)); + l1_dcache = sysconf(_SC_LEVEL1_DCACHE_LINESIZE); + if (l1_dcache > 0) + size = roundup(size, l1_dcache); #endif ptv = malloc(PTVAR_SIZE(nr, size)); @@ -88,17 +92,26 @@ ptvar_get( int *retp) { void *p; + int ret; p = pthread_getspecific(ptv->key); if (!p) { pthread_mutex_lock(&ptv->lock); assert(ptv->nr_used < ptv->nr_counters); p = &ptv->data[(ptv->nr_used++) * ptv->data_size]; - pthread_setspecific(ptv->key, p); + ret = pthread_setspecific(ptv->key, p); + if (ret) + goto out_unlock; pthread_mutex_unlock(&ptv->lock); } *retp = 0; return p; + +out_unlock: + ptv->nr_used--; + pthread_mutex_unlock(&ptv->lock); + *retp = ret; + return NULL; } /* Iterate all of the per-thread variables. */ |