From: Ondřej Surý Date: Sat, 17 Mar 2018 19:59:19 +0000 (+0000) Subject: Unwrap isc_refcount_t from struct isc_refcount as it is always a simple type now X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=158986c5e9ad5e17c17aa8b85e7ea887ae8b195b;p=thirdparty%2Fbind9.git Unwrap isc_refcount_t from struct isc_refcount as it is always a simple type now --- diff --git a/lib/isc/Makefile.in b/lib/isc/Makefile.in index 9c1465fe78c..68cf71c0533 100644 --- a/lib/isc/Makefile.in +++ b/lib/isc/Makefile.in @@ -57,7 +57,7 @@ OBJS = @ISC_EXTRA_OBJS@ @ISC_PK11_O@ @ISC_PK11_RESULT_O@ \ md5.@O@ mem.@O@ mutexblock.@O@ \ netaddr.@O@ netscope.@O@ pool.@O@ \ parseint.@O@ portset.@O@ quota.@O@ radix.@O@ random.@O@ \ - ratelimiter.@O@ refcount.@O@ region.@O@ regex.@O@ result.@O@ \ + ratelimiter.@O@ region.@O@ regex.@O@ result.@O@ \ rwlock.@O@ \ safe.@O@ serial.@O@ sha1.@O@ sha2.@O@ sockaddr.@O@ stats.@O@ \ string.@O@ strtoul.@O@ symtab.@O@ task.@O@ taskpool.@O@ \ @@ -75,7 +75,7 @@ SRCS = @ISC_EXTRA_SRCS@ @ISC_PK11_C@ @ISC_PK11_RESULT_C@ \ md5.c mem.c mutexblock.c \ netaddr.c netscope.c pool.c \ parseint.c portset.c quota.c radix.c random.c \ - ratelimiter.c refcount.c region.c regex.c result.c rwlock.c \ + ratelimiter.c region.c regex.c result.c rwlock.c \ safe.c serial.c sha1.c sha2.c sockaddr.c stats.c string.c \ strtoul.c symtab.c task.c taskpool.c timer.c \ tm.c version.c diff --git a/lib/isc/include/isc/refcount.h b/lib/isc/include/isc/refcount.h index e0df1c82aea..4ff05c91645 100644 --- a/lib/isc/include/isc/refcount.h +++ b/lib/isc/include/isc/refcount.h @@ -91,42 +91,40 @@ ISC_LANG_BEGINDECLS */ #ifdef ISC_PLATFORM_USETHREADS -typedef struct isc_refcount { - atomic_int_fast32_t refs; -} isc_refcount_t; +typedef atomic_int_fast32_t isc_refcount_t; -#define isc_refcount_current(rp) \ - ((unsigned int)(atomic_load_explicit(&(rp)->refs, \ +#define isc_refcount_current(ref) \ + ((unsigned int)(atomic_load_explicit(ref, \ memory_order_relaxed))) -#define isc_refcount_destroy(rp) ISC_REQUIRE(isc_refcount_current(rp) == 0) +#define isc_refcount_destroy(ref) ISC_REQUIRE(isc_refcount_current(ref) == 0) -#define isc_refcount_increment0(rp, tp) \ +#define isc_refcount_increment0(ref, tp) \ do { \ unsigned int *_tmp = (unsigned int *)(tp); \ isc_int32_t prev; \ prev = atomic_fetch_add_explicit \ - (&(rp)->refs, 1, memory_order_relaxed); \ + (ref, 1, memory_order_relaxed); \ if (_tmp != NULL) \ *_tmp = prev + 1; \ } while (0) -#define isc_refcount_increment(rp, tp) \ +#define isc_refcount_increment(ref, tp) \ do { \ unsigned int *_tmp = (unsigned int *)(tp); \ isc_int32_t prev; \ prev = atomic_fetch_add_explicit \ - (&(rp)->refs, 1, memory_order_relaxed); \ + (ref, 1, memory_order_relaxed); \ ISC_REQUIRE(prev > 0); \ if (_tmp != NULL) \ *_tmp = prev + 1; \ } while (0) -#define isc_refcount_decrement(rp, tp) \ +#define isc_refcount_decrement(ref, tp) \ do { \ unsigned int *_tmp = (unsigned int *)(tp); \ isc_int32_t prev; \ prev = atomic_fetch_sub_explicit \ - (&(rp)->refs, 1, memory_order_relaxed); \ + (ref, 1, memory_order_relaxed); \ ISC_REQUIRE(prev > 0); \ if (_tmp != NULL) \ *_tmp = prev - 1; \ @@ -138,41 +136,46 @@ typedef struct isc_refcount { int refs; } isc_refcount_t; -#define isc_refcount_destroy(rp) ISC_REQUIRE((rp)->refs == 0) -#define isc_refcount_current(rp) ((unsigned int)((rp)->refs)) +#define isc_refcount_destroy(ref) ISC_REQUIRE(ref == 0) +#define isc_refcount_current(ref) ((unsigned int)(ref) -#define isc_refcount_increment0(rp, tp) \ +#define isc_refcount_increment0(ref, tp) \ do { \ unsigned int *_tmp = (unsigned int *)(tp); \ - int _n = ++(rp)->refs; \ + int _n = ++ref; \ if (_tmp != NULL) \ *_tmp = _n; \ } while (0) -#define isc_refcount_increment(rp, tp) \ +#define isc_refcount_increment(ref, tp) \ do { \ unsigned int *_tmp = (unsigned int *)(tp); \ int _n; \ - ISC_REQUIRE((rp)->refs > 0); \ - _n = ++(rp)->refs; \ + ISC_REQUIRE(ref > 0); \ + _n = ++ref; \ if (_tmp != NULL) \ *_tmp = _n; \ } while (0) -#define isc_refcount_decrement(rp, tp) \ +#define isc_refcount_decrement(ref, tp) \ do { \ unsigned int *_tmp = (unsigned int *)(tp); \ int _n; \ - ISC_REQUIRE((rp)->refs > 0); \ - _n = --(rp)->refs; \ + ISC_REQUIRE((ref) > 0); \ + _n = --ref; \ if (_tmp != NULL) \ *_tmp = _n; \ } while (0) #endif /* ISC_PLATFORM_USETHREADS */ +static inline isc_result_t -isc_refcount_init(isc_refcount_t *ref, unsigned int n); +isc_refcount_init(isc_refcount_t *ref, isc_refcount_t n) { + ISC_REQUIRE(ref); + *ref = n; + return (ISC_R_SUCCESS); +} ISC_LANG_ENDDECLS diff --git a/lib/isc/refcount.c b/lib/isc/refcount.c deleted file mode 100644 index 0adc447e0d1..00000000000 --- a/lib/isc/refcount.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) Internet Systems Consortium, Inc. ("ISC") - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * See the COPYRIGHT file distributed with this work for additional - * information regarding copyright ownership. - */ - - -#include - -#include - -#include -#include -#include -#include - -isc_result_t -isc_refcount_init(isc_refcount_t *ref, unsigned int n) { - REQUIRE(ref != NULL); - - ref->refs = n; - return (ISC_R_SUCCESS); -}