Files
ternfs-XTXMarkets/kmod/latch.h
T
Francesco Mazzoli 6addbdee6a First version of kernel module
Initial version really by Pawel, but many changes in between.

Big outstanding issues:

* span cache reclamation (unbounded memory otherwise...)
* bad block service detection and workarounds
* corrupted blocks detection and workaround

Co-authored-by: Paweł Dziepak <pawel.dziepak@xtxmarkets.com>
2023-05-18 15:29:41 +00:00

36 lines
885 B
C

#ifndef _EGGSFS_LATCH_H
#define _EGGSFS_LATCH_H
#include <linux/kernel.h>
#include <linux/wait.h>
struct eggsfs_latch {
atomic64_t counter;
wait_queue_head_t wq;
};
#define eggsfs_latch_init(_latch) ({ \
atomic64_set(&(_latch)->counter, 0); \
init_waitqueue_head(&(_latch)->wq); \
})
#define eggsfs_latch_try_acquire(_latch, _seqno) ({ \
(_seqno) = atomic64_fetch_or(1, &(_latch)->counter); \
smp_mb__after_atomic(); \
!(_seqno & 1); \
})
#define eggsfs_latch_release(_latch, _seqno) ({ \
smp_mb__before_atomic(); \
atomic64_set(&(_latch)->counter, (_seqno) + 2); \
wake_up_all(&(_latch)->wq); \
})
#define eggsfs_latch_wait_killable(_latch, _seqno) ({ \
u64 goal = ((_seqno) | 1); \
wait_event_killable((_latch)->wq, atomic64_read(&(_latch)->counter) > goal); \
})
#endif