From 03bd6d6c49127fb732713b398d4fbe457ae4b933 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 25 Feb 2019 17:47:27 +0100 Subject: [PATCH] Add ocf_cache_has_pending_requests() function Signed-off-by: Robert Baldyga --- inc/ocf_cache.h | 7 +++++++ src/ocf_cache.c | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/inc/ocf_cache.h b/inc/ocf_cache.h index c31d72b..abb15a0 100644 --- a/inc/ocf_cache.h +++ b/inc/ocf_cache.h @@ -179,6 +179,13 @@ bool ocf_cache_is_running(ocf_cache_t cache); */ void ocf_cache_wait_for_io_finish(ocf_cache_t cache); +/** + * @brief Check if cache has any unfunished requests + * + * @param[in] cache Cache object + */ +bool ocf_cache_has_pending_requests(ocf_cache_t cache); + /** * @brief Get cache mode of given cache object * diff --git a/src/ocf_cache.c b/src/ocf_cache.c index cda2340..ffe4ab4 100644 --- a/src/ocf_cache.c +++ b/src/ocf_cache.c @@ -56,6 +56,8 @@ void ocf_cache_wait_for_io_finish(ocf_cache_t cache) { uint32_t req_active = 0; + OCF_CHECK_NULL(cache); + do { req_active = ocf_req_get_allocated(cache); if (req_active) @@ -63,6 +65,12 @@ void ocf_cache_wait_for_io_finish(ocf_cache_t cache) } while (req_active); } +bool ocf_cache_has_pending_requests(ocf_cache_t cache) +{ + OCF_CHECK_NULL(cache); + return ocf_req_get_allocated(cache) > 0; +} + ocf_cache_mode_t ocf_cache_get_mode(ocf_cache_t cache) { OCF_CHECK_NULL(cache);