Can I use <stdatomic.h> from C11 in Linux driver, or do I must to use Linux functions of memory-barriers?

c, driver, gcc, kernel, linux-kernel

Solution

If you are writing kernel code, you should do it in C, and do it in the version of C required by the current kernel (shipping gcc). If you want to get it accepted into mainline (or write it as if it were going to get accepted), you should use the Linux functions. You will also find that they work without unexpected surprises, and you will get better debugging help.

Summary: use the linux functions.

Problem

Can I use `#include <stdatomic.h>` and `atomic_thread_fence()` with `memory_order` from C11 in Linux driver (kernel-space), or do I must to use Linux functions of memory-barriers: - http://lxr.free-electrons.com/source/Documentation/memory-barriers.txt - http://lxr.free-electrons.com/source/Documentation/atomic_ops.txt Using: - Linux-kernel 2.6.18 or greater - GCC 4.7.2 or greater

Original source