]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Rewrite ensure_valgrind() in a slightly less stupid way. This
authorJulian Seward <jseward@acm.org>
Sun, 28 Nov 2004 02:58:11 +0000 (02:58 +0000)
committerJulian Seward <jseward@acm.org>
Sun, 28 Nov 2004 02:58:11 +0000 (02:58 +0000)
significantly reduces the number of client requests made by programs
which make intensive use of the pthread_ functions, such as
OpenOffice.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3131

coregrind/vg_libpthread.c

index 3ae688faa52ba08ec8bc29ae98b3ce0bfa6cf6b3..0a9dc423f99cf5afebe69e00e2b766d01d0434d4 100644 (file)
@@ -248,14 +248,30 @@ int get_pt_trace_level ( void )
 }
 
 /* Don't do anything if we're not under Valgrind */
+/* Optimisation (?) 28 Nov 04: assume that once we establish
+   yes/no, the situation does not change, and so only one 
+   client request is ever needed.
+*/
 static __inline__
 void ensure_valgrind ( char* caller )
 {
-   if (!RUNNING_ON_VALGRIND) {
-      const char msg[] = "Warning: this libpthread.so should only be run with Valgrind\n";
+   /* 0: unknown   1: running on V   2: not running on V */
+   static Int status = 0; 
+
+  again:
+   /* common case */
+   if (status == 1) 
+      return;
+
+   if (status == 2) {
+      const char msg[] = "Error: this libpthread.so should "
+                         "only be run with Valgrind\n";
       VG_(do_syscall)(__NR_write, 2, msg, sizeof(msg)-1);
       VG_(do_syscall)(__NR_exit, 1);
    }
+   
+   status = (RUNNING_ON_VALGRIND) ? 1 : 2;
+   goto again;
 }
 
 /* While we're at it ... hook our own startup function into this