Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/linux/seqlock.h
Show All 24 Lines | |||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||||
* SUCH DAMAGE. | * SUCH DAMAGE. | ||||
*/ | */ | ||||
#ifndef _LINUXKPI_LINUX_SEQLOCK_H__ | #ifndef _LINUXKPI_LINUX_SEQLOCK_H__ | ||||
#define _LINUXKPI_LINUX_SEQLOCK_H__ | #define _LINUXKPI_LINUX_SEQLOCK_H__ | ||||
#include <sys/param.h> | #include <sys/param.h> | ||||
#include <sys/systm.h> | |||||
#include <sys/lock.h> | #include <sys/lock.h> | ||||
#include <sys/mutex.h> | #include <sys/mutex.h> | ||||
#include <sys/seqc.h> | #include <sys/seqc.h> | ||||
struct lock_class_key; | struct lock_class_key; | ||||
struct seqcount { | struct seqcount { | ||||
seqc_t seqc; | seqc_t seqc; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | seqlock_init(struct seqlock *seqlock) | ||||
* seqlock has been freed. There is no seqlock destructor exists so we | * seqlock has been freed. There is no seqlock destructor exists so we | ||||
* can't expect automatic mtx_destroy() execution before free(). | * can't expect automatic mtx_destroy() execution before free(). | ||||
*/ | */ | ||||
mtx_init(&seqlock->seql_lock, "seqlock", NULL, MTX_DEF|MTX_NOWITNESS); | mtx_init(&seqlock->seql_lock, "seqlock", NULL, MTX_DEF|MTX_NOWITNESS); | ||||
seqcount_init(&seqlock->seql_count); | seqcount_init(&seqlock->seql_count); | ||||
} | } | ||||
static inline void | static inline void | ||||
write_seqlock(struct seqlock *seqlock) | lkpi_write_seqlock(struct seqlock *seqlock, const bool irqsave) | ||||
hselasky: Use lkpi_ as prefix for internal functions. | |||||
{ | { | ||||
mtx_lock(&seqlock->seql_lock); | mtx_lock(&seqlock->seql_lock); | ||||
if (irqsave) | |||||
critical_enter(); | |||||
write_seqcount_begin(&seqlock->seql_count); | write_seqcount_begin(&seqlock->seql_count); | ||||
} | } | ||||
static inline void | static inline void | ||||
write_sequnlock(struct seqlock *seqlock) | write_seqlock(struct seqlock *seqlock) | ||||
{ | { | ||||
lkpi_write_seqlock(seqlock, false); | |||||
} | |||||
static inline void | |||||
lkpi_write_sequnlock(struct seqlock *seqlock, const bool irqsave) | |||||
{ | |||||
write_seqcount_end(&seqlock->seql_count); | write_seqcount_end(&seqlock->seql_count); | ||||
if (irqsave) | |||||
critical_exit(); | |||||
mtx_unlock(&seqlock->seql_lock); | mtx_unlock(&seqlock->seql_lock); | ||||
} | } | ||||
static inline void | |||||
write_sequnlock(struct seqlock *seqlock) | |||||
{ | |||||
lkpi_write_sequnlock(seqlock, false); | |||||
} | |||||
/* | |||||
* Disable preemption when the consumer wants to disable interrupts. This | |||||
* ensures that the caller won't be starved if it is preempted by a | |||||
* higher-priority reader, but assumes that the caller won't perform any | |||||
* blocking operations while holding the write lock; probably a safe | |||||
* assumption. | |||||
*/ | |||||
#define write_seqlock_irqsave(seqlock, flags) do { \ | #define write_seqlock_irqsave(seqlock, flags) do { \ | ||||
(flags) = 0; \ | (flags) = 0; \ | ||||
write_seqlock(seqlock); \ | lkpi_write_seqlock(seqlock, true); \ | ||||
} while (0) | } while (0) | ||||
static inline void | static inline void | ||||
write_sequnlock_irqrestore(struct seqlock *seqlock, | write_sequnlock_irqrestore(struct seqlock *seqlock, | ||||
unsigned long flags __unused) | unsigned long flags __unused) | ||||
{ | { | ||||
write_sequnlock(seqlock); | lkpi_write_sequnlock(seqlock, true); | ||||
} | } | ||||
static inline unsigned | static inline unsigned | ||||
read_seqbegin(const struct seqlock *seqlock) | read_seqbegin(const struct seqlock *seqlock) | ||||
{ | { | ||||
return (read_seqcount_begin(&seqlock->seql_count)); | return (read_seqcount_begin(&seqlock->seql_count)); | ||||
} | } | ||||
#define read_seqretry(seqlock, gen) \ | #define read_seqretry(seqlock, gen) \ | ||||
read_seqcount_retry(&(seqlock)->seql_count, gen) | read_seqcount_retry(&(seqlock)->seql_count, gen) | ||||
#endif /* _LINUXKPI_LINUX_SEQLOCK_H__ */ | #endif /* _LINUXKPI_LINUX_SEQLOCK_H__ */ |
Use lkpi_ as prefix for internal functions.