mirror of
https://github.com/XTXMarkets/ternfs.git
synced 2026-05-07 21:01:48 -05:00
6addbdee6a
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>
36 lines
885 B
C
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
|
|
|