]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fixed the sem test to work on systems with semtimedop.
authorTom Hughes <tom@compton.nu>
Mon, 14 Jun 2004 12:33:43 +0000 (12:33 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 14 Jun 2004 12:33:43 +0000 (12:33 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2414

configure.in
none/tests/sem.c

index e83ff8f8b2191944010123b6d014282ebfb53f5d..fc4e7b01e420113996eba3c66dc34ba5459b50c5 100644 (file)
@@ -345,7 +345,7 @@ AC_FUNC_MEMCMP
 AC_FUNC_MMAP
 AC_TYPE_SIGNAL
 
-AC_CHECK_FUNCS([floor memchr memset mkdir strchr strdup strpbrk strrchr strstr])
+AC_CHECK_FUNCS([floor memchr memset mkdir strchr strdup strpbrk strrchr strstr semtimedop])
 
 AC_OUTPUT(
    Makefile 
index 4e26b369f447f1e1b0f97b131062a4750f0394ca..3eddaffda5b9e56fb349f89756879d43ca92994e 100644 (file)
@@ -6,6 +6,56 @@
 #include <sys/ipc.h>
 #include <sys/sem.h>
 
+#ifndef HAVE_SEMTIMEDOP
+
+#include <signal.h>
+#include <sys/time.h>
+
+static int semtimedop(int  semid, struct sembuf *sops, unsigned nsops,
+                      struct timespec *timeout)
+{
+   struct sigaction act;
+   struct sigaction oldact;
+   struct itimerval itv;
+   int rv;
+
+   act.sa_handler = SIG_IGN;
+   sigemptyset( &act.sa_mask );
+   act.sa_flags = 0;
+   
+   if (sigaction(SIGALRM, &act, &oldact) < 0)
+   {
+      perror("sigaction");
+      exit(1);
+   }
+   
+   itv.it_interval.tv_sec = 0;
+   itv.it_interval.tv_usec = 0;
+   itv.it_value.tv_sec = timeout->tv_sec;
+   itv.it_value.tv_usec = timeout->tv_nsec / 1000;
+   
+   if (setitimer(ITIMER_REAL, &itv, NULL) < 0)
+   {
+      perror("setitimer");
+      exit(1);
+   }
+   
+   if ((rv = semop(semid, sops, nsops)) < 0 && errno == EINTR)
+   {
+      errno = EAGAIN;
+   }
+
+   if (sigaction(SIGALRM, &oldact, NULL) < 0)
+   {
+      perror("sigaction");
+      exit(1);
+   }
+   
+   return rv;
+}
+
+#endif
+
 int main(int argc, char **argv)
 {
    int semid;