File tree Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Expand file tree Collapse file tree 3 files changed +29
-5
lines changed Original file line number Diff line number Diff line change @@ -1541,6 +1541,8 @@ def _build_one(
1541
1541
not my_path_properties ['extra_objs_disable_baremetal_bootloader' ]
1542
1542
):
1543
1543
extra_objs .extend (extra_objs_baremetal_bootloader )
1544
+ if self .env ['mode' ] == 'userland' :
1545
+ cc_flags_after .extend (['-pthread' , LF ])
1544
1546
if self .need_rebuild ([in_path ] + extra_objs + extra_deps , out_path ):
1545
1547
cc_flags .extend (my_path_properties ['cc_flags' ])
1546
1548
cc_flags_after .extend (my_path_properties ['cc_flags_after' ])
Original file line number Diff line number Diff line change @@ -507,7 +507,6 @@ def get(path):
507
507
'proc_events.c' : {'requires_sudo' : True },
508
508
'sched_getaffinity.c' : {'requires_syscall_getcpu' : True },
509
509
'sched_getaffinity_threads.c' : {
510
- 'cc_flags_after' : ['-pthread' , LF ],
511
510
'more_than_1s' : True ,
512
511
'requires_syscall_getcpu' : True ,
513
512
},
Original file line number Diff line number Diff line change 16
16
#if __cplusplus >= 201103L
17
17
std::atomic_ulong my_atomic_ulong (0 );
18
18
unsigned long my_non_atomic_ulong = 0 ;
19
+ #if defined(__x86_64__)
20
+ unsigned long my_arch_atomic_ulong = 0 ;
21
+ unsigned long my_arch_non_atomic_ulong = 0 ;
22
+ #endif
19
23
size_t niters;
20
24
21
25
void threadMain () {
22
26
for (size_t i = 0 ; i < niters; ++i) {
23
27
my_atomic_ulong++;
24
28
my_non_atomic_ulong++;
29
+ #if defined(__x86_64__)
30
+ __asm__ __volatile__ (
31
+ " incq %0;"
32
+ : " +m" (my_arch_non_atomic_ulong)
33
+ :
34
+ :
35
+ );
36
+ __asm__ __volatile__ (
37
+ " lock;"
38
+ " incq %0;"
39
+ : " +m" (my_arch_atomic_ulong)
40
+ :
41
+ :
42
+ );
43
+ #endif
25
44
}
26
45
}
27
46
#endif
@@ -37,16 +56,20 @@ int main(int argc, char **argv) {
37
56
if (argc > 2 ) {
38
57
niters = std::stoull (argv[2 ], NULL , 0 );
39
58
} else {
40
- niters = 1000 ;
59
+ niters = 10000 ;
41
60
}
42
61
std::vector<std::thread> threads (nthreads);
43
62
for (size_t i = 0 ; i < nthreads; ++i)
44
63
threads[i] = std::thread (threadMain);
45
64
for (size_t i = 0 ; i < nthreads; ++i)
46
65
threads[i].join ();
47
66
assert (my_atomic_ulong.load () == nthreads * niters);
48
- // Same as above through `operator T`.
49
- assert (my_atomic_ulong == nthreads * niters);
50
- std::cout << my_non_atomic_ulong << std::endl;
67
+ // We can also use the atomics direclty through `operator T` conversion.
68
+ assert (my_atomic_ulong == my_atomic_ulong.load ());
69
+ std::cout << " my_non_atomic_ulong " << my_non_atomic_ulong << std::endl;
70
+ #if defined(__x86_64__)
71
+ assert (my_arch_atomic_ulong == nthreads * niters);
72
+ std::cout << " my_arch_non_atomic_ulong " << my_arch_non_atomic_ulong << std::endl;
73
+ #endif
51
74
#endif
52
75
}
You can’t perform that action at this time.
0 commit comments