File: spinlock.h

package info (click to toggle)
xfsprogs 6.18.0-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 11,304 kB
  • sloc: ansic: 167,330; sh: 4,604; makefile: 1,337; python: 835; cpp: 5
file content (30 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2019-20 RedHat, Inc.
 * All Rights Reserved.
 */
#ifndef __LIBXFS_SPINLOCK_H__
#define __LIBXFS_SPINLOCK_H__

/*
 * This implements kernel compatible spinlock exclusion semantics. These,
 * however, are not spinlocks, as spinlocks cannot be reliably implemented in
 * userspace without using realtime scheduling task contexts. Hence this
 * interface is implemented with pthread mutexes and so can block, but this is
 * no different to the kernel RT build which replaces spinlocks with mutexes.
 * Hence we know it works.
 */

typedef pthread_mutex_t	spinlock_t;

#define spin_lock_init(l)	pthread_mutex_init(l, NULL)
#define spin_lock(l)		pthread_mutex_lock(l)
#define spin_trylock(l)		(pthread_mutex_trylock(l) != EBUSY)
#define spin_unlock(l)		pthread_mutex_unlock(l)

#define mutex_init(l)		pthread_mutex_init(l, NULL)
#define mutex_lock(l)		pthread_mutex_lock(l)
#define mutex_trylock(l)	(pthread_mutex_trylock(l) != EBUSY)
#define mutex_unlock(l)		pthread_mutex_unlock(l)

#endif /* __LIBXFS_SPINLOCK_H__ */