]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/valgrind/src/valgrind-3.6.0-svn/drd/tests/annotate_static.cpp
update
[l4.git] / l4 / pkg / valgrind / src / valgrind-3.6.0-svn / drd / tests / annotate_static.cpp
1 // Test for ANNOTATE_BENIGN_RACE_STATIC() and ANNOTATE_UNPROTECTED_READ().
2
3
4 #include <pthread.h> /* pthread_create() */
5 #include <stdio.h>   /* fprintf() */
6 #include "../../drd/drd.h"
7
8
9 /* Local variables. */
10
11 static int s_i;
12 static volatile int s_j;
13
14 ANNOTATE_BENIGN_RACE_STATIC(s_i, "Benign because duplicate assignment.");
15
16
17 /* Local functions. */
18
19 static inline void AnnotateIgnoreReadsBegin() { ANNOTATE_IGNORE_READS_BEGIN(); }
20 static inline void AnnotateIgnoreReadsEnd() { ANNOTATE_IGNORE_READS_END(); }
21
22 static void* thread_func(void*)
23 {
24 #if defined(__powerpc__) && __GNUC__ -0 == 4 && __GNUC_MINOR__ -0 == 3 \
25     && __GNUC_PATCHLEVEL__ -0 == 0
26   AnnotateIgnoreReadsBegin();
27   int i = s_j;
28   AnnotateIgnoreReadsEnd();
29   s_i = i;
30 #else
31   s_i = ANNOTATE_UNPROTECTED_READ(s_j);
32 #endif
33   return 0;
34 }
35
36 int main(int argc, char** argv)
37 {
38   pthread_t tid;
39
40   pthread_create(&tid, 0, thread_func, NULL);
41   s_j++;
42   s_i = s_j;
43   pthread_join(tid, NULL);
44
45   fprintf(stderr, "Done.\n");
46
47   return 0;
48 }