From: Julian Seward Date: Sun, 28 Nov 2004 02:58:11 +0000 (+0000) Subject: Rewrite ensure_valgrind() in a slightly less stupid way. This X-Git-Tag: svn/VALGRIND_3_0_0~1187 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c41cd6b5bf51f4eb820c33a0ece918793367ff8;p=thirdparty%2Fvalgrind.git Rewrite ensure_valgrind() in a slightly less stupid way. This 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 --- diff --git a/coregrind/vg_libpthread.c b/coregrind/vg_libpthread.c index 3ae688faa5..0a9dc423f9 100644 --- a/coregrind/vg_libpthread.c +++ b/coregrind/vg_libpthread.c @@ -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