From: Julian Seward Date: Fri, 11 Mar 2011 19:10:48 +0000 (+0000) Subject: NB: this is an temporary fix, until such time as bug 243935 is fully X-Git-Tag: svn/VALGRIND_3_7_0~604 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=159af3e3ee4b4f61b65e717da71e75d46a9df9d8;p=thirdparty%2Fvalgrind.git NB: this is an temporary fix, until such time as bug 243935 is fully resolved. Add a client request, ANNOTATE_HAPPENS_BEFORE_FORGET_ALL, to notify Helgrind that it can forget about any h-b edges previously associated with the specified tag, and release associated resources. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11625 --- diff --git a/helgrind/helgrind.h b/helgrind/helgrind.h index 23eb4b70e6..cbe09002eb 100644 --- a/helgrind/helgrind.h +++ b/helgrind/helgrind.h @@ -108,7 +108,7 @@ typedef _VG_USERREQ__HG_CLIENTREQ_UNIMP, /* char* */ _VG_USERREQ__HG_USERSO_SEND_PRE, /* arbitrary UWord SO-tag */ _VG_USERREQ__HG_USERSO_RECV_POST, /* arbitrary UWord SO-tag */ - _VG_USERREQ__HG_RESERVED1, /* Do not use */ + _VG_USERREQ__HG_USERSO_FORGET_ALL, /* arbitrary UWord SO-tag */ _VG_USERREQ__HG_RESERVED2, /* Do not use */ _VG_USERREQ__HG_RESERVED3, /* Do not use */ _VG_USERREQ__HG_RESERVED4, /* Do not use */ @@ -458,6 +458,20 @@ typedef See also, extensive discussion on semantics of this in https://bugs.kde.org/show_bug.cgi?id=243935 + + ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) is interim until such time + as bug 243935 is fully resolved. It instructs Helgrind to forget + about any ANNOTATE_HAPPENS_BEFORE calls on the specified object, in + effect putting it back in its original state. Once in that state, + a use of ANNOTATE_HAPPENS_AFTER on it has no effect on the calling + thread. + + An implementation may optionally release resources it has + associated with 'obj' when ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) + happens. Users are recommended to use + ANNOTATE_HAPPENS_BEFORE_FORGET_ALL to indicate when a + synchronisation object is no longer needed, so as to avoid + potential indefinite resource leaks. ---------------------------------------------------------------- */ #define ANNOTATE_HAPPENS_BEFORE(obj) \ @@ -466,6 +480,8 @@ typedef #define ANNOTATE_HAPPENS_AFTER(obj) \ DO_CREQ_v_W(_VG_USERREQ__HG_USERSO_RECV_POST, void*,(obj)) +#define ANNOTATE_HAPPENS_BEFORE_FORGET_ALL(obj) \ + DO_CREQ_v_W(_VG_USERREQ__HG_USERSO_FORGET_ALL, void*,(obj)) /* ---------------------------------------------------------------- Memory publishing. The TSan sources say: diff --git a/helgrind/hg_main.c b/helgrind/hg_main.c index 74f78fb575..a09e18c17a 100644 --- a/helgrind/hg_main.c +++ b/helgrind/hg_main.c @@ -3021,17 +3021,16 @@ static SO* map_usertag_to_SO_lookup_or_alloc ( UWord usertag ) { } } -// If it's ever needed (XXX check before use) -//static void map_usertag_to_SO_delete ( UWord usertag ) { -// UWord keyW, valW; -// map_usertag_to_SO_INIT(); -// if (VG_(delFromFM)( map_usertag_to_SO, &keyW, &valW, usertag )) { -// SO* so = (SO*)valW; -// tl_assert(keyW == usertag); -// tl_assert(so); -// libhb_so_dealloc(so); -// } -//} +static void map_usertag_to_SO_delete ( UWord usertag ) { + UWord keyW, valW; + map_usertag_to_SO_INIT(); + if (VG_(delFromFM)( map_usertag_to_SO, &keyW, &valW, usertag )) { + SO* so = (SO*)valW; + tl_assert(keyW == usertag); + tl_assert(so); + libhb_so_dealloc(so); + } +} static @@ -3090,6 +3089,21 @@ void evh__HG_USERSO_RECV_POST ( ThreadId tid, UWord usertag ) libhb_so_recv( thr->hbthr, so, True/*strong_recv*/ ); } +static +void evh__HG_USERSO_FORGET_ALL ( ThreadId tid, UWord usertag ) +{ + /* TID declares that any happens-before edges notionally stored in + USERTAG can be deleted. If (as would normally be the case) a + SO is associated with USERTAG, then the assocation is removed + and all resources associated with SO are freed. Importantly, + that frees up any VTSs stored in SO. */ + if (SHOW_EVENTS >= 1) + VG_(printf)("evh__HG_USERSO_FORGET_ALL(ctid=%d, usertag=%#lx)\n", + (Int)tid, usertag ); + + map_usertag_to_SO_delete( usertag ); +} + /*--------------------------------------------------------------*/ /*--- Lock acquisition order monitoring ---*/ @@ -4505,6 +4519,11 @@ Bool hg_handle_client_request ( ThreadId tid, UWord* args, UWord* ret) evh__HG_USERSO_RECV_POST( tid, args[1] ); break; + case _VG_USERREQ__HG_USERSO_FORGET_ALL: + /* UWord arbitrary-SO-tag */ + evh__HG_USERSO_FORGET_ALL( tid, args[1] ); + break; + default: /* Unhandled Helgrind client request! */ tl_assert2(0, "unhandled Helgrind client request 0x%lx",