diff options
author | unknown <serg@serg.mylan> | 2006-06-17 16:20:39 +0200 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2006-06-17 16:20:39 +0200 |
commit | d1fb292251fc6ba5a455e39d59dad5f7d0d0023f (patch) | |
tree | 1ed4d5cf639665eb2901d57998183b18637eab1a /unittest | |
parent | 0d8d39c8c6ff44e54e0b7869c7497e79ff4d697f (diff) | |
download | mariadb-git-d1fb292251fc6ba5a455e39d59dad5f7d0d0023f.tar.gz |
atomic ops:
my_atomic_XX_t -> intXX, no implicit locking anymore
simplified framework, support for requested cleanups
dbug/dbug.c:
compiler warning
include/atomic/nolock.h:
my_atomic_XX_t -> intXX
include/atomic/rwlock.h:
my_atomic_XX_t -> intXX, no implicit locking anymore
include/atomic/x86-gcc.h:
my_atomic_XX_t -> intXX, no implicit locking anymore
include/atomic/x86-msvc.h:
my_atomic_XX_t -> intXX
simplified defines
support for cleanups
include/my_atomic.h:
my_atomic_XX_t -> intXX, no implicit locking anymore
simplified framework, support for requested cleanups
unittest/examples/no_plan-t.c:
compiler warning
unittest/mysys/Makefile.am:
fix for dependencies
unittest/mysys/my_atomic-t.c:
my_atomic_XX_t -> intXX, no implicit locking anymore
unittest/mytap/tap.c:
cosmetic fix
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/examples/no_plan-t.c | 6 | ||||
-rw-r--r-- | unittest/mysys/Makefile.am | 8 | ||||
-rw-r--r-- | unittest/mysys/my_atomic-t.c | 70 | ||||
-rw-r--r-- | unittest/mytap/tap.c | 4 |
4 files changed, 59 insertions, 29 deletions
diff --git a/unittest/examples/no_plan-t.c b/unittest/examples/no_plan-t.c index 98e4d06def6..a40b46dc278 100644 --- a/unittest/examples/no_plan-t.c +++ b/unittest/examples/no_plan-t.c @@ -14,8 +14,8 @@ tests are skipped for an unknown reason. */ int main() { - ok(1, NULL); - ok(1, NULL); - ok(1, NULL); + ok(1, " "); + ok(1, " "); + ok(1, " "); return exit_status(); } diff --git a/unittest/mysys/Makefile.am b/unittest/mysys/Makefile.am index b1e0356bac6..8e6255b9e68 100644 --- a/unittest/mysys/Makefile.am +++ b/unittest/mysys/Makefile.am @@ -2,10 +2,10 @@ AM_CPPFLAGS = @ZLIB_INCLUDES@ -I$(top_builddir)/include AM_CPPFLAGS += -I$(top_srcdir)/include -I$(top_srcdir)/unittest/mytap -AM_LDFLAGS = -L$(top_builddir)/unittest/mytap -L$(top_builddir)/mysys -AM_LDFLAGS += -L$(top_builddir)/strings -L$(top_builddir)/dbug - -LDADD = -lmytap -lmysys -ldbug -lmystrings +LDADD = $(top_builddir)/unittest/mytap/libmytap.a \ + $(top_builddir)/mysys/libmysys.a \ + $(top_builddir)/dbug/libdbug.a \ + $(top_builddir)/strings/libmystrings.a noinst_PROGRAMS = bitmap-t base64-t my_atomic-t diff --git a/unittest/mysys/my_atomic-t.c b/unittest/mysys/my_atomic-t.c index 8a3fe129b07..71408ce957f 100644 --- a/unittest/mysys/my_atomic-t.c +++ b/unittest/mysys/my_atomic-t.c @@ -14,13 +14,12 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include <tap.h> - #include <my_global.h> +#include <tap.h> #include <my_sys.h> #include <my_atomic.h> -my_atomic_32_t a32,b32,c32; +int32 a32,b32,c32; my_atomic_rwlock_t rwl; pthread_attr_t thr_attr; @@ -36,8 +35,13 @@ pthread_handler_t test_atomic_add_handler(void *arg) for (x=((int)(&m)); m ; m--) { x=x*m+0x87654321; - my_atomic_add32(&a32, x, &rwl); - my_atomic_add32(&a32, -x, &rwl); + my_atomic_rwlock_wrlock(&rwl); + my_atomic_add32(&a32, x); + my_atomic_rwlock_wrunlock(&rwl); + + my_atomic_rwlock_wrlock(&rwl); + my_atomic_add32(&a32, -x); + my_atomic_rwlock_wrunlock(&rwl); } pthread_mutex_lock(&mutex); N--; @@ -57,17 +61,33 @@ pthread_handler_t test_atomic_add_handler(void *arg) pthread_handler_t test_atomic_swap_handler(void *arg) { int m=*(int *)arg; - uint32 x=my_atomic_add32(&b32, 1, &rwl); + int32 x; + + my_atomic_rwlock_wrlock(&rwl); + x=my_atomic_add32(&b32, 1); + my_atomic_rwlock_wrunlock(&rwl); - my_atomic_add32(&a32, x, &rwl); + my_atomic_rwlock_wrlock(&rwl); + my_atomic_add32(&a32, x); + my_atomic_rwlock_wrunlock(&rwl); for (; m ; m--) - x=my_atomic_swap32(&c32, x,&rwl); + { + my_atomic_rwlock_wrlock(&rwl); + x=my_atomic_swap32(&c32, x); + my_atomic_rwlock_wrunlock(&rwl); + } if (!x) - x=my_atomic_swap32(&c32, x,&rwl); + { + my_atomic_rwlock_wrlock(&rwl); + x=my_atomic_swap32(&c32, x); + my_atomic_rwlock_wrunlock(&rwl); + } - my_atomic_add32(&a32, -x, &rwl); + my_atomic_rwlock_wrlock(&rwl); + my_atomic_add32(&a32, -x); + my_atomic_rwlock_wrunlock(&rwl); pthread_mutex_lock(&mutex); N--; @@ -82,14 +102,25 @@ pthread_handler_t test_atomic_swap_handler(void *arg) */ pthread_handler_t test_atomic_cas_handler(void *arg) { - int m=*(int *)arg; - int32 x; + int m=*(int *)arg, ok; + int32 x,y; for (x=((int)(&m)); m ; m--) { - uint32 y=my_atomic_load32(&a32, &rwl); + my_atomic_rwlock_wrlock(&rwl); + y=my_atomic_load32(&a32); + my_atomic_rwlock_wrunlock(&rwl); + x=x*m+0x87654321; - while (!my_atomic_cas32(&a32, &y, y+x, &rwl)) ; - while (!my_atomic_cas32(&a32, &y, y-x, &rwl)) ; + do { + my_atomic_rwlock_wrlock(&rwl); + ok=my_atomic_cas32(&a32, &y, y+x); + my_atomic_rwlock_wrunlock(&rwl); + } while (!ok); + do { + my_atomic_rwlock_wrlock(&rwl); + ok=my_atomic_cas32(&a32, &y, y-x); + my_atomic_rwlock_wrunlock(&rwl); + } while (!ok); } pthread_mutex_lock(&mutex); N--; @@ -103,9 +134,9 @@ void test_atomic(const char *test, pthread_handler handler, int n, int m) pthread_t t; ulonglong now=my_getsystime(); - my_atomic_store32(&a32, 0, &rwl); - my_atomic_store32(&b32, 0, &rwl); - my_atomic_store32(&c32, 0, &rwl); + a32= 0; + b32= 0; + c32= 0; diag("Testing %s with %d threads, %d iterations... ", test, n, m); for (N=n ; n ; n--) @@ -116,8 +147,7 @@ void test_atomic(const char *test, pthread_handler handler, int n, int m) pthread_cond_wait(&cond, &mutex); pthread_mutex_unlock(&mutex); now=my_getsystime()-now; - ok(my_atomic_load32(&a32, &rwl) == 0, - "tested %s in %g secs", test, ((double)now)/1e7); + ok(a32 == 0, "tested %s in %g secs", test, ((double)now)/1e7); } int main() diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index 2b728670cea..d3f5013b4c9 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -199,8 +199,8 @@ int exit_status() { if (g_test.plan != g_test.last) { - diag("%d tests planned but only %d executed", - g_test.plan, g_test.last); + diag("%d tests planned but%s %d executed", + g_test.plan, (g_test.plan > g_test.last ? " only" : ""), g_test.last); return EXIT_FAILURE; } |