Update.
authorUlrich Drepper <drepper@redhat.com>
Sat, 15 Feb 2003 10:32:02 +0000 (10:32 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sat, 15 Feb 2003 10:32:02 +0000 (10:32 +0000)
* tst-mutex3.c (do_test): Add tests for trylock with RECURSIVE mutexes.

nptl/ChangeLog
nptl/tst-mutex3.c

index de93173..1dc5f23 100644 (file)
@@ -1,5 +1,7 @@
 2003-02-15  Ulrich Drepper  <drepper@redhat.com>
 
+       * tst-mutex3.c (do_test): Add tests for trylock with RECURSIVE mutexes.
+
        * sysdeps/unix/sysv/linux/pthread_kill.c (__pthread_kill): Don't
        use INLINE_SYSCALL.  Error number is returned, not -1.
 
index c6c75ca..c45637b 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
 
 #include <errno.h>
 #include <pthread.h>
 #include <stdio.h>
+#include <stdlib.h>
+
+
+static pthread_mutex_t m;
+
+
+static void *
+tf (void *arg)
+{
+  int e = pthread_mutex_trylock (&m);
+  if (e == 0)
+    {
+      puts ("mutex_trylock in second thread succeeded");
+      exit (1);
+    }
+  if (e != EBUSY)
+    {
+      puts ("mutex_trylock returned wrong value");
+      exit (1);
+    }
+
+  return NULL;
+}
 
 
 static int
 do_test (void)
 {
-  pthread_mutex_t m;
   pthread_mutexattr_t a;
 
   if (pthread_mutexattr_init (&a) != 0)
@@ -58,6 +80,12 @@ do_test (void)
       return 1;
     }
 
+  if (pthread_mutex_trylock (&m) != 0)
+    {
+      puts ("1st trylock failed");
+      return 1;
+    }
+
   if (pthread_mutex_unlock (&m) != 0)
     {
       puts ("mutex_unlock failed");
@@ -70,6 +98,25 @@ do_test (void)
       return 1;
     }
 
+  pthread_t th;
+  if (pthread_create (&th, NULL, tf, NULL) != 0)
+    {
+      puts ("create failed");
+      return 1;
+    }
+
+  if (pthread_join (th, NULL) != 0)
+    {
+      puts ("join failed");
+      return 1;
+    }
+
+  if (pthread_mutex_unlock (&m) != 0)
+    {
+      puts ("3rd mutex_unlock failed");
+      return 1;
+    }
+
   if (pthread_mutex_destroy (&m) != 0)
     {
       puts ("mutex_destroy failed");