File: uassert.h

package info (click to toggle)
liburcu 0.15.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,356 kB
  • sloc: ansic: 23,361; xml: 23,227; sh: 6,480; makefile: 1,045; cpp: 15
file content (73 lines) | stat: -rw-r--r-- 1,991 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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-FileCopyrightText: 2025 Michael Jeanson <mjeanson@efficios.com>
//
// SPDX-License-Identifier: LGPL-2.1-or-later

#ifndef _URCU_ARCH_UATOMIC_UASSERT_H
#define _URCU_ARCH_UATOMIC_UASSERT_H

#include <urcu/compiler.h>

#ifdef __cplusplus
extern "C" {
#endif

#define _uatomic_str(s) #s
#define _uatomic_xstr(s) _uatomic_str(s)

#if (!(defined(UATOMIC_HAS_ATOMIC_BYTE) || \
	defined(UATOMIC_HAS_ATOMIC_SHORT) || \
	defined(UATOMIC_HAS_ATOMIC_INT) || \
	defined(UATOMIC_HAS_ATOMIC_LLONG)))
#error "This header must be included after the architecture UATOMIC_HAS_ATOMIC_* defines."
#endif

#ifdef UATOMIC_HAS_ATOMIC_BYTE
#define _UATOMIC_HAS_ATOMIC_BYTE_FLAG (1 << 0)
#else
#define _UATOMIC_HAS_ATOMIC_BYTE_FLAG (0)
#endif

#ifdef UATOMIC_HAS_ATOMIC_SHORT
#define _UATOMIC_HAS_ATOMIC_SHORT_FLAG (1 << 1)
#else
#define _UATOMIC_HAS_ATOMIC_SHORT_FLAG (0)
#endif

#ifdef UATOMIC_HAS_ATOMIC_INT
#define _UATOMIC_HAS_ATOMIC_INT_FLAG (1 << 2)
#else
#define _UATOMIC_HAS_ATOMIC_INT_FLAG (0)
#endif

#ifdef UATOMIC_HAS_ATOMIC_LLONG
#define _UATOMIC_HAS_ATOMIC_LLONG_FLAG (1 << 3)
#else
#define _UATOMIC_HAS_ATOMIC_LLONG_FLAG (0)
#endif

/*
 * Bitmask of the supported atomic sizes for the architecture.
 */
#define _UATOMIC_HAS_ATOMIC_MASK						\
	(_UATOMIC_HAS_ATOMIC_BYTE_FLAG | _UATOMIC_HAS_ATOMIC_SHORT_FLAG |	\
	 _UATOMIC_HAS_ATOMIC_INT_FLAG | _UATOMIC_HAS_ATOMIC_LLONG_FLAG)

#define _uatomic_has_atomic_type(len)						\
	(len && !(len & (len - 1)) && (_UATOMIC_HAS_ATOMIC_MASK & len))

/*
 * Static assert to test that atomic operations are supported on types of 'len'
 * bytes on the current architecture. The 'len' parameter must be a constant
 * expression.
 */
#define _uatomic_static_assert_atomic(len)					\
	urcu_static_assert(_uatomic_has_atomic_type(len),			\
		"The architecture does not support atomic "			\
		"operations on types of " _uatomic_xstr(len) " bytes.",		\
		uatomic_atomic_type_not_supported)

#ifdef __cplusplus
}
#endif

#endif /* _URCU_ARCH_UATOMIC_UASSERT_H */