aboutsummaryrefslogtreecommitdiff
path: root/include/apos/lock.h
blob: b8983faa32307da872603e762e47d4b8ddeaae74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef LOCK_H
#define LOCK_H

#include <apos/atomic.h>
typedef atomic_int spinlock_t;

#include <lock.h>

static inline void spin_lock(spinlock_t *lck)
{
	do {
		while (atomic_load_explicit(lck, memory_order_acquire))
			optional_pause();

	} while (atomic_exchange_explicit(lck, 1, memory_order_acq_rel));
}

static inline void spin_unlock(spinlock_t *lck)
{
	atomic_store_explicit(lck, 0, memory_order_release);
}

#endif /* LOCK_H */