Skip to content

Commit b487769

Browse files
committed
add utils_min/max functions
1 parent 50842f8 commit b487769

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/pool/pool_disjoint.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ class DisjointPool::AllocImpl {
180180
// Powers of 2 and the value halfway between the powers of 2.
181181
auto Size1 = this->params.MinBucketSize;
182182
// MinBucketSize cannot be larger than CutOff.
183-
Size1 = std::min(Size1, CutOff);
183+
Size1 = utils_min(Size1, CutOff);
184184
// Buckets sized smaller than the bucket default size- 8 aren't needed.
185-
Size1 = std::max(Size1, UMF_DISJOINT_POOL_MIN_BUCKET_DEFAULT_SIZE);
185+
Size1 = utils_max(Size1, UMF_DISJOINT_POOL_MIN_BUCKET_DEFAULT_SIZE);
186186
// Calculate the exponent for MinBucketSize used for finding buckets.
187187
MinBucketSizeExp = (size_t)log2Utils(Size1);
188188
auto Size2 = Size1 + Size1 / 2;
@@ -387,11 +387,13 @@ void bucket_update_stats(bucket_t *bucket, int InUse, int InPool) {
387387
return;
388388
}
389389
bucket->currSlabsInUse += InUse;
390+
390391
bucket->maxSlabsInUse =
391-
std::max(bucket->currSlabsInUse, bucket->maxSlabsInUse);
392+
utils_max(bucket->currSlabsInUse, bucket->maxSlabsInUse);
392393
bucket->currSlabsInPool += InPool;
393394
bucket->maxSlabsInPool =
394-
std::max(bucket->currSlabsInPool, bucket->maxSlabsInPool);
395+
utils_max(bucket->currSlabsInPool, bucket->maxSlabsInPool);
396+
395397
// Increment or decrement current pool sizes based on whether
396398
// slab was added to or removed from pool.
397399
bucket_get_params(bucket)->CurPoolSize +=
@@ -605,10 +607,10 @@ void DisjointPool::AllocImpl::printStats(bool &TitlePrinted,
605607
//(*B).printStats(TitlePrinted, MTName);
606608
bucket_t *bucket = B;
607609
HighPeakSlabsInUse =
608-
std::max(bucket->maxSlabsInUse, HighPeakSlabsInUse);
610+
utils_max(bucket->maxSlabsInUse, HighPeakSlabsInUse);
609611
if ((*B).allocCount) {
610612
HighBucketSize =
611-
std::max(bucket_slab_alloc_size(bucket), HighBucketSize);
613+
utils_max(bucket_slab_alloc_size(bucket), HighBucketSize);
612614
}
613615
}
614616
}

src/utils/utils_common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,6 @@ umf_result_t utils_translate_flags(unsigned in_flags, unsigned max,
138138
*out_flags = out_f;
139139
return UMF_RESULT_SUCCESS;
140140
}
141+
142+
size_t utils_max(size_t a, size_t b) { return a > b ? a : b; }
143+
size_t utils_min(size_t a, size_t b) { return a < b ? a : b; }

src/utils/utils_common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ int utils_file_open_or_create(const char *path);
153153

154154
int utils_fallocate(int fd, long offset, long len);
155155

156+
size_t utils_max(size_t a, size_t b);
157+
158+
size_t utils_min(size_t a, size_t b);
159+
156160
#ifdef __cplusplus
157161
}
158162
#endif

0 commit comments

Comments
 (0)