Replace global concurrency rw spinlock with rw semaphore
@@ -50,7 +50,7 @@ struct __waiters_list {
};
struct ocf_cache_line_concurrency {
- env_rwlock lock;
+ env_rwsem lock;
env_atomic *access;
env_atomic waiting;
size_t access_limit;
@@ -85,6 +85,13 @@ int ocf_cache_line_concurrency_init(struct ocf_cache *cache)
goto ocf_cache_line_concurrency_init;
}
+ error = env_rwsem_init(&c->lock);
+ if (error) {
+ env_vfree(c);
+ error = __LINE__;
+ goto ocf_cache_line_concurrency_init;
+ }
+
cache->device->concurrency.cache_line = c;
OCF_REALLOC_INIT(&c->access, &c->access_limit);
@@ -116,8 +123,6 @@ int ocf_cache_line_concurrency_init(struct ocf_cache *cache)
goto spinlock_err;
}
- env_rwlock_init(&c->lock);
-
return 0;
spinlock_err:
@@ -127,6 +132,7 @@ ocf_cache_line_concurrency_init:
ocf_cache_log(cache, log_err, "Cannot initialize cache concurrency, "
"ERROR %d", error);
+ if (cache->device->concurrency.cache_line)
ocf_cache_line_concurrency_deinit(cache);
return -1;
@@ -147,7 +153,7 @@ void ocf_cache_line_concurrency_deinit(struct ocf_cache *cache)
concurrency = cache->device->concurrency.cache_line;
- env_rwlock_destroy(&concurrency->lock);
+ env_rwsem_destroy(&concurrency->lock);
for (i = 0; i < _WAITERS_LIST_ENTRIES; i++)
env_spinlock_destroy(&concurrency->waiters_lsts[i].lock);
@@ -813,14 +819,14 @@ int ocf_req_async_lock_rd(struct ocf_request *req, ocf_req_async_lock_cb cb)
req->cache->device->concurrency.cache_line;
int lock;
- env_rwlock_read_lock(&c->lock);
+ env_rwsem_down_read(&c->lock);
lock = _ocf_req_trylock_rd(req);
- env_rwlock_read_unlock(&c->lock);
+ env_rwsem_up_read(&c->lock);
if (lock != OCF_LOCK_ACQUIRED) {
- env_rwlock_write_lock(&c->lock);
+ env_rwsem_down_write(&c->lock);
lock = _ocf_req_lock_rd(req, cb);
- env_rwlock_write_unlock(&c->lock);
+ env_rwsem_up_write(&c->lock);
}
return lock;
@@ -940,14 +946,14 @@ int ocf_req_async_lock_wr(struct ocf_request *req, ocf_req_async_lock_cb cb)
req->cache->device->concurrency.cache_line;
int lock;
- env_rwlock_read_lock(&c->lock);
+ env_rwsem_down_read(&c->lock);
lock = _ocf_req_trylock_wr(req);
- env_rwlock_read_unlock(&c->lock);
+ env_rwsem_up_read(&c->lock);
if (lock != OCF_LOCK_ACQUIRED) {
- env_rwlock_write_lock(&c->lock);
+ env_rwsem_down_write(&c->lock);
lock = _ocf_req_lock_wr(req, cb);
- env_rwlock_write_unlock(&c->lock);
+ env_rwsem_up_write(&c->lock);
}
return lock;
