Don't unlock when locking failed in the timer thread

Authored by mwolff on Apr 24 2018, 2:20 PM.

Description

Don't unlock when locking failed in the timer thread

Fixes an issue found by helgrind:

29171== Thread #2 unlocked lock at 0x242A60 currently held by thread #1

29171== at 0x4C30156: mutex_unlock_WRK (hg_intercepts.c:1086)

29171== by 0x4C33ACC: pthread_mutex_unlock (hg_intercepts.c:1107)

29171== by 0x2005B9: __gthread_mutex_unlock(pthread_mutex_t*) (gthr-default.h:778)

29171== by 0x203493: std::mutex::unlock() (std_mutex.h:121)

29171== by 0x200C78: (anonymous namespace)::HeapTrack::~HeapTrack() (libheaptrack.cpp:309)

29171== by 0x2016C8: (anonymous namespace)::HeapTrack::LockedData::LockedData(_IO_FILE*, void (*)())::{lambda()#1}::operator()() const (libheaptrack.cpp:631)

29171== by 0x202DD0: void std::invoke_impl<void, (anonymous namespace)::HeapTrack::LockedData::LockedData(_IO_FILE*, void (*)())::{lambda()#1}>(std::invoke_other, (anonymous namespace)::HeapTrack::LockedData::LockedData(_IO_FILE*, void (*)())::{lambda()#1}&&) (invoke.h:60)

Use an exception to get out of the constructor to prevent
the destructor from being called which would always unlock
the mutex, even if the timer thread didn't get the lock itself.

Details

Committed
mwolffApr 24 2018, 2:20 PM
Parents
R45:03f534bd31b9: Make it easily possible to use a mutex for locking internally
Branches
Unknown
Tags
Unknown