mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-12-10 00:00:24 +03:00
Switch to pthread_mutex_t for spinlocks, too
This fixes an observed journal deadlock - real spinlocks aren't safe in userspace.
This commit is contained in:
parent
a1e928af83
commit
cc1a99fb74
@ -2,27 +2,27 @@
|
|||||||
#define __TOOLS_LINUX_SPINLOCK_H
|
#define __TOOLS_LINUX_SPINLOCK_H
|
||||||
|
|
||||||
#include <linux/atomic.h>
|
#include <linux/atomic.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int count;
|
pthread_mutex_t lock;
|
||||||
} raw_spinlock_t;
|
} raw_spinlock_t;
|
||||||
|
|
||||||
#define __RAW_SPIN_LOCK_UNLOCKED(name) (raw_spinlock_t) { .count = 0 }
|
#define __RAW_SPIN_LOCK_UNLOCKED(name) (raw_spinlock_t) { .lock = PTHREAD_MUTEX_INITIALIZER }
|
||||||
|
|
||||||
static inline void raw_spin_lock_init(raw_spinlock_t *lock)
|
static inline void raw_spin_lock_init(raw_spinlock_t *lock)
|
||||||
{
|
{
|
||||||
smp_store_release(&lock->count, 0);
|
pthread_mutex_init(&lock->lock, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void raw_spin_lock(raw_spinlock_t *lock)
|
static inline void raw_spin_lock(raw_spinlock_t *lock)
|
||||||
{
|
{
|
||||||
while (xchg_acquire(&lock->count, 1))
|
pthread_mutex_lock(&lock->lock);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void raw_spin_unlock(raw_spinlock_t *lock)
|
static inline void raw_spin_unlock(raw_spinlock_t *lock)
|
||||||
{
|
{
|
||||||
smp_store_release(&lock->count, 0);
|
pthread_mutex_unlock(&lock->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define raw_spin_lock_irq(lock) raw_spin_lock(lock)
|
#define raw_spin_lock_irq(lock) raw_spin_lock(lock)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user