diff --git a/include/spdk/thread.h b/include/spdk/thread.h index a806c3de9..f036b19d8 100644 --- a/include/spdk/thread.h +++ b/include/spdk/thread.h @@ -1103,39 +1103,8 @@ void spdk_iobuf_entry_abort(struct spdk_iobuf_channel *ch, struct spdk_iobuf_ent * * \return pointer to a buffer or NULL if no buffers are currently available. */ -static inline void * -spdk_iobuf_get(struct spdk_iobuf_channel *ch, uint64_t len, - struct spdk_iobuf_entry *entry, spdk_iobuf_get_cb cb_fn) -{ - struct spdk_iobuf_pool *pool; - void *buf; - - assert(spdk_io_channel_get_thread(ch->parent) == spdk_get_thread()); - if (len <= ch->small.bufsize) { - pool = &ch->small; - } else { - assert(len <= ch->large.bufsize); - pool = &ch->large; - } - - buf = (void *)STAILQ_FIRST(&pool->cache); - if (buf) { - STAILQ_REMOVE_HEAD(&pool->cache, stailq); - assert(pool->cache_count > 0); - pool->cache_count--; - } else { - buf = spdk_mempool_get(pool->pool); - if (!buf) { - STAILQ_INSERT_TAIL(pool->queue, entry, stailq); - entry->module = ch->module; - entry->cb_fn = cb_fn; - - return NULL; - } - } - - return (char *)buf; -} +void *spdk_iobuf_get(struct spdk_iobuf_channel *ch, uint64_t len, struct spdk_iobuf_entry *entry, + spdk_iobuf_get_cb cb_fn); /** * Release a buffer back to the iobuf pool. If there are outstanding requests waiting for a buffer, @@ -1145,32 +1114,7 @@ spdk_iobuf_get(struct spdk_iobuf_channel *ch, uint64_t len, * \param buf Buffer to release * \param len Length of the buffer (must be the exact same value as specified in `spdk_iobuf_get()`). */ -static inline void -spdk_iobuf_put(struct spdk_iobuf_channel *ch, void *buf, uint64_t len) -{ - struct spdk_iobuf_entry *entry; - struct spdk_iobuf_pool *pool; - - assert(spdk_io_channel_get_thread(ch->parent) == spdk_get_thread()); - if (len <= ch->small.bufsize) { - pool = &ch->small; - } else { - pool = &ch->large; - } - - if (STAILQ_EMPTY(pool->queue)) { - if (pool->cache_count < pool->cache_size) { - STAILQ_INSERT_HEAD(&pool->cache, (struct spdk_iobuf_buffer *)buf, stailq); - pool->cache_count++; - } else { - spdk_mempool_put(pool->pool, buf); - } - } else { - entry = STAILQ_FIRST(pool->queue); - STAILQ_REMOVE_HEAD(pool->queue, stailq); - entry->cb_fn(entry, buf); - } -} +void spdk_iobuf_put(struct spdk_iobuf_channel *ch, void *buf, uint64_t len); #ifdef __cplusplus } diff --git a/lib/thread/iobuf.c b/lib/thread/iobuf.c index dfc8ad513..4c794f0f4 100644 --- a/lib/thread/iobuf.c +++ b/lib/thread/iobuf.c @@ -347,3 +347,64 @@ spdk_iobuf_entry_abort(struct spdk_iobuf_channel *ch, struct spdk_iobuf_entry *e STAILQ_REMOVE(pool->queue, entry, spdk_iobuf_entry, stailq); } + +void * +spdk_iobuf_get(struct spdk_iobuf_channel *ch, uint64_t len, + struct spdk_iobuf_entry *entry, spdk_iobuf_get_cb cb_fn) +{ + struct spdk_iobuf_pool *pool; + void *buf; + + assert(spdk_io_channel_get_thread(ch->parent) == spdk_get_thread()); + if (len <= ch->small.bufsize) { + pool = &ch->small; + } else { + assert(len <= ch->large.bufsize); + pool = &ch->large; + } + + buf = (void *)STAILQ_FIRST(&pool->cache); + if (buf) { + STAILQ_REMOVE_HEAD(&pool->cache, stailq); + assert(pool->cache_count > 0); + pool->cache_count--; + } else { + buf = spdk_mempool_get(pool->pool); + if (!buf) { + STAILQ_INSERT_TAIL(pool->queue, entry, stailq); + entry->module = ch->module; + entry->cb_fn = cb_fn; + + return NULL; + } + } + + return (char *)buf; +} + +void +spdk_iobuf_put(struct spdk_iobuf_channel *ch, void *buf, uint64_t len) +{ + struct spdk_iobuf_entry *entry; + struct spdk_iobuf_pool *pool; + + assert(spdk_io_channel_get_thread(ch->parent) == spdk_get_thread()); + if (len <= ch->small.bufsize) { + pool = &ch->small; + } else { + pool = &ch->large; + } + + if (STAILQ_EMPTY(pool->queue)) { + if (pool->cache_count < pool->cache_size) { + STAILQ_INSERT_HEAD(&pool->cache, (struct spdk_iobuf_buffer *)buf, stailq); + pool->cache_count++; + } else { + spdk_mempool_put(pool->pool, buf); + } + } else { + entry = STAILQ_FIRST(pool->queue); + STAILQ_REMOVE_HEAD(pool->queue, stailq); + entry->cb_fn(entry, buf); + } +} diff --git a/lib/thread/spdk_thread.map b/lib/thread/spdk_thread.map index abe047bd1..6942f39e9 100644 --- a/lib/thread/spdk_thread.map +++ b/lib/thread/spdk_thread.map @@ -72,6 +72,8 @@ spdk_iobuf_register_module; spdk_iobuf_for_each_entry; spdk_iobuf_entry_abort; + spdk_iobuf_get; + spdk_iobuf_put; # internal functions in spdk_internal/thread.h spdk_poller_get_name;