From 6d962b38e993129b61dd373ec8c8e663b232f1c2 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Thu, 14 Jan 2021 23:48:08 -0500 Subject: [PATCH] API for cacheline write trylock Signed-off-by: Michal Mielewczyk --- src/concurrency/ocf_cache_line_concurrency.c | 14 ++++++++++++++ src/concurrency/ocf_cache_line_concurrency.h | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/concurrency/ocf_cache_line_concurrency.c b/src/concurrency/ocf_cache_line_concurrency.c index 465d76f..cbe0833 100644 --- a/src/concurrency/ocf_cache_line_concurrency.c +++ b/src/concurrency/ocf_cache_line_concurrency.c @@ -1157,3 +1157,17 @@ void ocf_cache_line_unlock_rd(struct ocf_cache *cache, ocf_cache_line_t line) __unlock_cache_line_rd(c, line); } +bool ocf_cache_line_try_lock_wr(struct ocf_cache *cache, ocf_cache_line_t line) +{ + struct ocf_cache_line_concurrency *c = cache->device->concurrency.cache_line; + return __lock_cache_line_wr(c, line, NULL, NULL, 0); +} + +void ocf_cache_line_unlock_wr(struct ocf_cache *cache, ocf_cache_line_t line) +{ + struct ocf_cache_line_concurrency *c = cache->device->concurrency.cache_line; + + OCF_DEBUG_RQ(cache, "Cache line = %u", line); + + __unlock_cache_line_wr(c, line); +} diff --git a/src/concurrency/ocf_cache_line_concurrency.h b/src/concurrency/ocf_cache_line_concurrency.h index c49a803..c42c170 100644 --- a/src/concurrency/ocf_cache_line_concurrency.h +++ b/src/concurrency/ocf_cache_line_concurrency.h @@ -161,4 +161,23 @@ void ocf_cache_line_unlock_rd(struct ocf_cache *cache, ocf_cache_line_t line); */ bool ocf_cache_line_try_lock_rd(struct ocf_cache *cache, ocf_cache_line_t line); +/** + * @brief Release cache line write lock + * + * @param cache - OCF cache instance + * @param line - Cache line to be unlocked + */ +void ocf_cache_line_unlock_wr(struct ocf_cache *cache, ocf_cache_line_t line); + +/** + * @brief Attempt to lock cache line for write + * + * @param cache - OCF cache instance + * @param line - Cache line to be checked for waiters + * + * @retval true - write lock successfully acquired + * @retval false - failed to acquire write lock + */ +bool ocf_cache_line_try_lock_wr(struct ocf_cache *cache, ocf_cache_line_t line); + #endif /* OCF_CONCURRENCY_H_ */