Split out parts of scompare_loc_descriptor and emit_store_flag
[official-gcc.git] / libvtv / testsuite / libvtv.mt.cc / register_set_pair_inserts_mt.cc
blob6df197343f7da1d890157118847e8ed0e52c31a2
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <stdint.h>
4 #include <string.h>
6 #include "vtv_utils.h"
7 #include "vtv_rts.h"
8 #include "pthread.h"
11 /* Multi-threaded test for calls to RegisterPair */
13 /* This configuration will test mostly inserting of new elements since
14 the number of repeats is 1. It should also do a lot of rehashing */
16 /* This test case may fail depending on the system configuration.
17 Check the value of /proc/sys/vm/max_map_count and fix by doing
18 Ex: sudo sh -c "echo 131060 > /proc/sys/vm/max_map_count" */
20 #define NUM_MAPS 2000
21 #define ELEMENTS_PER_MAP 100
22 #define NUM_REPEATS 1
24 #define NUM_THREADS 9
26 #define KEY_TYPE_FIXED_SIZE 8
27 void *key_buffer = malloc (17);
28 typedef char * name_string;
29 name_string fake_names[NUM_MAPS];
31 /* This variable has to be put in rel.ro */
32 void * volatile maps[NUM_MAPS] VTV_PROTECTED_VAR;
34 struct fake_vt {
35 void * fake_vfp [4];
37 void * fake_vts [NUM_MAPS * ELEMENTS_PER_MAP];
39 volatile int current_map = -1;
40 volatile int threads_completed_it = 0;
42 void
43 generate_names (void)
45 int i;
47 for (i = 0; i < NUM_MAPS; ++i)
49 fake_names[i] = (char *) malloc (9 * sizeof (char));
50 snprintf (fake_names[i], 9, "name%d", i);
54 static uint32_t
55 vtv_string_hash(const char *in)
57 const char *s = in;
58 uint32_t h = 0;
60 for ( ; *s; ++s)
61 h = 5 * h + *s;
62 return h;
65 void * do_register_pairs(void *)
67 for (int k = 0; k < NUM_REPEATS; k++)
69 int curr_fake_vt = 0;
70 for (int i = 0; i < NUM_MAPS; i++)
72 uint32_t *value_ptr = (uint32_t *) key_buffer;
73 uint32_t len1 = strlen (fake_names[i]);
74 uint32_t hash_value = vtv_string_hash (fake_names[i]);
75 void *temp_array[ELEMENTS_PER_MAP];
77 while (current_map < (k*NUM_MAPS + i))
80 __VLTChangePermission(__VLTP_READ_WRITE);
82 *value_ptr = len1;
83 value_ptr++;
84 *value_ptr = hash_value;
86 memcpy ((char *) key_buffer + KEY_TYPE_FIXED_SIZE, fake_names[i],
87 len1);
90 #ifdef VTV_DEBUG
91 __VLTRegisterPairDebug ((void **) &maps[i], (char *) key_buffer, 128,
92 &fake_vts[curr_fake_vt], "", "");
93 #else
94 __VLTRegisterPair ((void **) &maps[i], (char *) key_buffer, 128,
95 &fake_vts[curr_fake_vt]);
96 #endif
97 for (int j = 0; j < ELEMENTS_PER_MAP; j++)
99 temp_array[j] = &fake_vts[curr_fake_vt];
100 curr_fake_vt++;
103 #ifdef VTV_DEBUG
104 __VLTRegisterSetDebug ((void **) &maps[i], (char *) key_buffer, 128, 100,
105 (void **) &temp_array);
106 #else
107 __VLTRegisterSet ((void **) &maps[i], (char *) key_buffer, 128, 100,
108 (void **) &temp_array);
109 #endif
110 __VLTChangePermission(__VLTP_READ_ONLY);
112 int old_value;
113 do {
114 old_value = threads_completed_it;
115 } while (!__sync_bool_compare_and_swap(&threads_completed_it, old_value, old_value + 1));
117 if (old_value == (NUM_THREADS - 1)) // Only one thread will do this.
119 threads_completed_it = 0;
120 printf("%c%d", 13, current_map + 1);
121 fflush(stdout);
122 current_map++;
127 return NULL;
131 int main()
133 pthread_t thread_ids[NUM_THREADS];
135 generate_names();
137 for (int t = 0; t < NUM_THREADS; t++ )
138 if (pthread_create(&thread_ids[t], NULL, do_register_pairs, NULL) != 0)
140 printf("failed pthread_create\n");
141 exit(1);
144 current_map = 0; // start the work on the other threads
146 for (int t = 0; t < NUM_THREADS; t++)
147 if (pthread_join(thread_ids[t], NULL) != 0)
149 printf("failed pthread_join\n");
150 exit(2);
153 printf("\n");
155 return 0;