From: Bart Van Assche Date: Tue, 21 Jul 2009 16:35:48 +0000 (+0000) Subject: Added more error checking. X-Git-Tag: svn/VALGRIND_3_5_0~337 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=76f381d299126b57bf5d1726c1cac87323fc7839;p=thirdparty%2Fvalgrind.git Added more error checking. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@10511 --- diff --git a/drd/tests/rwlock_test.c b/drd/tests/rwlock_test.c index b8dcf471f4..f7cc33c4ba 100644 --- a/drd/tests/rwlock_test.c +++ b/drd/tests/rwlock_test.c @@ -10,11 +10,30 @@ #include #include +#include // strerror() + + +#define PTH_CALL(expr) \ + do \ + { \ + int err = (expr); \ + if ((err) != 0) \ + { \ + fprintf(stderr, \ + "%s:%d %s returned error code %d (%s)\n", \ + __FILE__, \ + __LINE__, \ + #expr, \ + err, \ + strerror(err)); \ + } \ + } while (0) static pthread_rwlock_t s_rwlock; static int s_counter; + static void* thread_func(void* arg) { int i; @@ -22,12 +41,12 @@ static void* thread_func(void* arg) for (i = 0; i < 1000; i++) { - pthread_rwlock_rdlock(&s_rwlock); + PTH_CALL(pthread_rwlock_rdlock(&s_rwlock)); sum += s_counter; - pthread_rwlock_unlock(&s_rwlock); - pthread_rwlock_wrlock(&s_rwlock); + PTH_CALL(pthread_rwlock_unlock(&s_rwlock)); + PTH_CALL(pthread_rwlock_wrlock(&s_rwlock)); s_counter++; - pthread_rwlock_unlock(&s_rwlock); + PTH_CALL(pthread_rwlock_unlock(&s_rwlock)); } return 0; @@ -39,15 +58,15 @@ int main(int argc, char** argv) pthread_t tid[thread_count]; int i; - pthread_rwlock_init(&s_rwlock, NULL); + PTH_CALL(pthread_rwlock_init(&s_rwlock, NULL)); for (i = 0; i < thread_count; i++) { - pthread_create(&tid[i], 0, thread_func, 0); + PTH_CALL(pthread_create(&tid[i], 0, thread_func, 0)); } for (i = 0; i < thread_count; i++) { - pthread_join(tid[i], 0); + PTH_CALL(pthread_join(tid[i], 0)); } fprintf(stderr, "Finished.\n");