summaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorVladislav Vaintroub <vvaintroub@linux-rbsx>2009-12-19 03:21:49 +0100
committerVladislav Vaintroub <vvaintroub@linux-rbsx>2009-12-19 03:21:49 +0100
commit106bb1652ed8918ee580e0aa83d59bf46053f7e9 (patch)
tree9ccfada701764a2476975250d029acbe812b12b1 /unittest
parent27c0d595e9e3a35232672209219ecc9b74004ab4 (diff)
parent4e8d1c6bf30abfd45a993b058ff2a33d4671b73d (diff)
downloadmariadb-git-106bb1652ed8918ee580e0aa83d59bf46053f7e9.tar.gz
merge
Diffstat (limited to 'unittest')
-rw-r--r--unittest/mysys/my_atomic-t.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/unittest/mysys/my_atomic-t.c b/unittest/mysys/my_atomic-t.c
index 1a558e8cb73..9853d3cf964 100644
--- a/unittest/mysys/my_atomic-t.c
+++ b/unittest/mysys/my_atomic-t.c
@@ -48,6 +48,34 @@ pthread_handler_t test_atomic_add(void *arg)
return 0;
}
+volatile int64 a64;
+/* add and sub a random number in a loop. Must get 0 at the end */
+pthread_handler_t test_atomic_add64(void *arg)
+{
+ int m= (*(int *)arg)/2;
+ GCC_BUG_WORKAROUND int64 x;
+ for (x= ((int64)(intptr)(&m)); m ; m--)
+ {
+ x= (x*m+0xfdecba987654321LL) & INT_MAX64;
+ my_atomic_rwlock_wrlock(&rwl);
+ my_atomic_add64(&a64, x);
+ my_atomic_rwlock_wrunlock(&rwl);
+
+ my_atomic_rwlock_wrlock(&rwl);
+ my_atomic_add64(&a64, -x);
+ my_atomic_rwlock_wrunlock(&rwl);
+ }
+ pthread_mutex_lock(&mutex);
+ if (!--running_threads)
+ {
+ bad= (a64 != 0);
+ pthread_cond_signal(&cond);
+ }
+ pthread_mutex_unlock(&mutex);
+ return 0;
+}
+
+
/*
1. generate thread number 0..N-1 from b32
2. add it to bad
@@ -128,7 +156,7 @@ pthread_handler_t test_atomic_cas(void *arg)
void do_tests()
{
- plan(4);
+ plan(6);
bad= my_atomic_initialize();
ok(!bad, "my_atomic_initialize() returned %d", bad);
@@ -142,5 +170,14 @@ void do_tests()
b32= c32= 0;
test_concurrently("my_atomic_cas32", test_atomic_cas, THREADS, CYCLES);
+ {
+ int64 b=0x1000200030004000LL;
+ a64=0;
+ my_atomic_add64(&a64, b);
+ ok(a64==b, "add64");
+ }
+ a64=0;
+ test_concurrently("my_atomic_add64", test_atomic_add64, THREADS, CYCLES);
+
my_atomic_rwlock_destroy(&rwl);
}