From 82b145efab6c431d9014ad6f9a888b5d1f6d5b2b Mon Sep 17 00:00:00 2001 From: Morgan Douglas Date: Fri, 18 Oct 2024 13:56:21 -0400 Subject: [PATCH] Put min() in utils Signed-off-by: Morgan Douglas --- db/eventlog.c | 2 +- util/math_util.h | 25 +++++++++++++++++++++++++ util/object_pool.c | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 util/math_util.h diff --git a/db/eventlog.c b/db/eventlog.c index a91af933f0..f8edfcb4b8 100644 --- a/db/eventlog.c +++ b/db/eventlog.c @@ -38,6 +38,7 @@ #include "logmsg.h" #include "thread_stats.h" #include "dbinc/locker_info.h" +#include "math_util.h" /* min */ #include "cson.h" #include "comdb2_atomic.h" @@ -64,7 +65,6 @@ static int64_t eventlog_count = 0; static int eventlog_debug_events = 0; static void eventlog_roll(void); -#define min(x, y) ((x) < (y) ? (x) : (y)) struct sqltrack { char fingerprint[FINGERPRINTSZ]; diff --git a/util/math_util.h b/util/math_util.h new file mode 100644 index 0000000000..14dae90091 --- /dev/null +++ b/util/math_util.h @@ -0,0 +1,25 @@ +/* + Copyright 2024 Bloomberg Finance L.P. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#ifndef __MATH_UTIL_H__ +#define __MATH_UTIL_H__ + + #define min(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) + +#endif diff --git a/util/object_pool.c b/util/object_pool.c index e26d808a81..1e582ca9e5 100644 --- a/util/object_pool.c +++ b/util/object_pool.c @@ -29,13 +29,13 @@ #include "object_pool.h" #include "logmsg.h" #include "sys_wrap.h" +#include "math_util.h" /* min */ #include #include // macros //#define OBJ_POOL_DEBUG -#define min(x, y) ((x) < (y) ? (x) : (y)) #define full(op) ((op)->nobjs == (op)->capacity) #define empty(op) ((op)->nobjs == 0) #define exhausted(op) ((op)->nactiveobjs == (op)->nobjs)