1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
/* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */
#ifndef __EROFS_LOCK_H
#define __EROFS_LOCK_H
#include "defs.h"
#if defined(HAVE_PTHREAD_H) && defined(EROFS_MT_ENABLED)
#include <pthread.h>
typedef pthread_mutex_t erofs_mutex_t;
static inline void erofs_mutex_init(erofs_mutex_t *lock)
{
pthread_mutex_init(lock, NULL);
}
#define erofs_mutex_lock pthread_mutex_lock
#define erofs_mutex_unlock pthread_mutex_unlock
#define EROFS_DEFINE_MUTEX(lock) \
erofs_mutex_t lock = PTHREAD_MUTEX_INITIALIZER
typedef pthread_rwlock_t erofs_rwsem_t;
static inline void erofs_init_rwsem(erofs_rwsem_t *lock)
{
pthread_rwlock_init(lock, NULL);
}
#define erofs_down_read pthread_rwlock_rdlock
#define erofs_down_write pthread_rwlock_wrlock
#define erofs_up_read pthread_rwlock_unlock
#define erofs_up_write pthread_rwlock_unlock
#else
typedef struct {} erofs_mutex_t;
static inline void erofs_mutex_init(erofs_mutex_t *lock) {}
static inline void erofs_mutex_lock(erofs_mutex_t *lock) {}
static inline void erofs_mutex_unlock(erofs_mutex_t *lock) {}
#define EROFS_DEFINE_MUTEX(lock) \
erofs_mutex_t lock = {}
typedef struct {} erofs_rwsem_t;
static inline void erofs_init_rwsem(erofs_rwsem_t *lock) {}
static inline void erofs_down_read(erofs_rwsem_t *lock) {}
static inline void erofs_down_write(erofs_rwsem_t *lock) {}
static inline void erofs_up_read(erofs_rwsem_t *lock) {}
static inline void erofs_up_write(erofs_rwsem_t *lock) {}
#endif
#endif
|