summaryrefslogtreecommitdiffstats
path: root/include/jemalloc/internal/cache_bin.h
diff options
context:
space:
mode:
authorQi Wang <interwq@gwu.edu>2019-04-03 00:50:42 (GMT)
committerQi Wang <interwq@gwu.edu>2019-04-03 00:50:42 (GMT)
commitb0b3e49a54ec29e32636f4577d9d5a896d67fd20 (patch)
treee80fd5feaedd401e7e2c884e73f8c884f51b5a65 /include/jemalloc/internal/cache_bin.h
parent61efbda7098de6fe64c362d309824864308c36d4 (diff)
parentf7489dc8f1fac233b0cd4e40331de8b738b1f2e2 (diff)
downloadjemalloc-5.2.0.zip
jemalloc-5.2.0.tar.gz
jemalloc-5.2.0.tar.bz2
Merge branch 'dev'5.2.0
Diffstat (limited to 'include/jemalloc/internal/cache_bin.h')
-rw-r--r--include/jemalloc/internal/cache_bin.h35
1 files changed, 26 insertions, 9 deletions
diff --git a/include/jemalloc/internal/cache_bin.h b/include/jemalloc/internal/cache_bin.h
index 12f3ef2..d14556a 100644
--- a/include/jemalloc/internal/cache_bin.h
+++ b/include/jemalloc/internal/cache_bin.h
@@ -88,11 +88,21 @@ JEMALLOC_ALWAYS_INLINE void *
cache_bin_alloc_easy(cache_bin_t *bin, bool *success) {
void *ret;
- if (unlikely(bin->ncached == 0)) {
- bin->low_water = -1;
- *success = false;
- return NULL;
+ bin->ncached--;
+
+ /*
+ * Check for both bin->ncached == 0 and ncached < low_water
+ * in a single branch.
+ */
+ if (unlikely(bin->ncached <= bin->low_water)) {
+ bin->low_water = bin->ncached;
+ if (bin->ncached == -1) {
+ bin->ncached = 0;
+ *success = false;
+ return NULL;
+ }
}
+
/*
* success (instead of ret) should be checked upon the return of this
* function. We avoid checking (ret == NULL) because there is never a
@@ -101,14 +111,21 @@ cache_bin_alloc_easy(cache_bin_t *bin, bool *success) {
* cacheline).
*/
*success = true;
- ret = *(bin->avail - bin->ncached);
- bin->ncached--;
+ ret = *(bin->avail - (bin->ncached + 1));
- if (unlikely(bin->ncached < bin->low_water)) {
- bin->low_water = bin->ncached;
+ return ret;
+}
+
+JEMALLOC_ALWAYS_INLINE bool
+cache_bin_dalloc_easy(cache_bin_t *bin, cache_bin_info_t *bin_info, void *ptr) {
+ if (unlikely(bin->ncached == bin_info->ncached_max)) {
+ return false;
}
+ assert(bin->ncached < bin_info->ncached_max);
+ bin->ncached++;
+ *(bin->avail - bin->ncached) = ptr;
- return ret;
+ return true;
}
#endif /* JEMALLOC_INTERNAL_CACHE_BIN_H */