Skip to content

Commit

Permalink
btrfs-progs: kernel-lib: make headers C++ compatible
Browse files Browse the repository at this point in the history
The snapper build fails due to updates to kernel-lib files, the type
casts do not work the same way in C++. Simplify READ_ONCE/WRITE_ONCE
even more, drop use of 'new' as identifier.

Issue: openSUSE/snapper#725
Signed-off-by: David Sterba <[email protected]>
  • Loading branch information
kdave committed Jun 6, 2022
1 parent a7ae6d5 commit 63e0f3b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
21 changes: 3 additions & 18 deletions kerncompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,29 +538,14 @@ struct __una_u64 { __le64 x; } __attribute__((__packed__));
* Changed:
* - __unqual_scalar_typeof: volatile cast to typeof()
* - compiletime_assert_rwonce_type: no word size compatibility checks
* - no const volatile cast
*/

/*
* Use __READ_ONCE() instead of READ_ONCE() if you do not require any
* atomicity. Note that this may result in tears!
*/
#ifndef __READ_ONCE
#define __READ_ONCE(x) (*(const volatile typeof(x) *)&(x))
#endif

#define READ_ONCE(x) \
({ \
__READ_ONCE(x); \
})

#define __WRITE_ONCE(x, val) \
do { \
*(volatile typeof(x) *)&(x) = (val); \
} while (0)
#define READ_ONCE(x) (x)

#define WRITE_ONCE(x, val) \
do { \
__WRITE_ONCE(x, val); \
(x) = (val); \
} while (0)

#endif
24 changes: 16 additions & 8 deletions kernel-lib/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <stddef.h>
#include <stdbool.h>

#ifdef __cplusplus
extern "C" {
#endif

#define LIST_POISON1 ((void *) 0x00100100)
#define LIST_POISON2 ((void *) 0x00200200)

Expand Down Expand Up @@ -187,8 +191,8 @@ static inline void __list_del_entry(struct list_head *entry)
static inline void list_del(struct list_head *entry)
{
__list_del_entry(entry);
entry->next = LIST_POISON1;
entry->prev = LIST_POISON2;
entry->next = (struct list_head *)LIST_POISON1;
entry->prev = (struct list_head *)LIST_POISON2;
}

/**
Expand Down Expand Up @@ -901,8 +905,8 @@ static inline void __hlist_del(struct hlist_node *n)
static inline void hlist_del(struct hlist_node *n)
{
__hlist_del(n);
n->next = LIST_POISON1;
n->pprev = LIST_POISON2;
n->next = (struct hlist_node *)LIST_POISON1;
n->pprev = (struct hlist_node **)LIST_POISON2;
}

/**
Expand Down Expand Up @@ -1012,11 +1016,11 @@ hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h)
* reference of the first entry if it exists.
*/
static inline void hlist_move_list(struct hlist_head *old,
struct hlist_head *new)
struct hlist_head *xnew)
{
new->first = old->first;
if (new->first)
new->first->pprev = &new->first;
xnew->first = old->first;
if (xnew->first)
xnew->first->pprev = &xnew->first;
old->first = NULL;
}

Expand Down Expand Up @@ -1076,4 +1080,8 @@ static inline void hlist_move_list(struct hlist_head *old,
pos && ({ n = pos->member.next; 1; }); \
pos = hlist_entry_safe(n, typeof(*pos), member))

#ifdef __cplusplus
}
#endif

#endif

0 comments on commit 63e0f3b

Please sign in to comment.