Click
Loading...
Searching...
No Matches
machine.hh
1#ifndef CLICK_MACHINE_HH
2#define CLICK_MACHINE_HH 1
3#if CLICK_LINUXMODULE
4# include <click/cxxprotect.h>
5CLICK_CXX_PROTECT
6# include <linux/threads.h>
7# include <linux/sched.h>
8# if defined(CONFIG_SMP) && LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
9# define num_possible_cpus() smp_num_cpus
10# endif
11CLICK_CXX_UNPROTECT
12# include <click/cxxunprotect.h>
13#endif
14
19inline void
20click_compiler_fence()
21{
22 asm volatile("" : : : "memory");
23}
24
28inline void
29click_relax_fence()
30{
31#if CLICK_LINUXMODULE
32 cpu_relax();
33#elif HAVE_MULTITHREAD && (defined(__i386__) || defined(__arch_um__) || defined(__x86_64__))
34 asm volatile("rep; nop" : : : "memory"); // equivalent to "pause"
35#else
36 click_compiler_fence();
37#endif
38}
39
41inline void
42click_fence()
43{
44#if CLICK_LINUXMODULE
45 smp_mb();
46#elif HAVE_MULTITHREAD && (defined(__i386__) || defined(__arch_um__) || defined(__x86_64__))
47 // GCC 4.2.1 on Mac has __sync_synchronize, but it doesn't work!
48 asm volatile("mfence" : : : "memory");
49#elif HAVE_MULTITHREAD && HAVE___SYNC_SYNCHRONIZE
50 __sync_synchronize();
51#else
52 click_compiler_fence();
53#endif
54}
55
59inline void click_read_fence() {
60#if CLICK_LINUXMODULE
61 smp_rmb();
62#elif HAVE_MULTITHREAD && (defined(__i386__) || defined(__arch_um__) || defined(__x86_64__))
63 click_compiler_fence();
64#else
65 click_fence();
66#endif
67}
68
72inline void click_write_fence() {
73#if CLICK_LINUXMODULE
74 smp_wmb();
75#elif HAVE_MULTITHREAD && (defined(__i386__) || defined(__arch_um__) || defined(__x86_64__))
76 click_compiler_fence();
77#else
78 click_fence();
79#endif
80}
81
82#endif