Adding synchronization primitives destroyers
Environment should provide calls for destroying primitives (i.e. env_mutex_destroy()) and OCF should call these functions in its cleanup paths. Signed-off-by: Firas Medini <mdnfiras@yahoo.com>
This commit is contained in:
5
env/posix/ocf_env.c
vendored
5
env/posix/ocf_env.c
vendored
@@ -110,11 +110,6 @@ void env_allocator_destroy(env_allocator *allocator)
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t env_allocator_item_count(env_allocator *allocator)
|
||||
{
|
||||
return env_atomic_read(&allocator->count);
|
||||
}
|
||||
|
||||
/* *** DEBUGING *** */
|
||||
|
||||
#define ENV_TRACE_DEPTH 16
|
||||
|
||||
110
env/posix/ocf_env.h
vendored
110
env/posix/ocf_env.h
vendored
@@ -169,8 +169,6 @@ void *env_allocator_new(env_allocator *allocator);
|
||||
|
||||
void env_allocator_del(env_allocator *allocator, void *item);
|
||||
|
||||
uint32_t env_allocator_item_count(env_allocator *allocator);
|
||||
|
||||
/* *** MUTEX *** */
|
||||
|
||||
typedef struct {
|
||||
@@ -198,22 +196,15 @@ static inline int env_mutex_lock_interruptible(env_mutex *mutex)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int env_mutex_trylock(env_mutex *mutex)
|
||||
{
|
||||
return pthread_mutex_trylock(&mutex->m) ? -OCF_ERR_NO_LOCK : 0;
|
||||
}
|
||||
|
||||
static inline void env_mutex_unlock(env_mutex *mutex)
|
||||
{
|
||||
ENV_BUG_ON(pthread_mutex_unlock(&mutex->m));
|
||||
}
|
||||
|
||||
static inline int env_mutex_is_locked(env_mutex *mutex)
|
||||
static inline int env_mutex_destroy(env_mutex *mutex)
|
||||
{
|
||||
if (env_mutex_trylock(mutex) == 0) {
|
||||
env_mutex_unlock(mutex);
|
||||
if(pthread_mutex_destroy(&mutex->m))
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -243,19 +234,17 @@ static inline int env_rmutex_lock_interruptible(env_rmutex *rmutex)
|
||||
return env_mutex_lock_interruptible(rmutex);
|
||||
}
|
||||
|
||||
static inline int env_rmutex_trylock(env_rmutex *rmutex)
|
||||
{
|
||||
return env_mutex_trylock(rmutex);
|
||||
}
|
||||
|
||||
static inline void env_rmutex_unlock(env_rmutex *rmutex)
|
||||
{
|
||||
env_mutex_unlock(rmutex);
|
||||
}
|
||||
|
||||
static inline int env_rmutex_is_locked(env_rmutex *rmutex)
|
||||
static inline int env_rmutex_destroy(env_rmutex *rmutex)
|
||||
{
|
||||
return env_mutex_is_locked(rmutex);
|
||||
if(pthread_mutex_destroy(&rmutex->m))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* *** RW SEMAPHORE *** */
|
||||
@@ -298,26 +287,9 @@ 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_is_locked(env_rwsem *s)
|
||||
static inline int env_rwsem_destroy(env_rwsem *s)
|
||||
{
|
||||
if (env_rwsem_down_read_trylock(s) == 0) {
|
||||
env_rwsem_up_read(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int env_rwsem_down_write_interruptible(env_rwsem *s)
|
||||
{
|
||||
env_rwsem_down_write(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline int env_rwsem_down_read_interruptible(env_rwsem *s)
|
||||
{
|
||||
env_rwsem_down_read(s);
|
||||
return 0;
|
||||
return pthread_rwlock_destroy(&s->lock);
|
||||
}
|
||||
|
||||
/* *** COMPLETION *** */
|
||||
@@ -342,10 +314,9 @@ static inline void env_completion_complete(env_completion *completion)
|
||||
sem_post(&completion->sem);
|
||||
}
|
||||
|
||||
static inline void env_completion_complete_and_exit(
|
||||
env_completion *completion, int ret)
|
||||
static inline void env_completion_destroy(env_completion *completion)
|
||||
{
|
||||
env_completion_complete(completion); /* TODO */
|
||||
sem_destroy(&completion->sem);
|
||||
}
|
||||
|
||||
/* *** ATOMIC VARIABLES *** */
|
||||
@@ -378,11 +349,6 @@ static inline void env_atomic_sub(int i, env_atomic *a)
|
||||
__sync_sub_and_fetch(&a->counter, i);
|
||||
}
|
||||
|
||||
static inline bool env_atomic_sub_and_test(int i, env_atomic *a)
|
||||
{
|
||||
return __sync_sub_and_fetch(&a->counter, i) == 0;
|
||||
}
|
||||
|
||||
static inline void env_atomic_inc(env_atomic *a)
|
||||
{
|
||||
env_atomic_add(1, a);
|
||||
@@ -398,11 +364,6 @@ static inline bool env_atomic_dec_and_test(env_atomic *a)
|
||||
return __sync_sub_and_fetch(&a->counter, 1) == 0;
|
||||
}
|
||||
|
||||
static inline bool env_atomic_inc_and_test(env_atomic *a)
|
||||
{
|
||||
return __sync_add_and_fetch(&a->counter, 1) == 0;
|
||||
}
|
||||
|
||||
static inline int env_atomic_add_return(int i, env_atomic *a)
|
||||
{
|
||||
return __sync_add_and_fetch(&a->counter, i);
|
||||
@@ -504,16 +465,6 @@ static inline void env_spinlock_unlock(env_spinlock *l)
|
||||
ENV_BUG_ON(pthread_spin_unlock(&l->lock));
|
||||
}
|
||||
|
||||
static inline void env_spinlock_lock_irq(env_spinlock *l)
|
||||
{
|
||||
env_spinlock_lock(l);
|
||||
}
|
||||
|
||||
static inline void env_spinlock_unlock_irq(env_spinlock *l)
|
||||
{
|
||||
env_spinlock_unlock(l);
|
||||
}
|
||||
|
||||
#define env_spinlock_lock_irqsave(l, flags) \
|
||||
(void)flags; \
|
||||
env_spinlock_lock(l)
|
||||
@@ -522,6 +473,11 @@ static inline void env_spinlock_unlock_irq(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 {
|
||||
@@ -553,22 +509,17 @@ 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 {
|
||||
sem_t sem;
|
||||
} env_waitqueue;
|
||||
|
||||
static inline void env_waitqueue_init(env_waitqueue *w)
|
||||
{
|
||||
sem_init(&w->sem, 0, 0);
|
||||
}
|
||||
|
||||
static inline void env_waitqueue_wake_up(env_waitqueue *w)
|
||||
{
|
||||
sem_post(&w->sem);
|
||||
}
|
||||
|
||||
#define env_waitqueue_wait(w, condition) \
|
||||
({ \
|
||||
int __ret = 0; \
|
||||
@@ -577,6 +528,11 @@ static inline void env_waitqueue_wake_up(env_waitqueue *w)
|
||||
__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)
|
||||
@@ -604,12 +560,6 @@ static inline bool env_bit_test(int nr, const volatile unsigned long *addr)
|
||||
return !!(*byte & mask);
|
||||
}
|
||||
|
||||
/* *** SCHEDULING *** */
|
||||
static inline void env_schedule(void)
|
||||
{
|
||||
sched_yield();
|
||||
}
|
||||
|
||||
static inline int env_in_interrupt(void)
|
||||
{
|
||||
return 0;
|
||||
@@ -689,14 +639,6 @@ struct env_timeval {
|
||||
uint64_t sec, usec;
|
||||
};
|
||||
|
||||
static inline void env_gettimeofday(struct env_timeval *tv)
|
||||
{
|
||||
struct timeval t;
|
||||
gettimeofday(&t, NULL);
|
||||
tv->sec = t.tv_sec;
|
||||
tv->usec = t.tv_usec;
|
||||
}
|
||||
|
||||
uint32_t env_crc32(uint32_t crc, uint8_t const *data, size_t len);
|
||||
|
||||
#define ENV_PRIu64 "lu"
|
||||
|
||||
Reference in New Issue
Block a user