]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libvtv/testsuite/register_pair_mt.cc
7 /* Multi-threaded test for calls to RegisterPair */
9 /* This configuration will test mostly inserting of elements that are already inserted since
10 the number of repeats is 10 */
12 /* This test case may fail depending on the system configuration.
13 Check the value of /proc/sys/vm/max_map_count and fix by doing
14 Ex: sudo sh -c "echo 131060 > /proc/sys/vm/max_map_count" */
17 #define ELEMENTS_PER_MAP 100
18 #define NUM_REPEATS 10
22 /* This variable has to be put in rel.ro */
23 void * volatile maps
[NUM_MAPS
] VTV_PROTECTED_VAR
;
28 void * fake_vts
[NUM_MAPS
* ELEMENTS_PER_MAP
];
30 volatile int current_map
= -1;
31 volatile int threads_completed_it
= 0;
33 void * do_register_pairs(void *)
35 for (int k
= 0; k
< NUM_REPEATS
; k
++)
38 for (int i
= 0; i
< NUM_MAPS
; i
++)
40 while (current_map
< (k
*NUM_MAPS
+ i
))
43 __VLTChangePermission(__VLTP_READ_WRITE
);
45 for (int j
= 0; j
< ELEMENTS_PER_MAP
; j
++)
48 __VLTRegisterPair((void **) &maps
[i
], &fake_vts
[curr_fake_vt
], 0, 0, 0, 0);
50 __VLTRegisterPair((void **) &maps
[i
], &fake_vts
[curr_fake_vt
]);
52 __VLTVerifyVtablePointer((void **) &maps
[i
], &fake_vts
[curr_fake_vt
]);
56 __VLTChangePermission(__VLTP_READ_ONLY
);
60 old_value
= threads_completed_it
;
61 } while (!__sync_bool_compare_and_swap(&threads_completed_it
, old_value
, old_value
+ 1));
63 if (old_value
== (NUM_THREADS
- 1)) // Only one thread will do this.
65 threads_completed_it
= 0;
66 printf("%c%d", 13, current_map
+ 1);
79 pthread_t thread_ids
[NUM_THREADS
];
81 for (int t
= 0; t
< NUM_THREADS
; t
++ )
82 if (pthread_create(&thread_ids
[t
], NULL
, do_register_pairs
, NULL
) != 0)
84 printf("failed pthread_create\n");
88 current_map
= 0; // start the work on the other threads
90 for (int t
= 0; t
< NUM_THREADS
; t
++)
91 if (pthread_join(thread_ids
[t
], NULL
) != 0)
93 printf("failed pthread_join\n");