summaryrefslogtreecommitdiffstats
path: root/man2/membarrier.2
diff options
context:
space:
mode:
Diffstat (limited to 'man2/membarrier.2')
-rw-r--r--man2/membarrier.250
1 files changed, 25 insertions, 25 deletions
diff --git a/man2/membarrier.2 b/man2/membarrier.2
index 1df4249b5..eeb52f6de 100644
--- a/man2/membarrier.2
+++ b/man2/membarrier.2
@@ -319,9 +319,9 @@ following code (x86) can be transformed using
.\" SRC BEGIN (membarrier.c)
.EX
#include <stdlib.h>
-
+\&
static volatile int a, b;
-
+\&
static void
fast_path(int *read_b)
{
@@ -329,7 +329,7 @@ fast_path(int *read_b)
asm volatile ("mfence" : : : "memory");
*read_b = b;
}
-
+\&
static void
slow_path(int *read_a)
{
@@ -337,29 +337,29 @@ slow_path(int *read_a)
asm volatile ("mfence" : : : "memory");
*read_a = a;
}
-
+\&
int
main(void)
{
int read_a, read_b;
-
+\&
/*
* Real applications would call fast_path() and slow_path()
* from different threads. Call those from main() to keep
* this example short.
*/
-
+\&
slow_path(&read_a);
fast_path(&read_b);
-
+\&
/*
* read_b == 0 implies read_a == 1 and
* read_a == 0 implies read_b == 1.
*/
-
+\&
if (read_b == 0 && read_a == 0)
abort();
-
+\&
exit(EXIT_SUCCESS);
}
.EE
@@ -378,37 +378,37 @@ becomes:
#include <unistd.h>
#include <sys/syscall.h>
#include <linux/membarrier.h>
-
+\&
static volatile int a, b;
-
+\&
static int
membarrier(int cmd, unsigned int flags, int cpu_id)
{
return syscall(__NR_membarrier, cmd, flags, cpu_id);
}
-
+\&
static int
init_membarrier(void)
{
int ret;
-
+\&
/* Check that membarrier() is supported. */
-
+\&
ret = membarrier(MEMBARRIER_CMD_QUERY, 0, 0);
if (ret < 0) {
perror("membarrier");
return \-1;
}
-
+\&
if (!(ret & MEMBARRIER_CMD_GLOBAL)) {
fprintf(stderr,
"membarrier does not support MEMBARRIER_CMD_GLOBAL\en");
return \-1;
}
-
+\&
return 0;
}
-
+\&
static void
fast_path(int *read_b)
{
@@ -416,7 +416,7 @@ fast_path(int *read_b)
asm volatile ("" : : : "memory");
*read_b = b;
}
-
+\&
static void
slow_path(int *read_a)
{
@@ -424,32 +424,32 @@ slow_path(int *read_a)
membarrier(MEMBARRIER_CMD_GLOBAL, 0, 0);
*read_a = a;
}
-
+\&
int
main(int argc, char *argv[])
{
int read_a, read_b;
-
+\&
if (init_membarrier())
exit(EXIT_FAILURE);
-
+\&
/*
* Real applications would call fast_path() and slow_path()
* from different threads. Call those from main() to keep
* this example short.
*/
-
+\&
slow_path(&read_a);
fast_path(&read_b);
-
+\&
/*
* read_b == 0 implies read_a == 1 and
* read_a == 0 implies read_b == 1.
*/
-
+\&
if (read_b == 0 && read_a == 0)
abort();
-
+\&
exit(EXIT_SUCCESS);
}
.EE