Merge pull request #234 from mdnfiras/sync-prim-destroyers

Adding synchronization primitives destroyers
This commit is contained in:
Robert Bałdyga 2019-08-13 15:46:26 +02:00 committed by GitHub
commit 8ed525ae7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 75 additions and 0 deletions

43
env/posix/ocf_env.h vendored
View File

@ -201,6 +201,16 @@ static inline void env_mutex_unlock(env_mutex *mutex)
ENV_BUG_ON(pthread_mutex_unlock(&mutex->m));
}
static inline int env_mutex_destroy(env_mutex *mutex)
{
if(pthread_mutex_destroy(&mutex->m))
return 1;
return 0;
}
/* *** RECURSIVE MUTEX *** */
typedef env_mutex env_rmutex;
static inline int env_rmutex_init(env_rmutex *rmutex)
@ -229,6 +239,14 @@ static inline void env_rmutex_unlock(env_rmutex *rmutex)
env_mutex_unlock(rmutex);
}
static inline int env_rmutex_destroy(env_rmutex *rmutex)
{
if(pthread_mutex_destroy(&rmutex->m))
return 1;
return 0;
}
/* *** RW SEMAPHORE *** */
typedef struct {
pthread_rwlock_t lock;
@ -269,6 +287,11 @@ static inline int env_rwsem_down_write_trylock(env_rwsem *s)
return pthread_rwlock_trywrlock(&s->lock) ? -OCF_ERR_NO_LOCK : 0;
}
static inline int env_rwsem_destroy(env_rwsem *s)
{
return pthread_rwlock_destroy(&s->lock);
}
/* *** COMPLETION *** */
struct completion {
sem_t sem;
@ -291,6 +314,11 @@ static inline void env_completion_complete(env_completion *completion)
sem_post(&completion->sem);
}
static inline void env_completion_destroy(env_completion *completion)
{
sem_destroy(&completion->sem);
}
/* *** ATOMIC VARIABLES *** */
typedef struct {
@ -445,6 +473,11 @@ static inline void env_spinlock_unlock(env_spinlock *l)
(void)flags; \
env_spinlock_unlock(l)
static inline void env_spinlock_destroy(env_spinlock *l)
{
ENV_BUG_ON(pthread_spin_destroy(&l->lock));
}
/* *** RW LOCKS *** */
typedef struct {
@ -476,6 +509,11 @@ static inline void env_rwlock_write_unlock(env_rwlock *l)
ENV_BUG_ON(pthread_rwlock_unlock(&l->lock));
}
static inline void env_rwlock_destroy(env_rwlock *l)
{
ENV_BUG_ON(pthread_rwlock_destroy(&l->lock));
}
/* *** WAITQUEUE *** */
typedef struct {
@ -490,6 +528,11 @@ typedef struct {
__ret = __ret; \
})
static inline void env_waitqueue_destroy(env_waitqueue *w)
{
sem_destroy(&w->sem);
}
/* *** BIT OPERATIONS *** */
static inline void env_bit_set(int nr, volatile void *addr)

View File

@ -233,8 +233,13 @@ void cleaning_policy_acp_init_cache_block(struct ocf_cache *cache,
void cleaning_policy_acp_deinitialize(struct ocf_cache *cache)
{
struct acp_context *acp;
_acp_remove_cores(cache);
acp = cache->cleaner.cleaning_policy_context;
env_rwsem_destroy(&acp->chunks_lock);
env_vfree(cache->cleaner.cleaning_policy_context);
cache->cleaner.cleaning_policy_context = NULL;
}

View File

@ -134,6 +134,7 @@ ocf_cache_line_concurrency_init:
*/
void ocf_cache_line_concurrency_deinit(struct ocf_cache *cache)
{
int i;
struct ocf_cache_line_concurrency *concurrency;
if (!cache->device->concurrency.cache_line)
@ -143,6 +144,11 @@ void ocf_cache_line_concurrency_deinit(struct ocf_cache *cache)
concurrency = cache->device->concurrency.cache_line;
env_rwlock_destroy(&concurrency->lock);
for (i = 0; i < _WAITERS_LIST_ENTRIES; i++)
env_spinlock_destroy(&concurrency->waiters_lsts[i].lock);
if (concurrency->access)
OCF_REALLOC_DEINIT(&concurrency->access,
&concurrency->access_limit);

View File

@ -12,6 +12,13 @@ void ocf_metadata_concurrency_init(struct ocf_cache *cache)
env_rwsem_init(&cache->metadata.lock.collision);
}
void ocf_metadata_concurrency_deinit(struct ocf_cache *cache)
{
env_spinlock_destroy(&cache->metadata.lock.eviction);
env_rwlock_destroy(&cache->metadata.lock.status);
env_rwsem_destroy(&cache->metadata.lock.collision);
}
int ocf_metadata_concurrency_attached_init(struct ocf_cache *cache)
{
return 0;

View File

@ -12,6 +12,8 @@
void ocf_metadata_concurrency_init(struct ocf_cache *cache);
void ocf_metadata_concurrency_deinit(struct ocf_cache *cache);
int ocf_metadata_concurrency_attached_init(struct ocf_cache *cache);
static inline void ocf_metadata_eviction_lock(struct ocf_cache *cache)

View File

@ -73,6 +73,8 @@ void ocf_metadata_deinit(struct ocf_cache *cache)
cache->metadata.iface.deinit(cache);
}
ocf_metadata_concurrency_deinit(cache);
ocf_metadata_io_deinit(cache);
}

View File

@ -129,6 +129,8 @@ int raw_dynamic_deinit(ocf_cache_t cache,
for (i = 0; i < raw->ssd_pages; i++)
env_secure_free(ctrl->pages[i], PAGE_SIZE);
env_mutex_destroy(&ctrl->lock);
env_vfree(ctrl);
raw->priv = NULL;

View File

@ -33,6 +33,7 @@ void ocf_metadata_updater_kick(ocf_cache_t cache)
void ocf_metadata_updater_stop(ocf_cache_t cache)
{
ctx_metadata_updater_stop(cache->owner, &cache->metadata_updater);
env_mutex_destroy(&cache->metadata_updater.syncher.lock);
}
void ocf_metadata_updater_set_priv(ocf_metadata_updater_t mu, void *priv)

View File

@ -135,6 +135,7 @@ void ocf_mngt_cache_put(ocf_cache_t cache)
ctx = cache->owner;
ocf_metadata_deinit(cache);
ocf_mngt_cache_lock_deinit(cache);
env_mutex_destroy(&cache->flush_mutex);
env_vfree(cache);
ocf_ctx_put(ctx);
}

View File

@ -233,6 +233,8 @@ void ocf_ctx_put(ocf_ctx_t ctx)
ocf_mngt_core_pool_deinit(ctx);
ocf_ctx_unregister_volume_types(ctx);
env_rmutex_destroy(&ctx->lock);
ocf_req_allocator_deinit(ctx);
ocf_logger_close(&ctx->logger);
env_free(ctx);

View File

@ -60,6 +60,7 @@ void ocf_queue_put(ocf_queue_t queue)
list_del(&queue->list);
queue->ops->stop(queue);
ocf_mngt_cache_put(queue->cache);
env_spinlock_destroy(&queue->io_list_lock);
env_free(queue);
}
}

View File

@ -308,6 +308,7 @@ static void ocf_volume_close_end(void *ctx)
env_completion *cmpl = ctx;
env_completion_complete(cmpl);
env_completion_destroy(cmpl);
}
void ocf_volume_close(ocf_volume_t volume)

View File

@ -73,6 +73,8 @@ void ocf_async_lock_deinit(struct ocf_async_lock *lock)
list_move_tail(&iter->list, &waiters);
env_mutex_unlock(&lock->mutex);
env_mutex_destroy(&lock->mutex);
_ocf_async_lock_run_waiters(lock, &waiters, -OCF_ERR_NO_LOCK);
}