2002 2003 2004 2005 2006 <2007> 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 | Index | 2002 2003 2004 2005 2006 <2007> 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 |
<== Date ==> | <== Thread ==> |
---|
Subject: | lock ownership enforcement in OO design |
From: | "Jeff Hill" <[email protected]> |
To: | "'EPICS core-talk'" <[email protected]> |
Date: | Fri, 1 Jun 2007 14:41:30 -0600 |
All, To enforce mutex lock ownership, and allow lock overhead consolidation
in complex designs, currently many of my classes look like this. class Fred { public: Fred
( epicsMutex & mutex ) : _mutex ( mutex ) {} Void
doIt ( epicsGuard < epicsMutex > & guard, … ) { guard.assertIdenticalMutex
( _mutex ); } private: epicsMutex
& _mutex; }; I am considering this alternative. class Fred { public: Fred
( epicsMutex & mutex ) : _mutex ( mutex ) {} Void
doIt ( … ) { _mutex.assertOwnership (); } private: epicsMutex
& _mutex; }; Negatives: runtime instead of compile time detection Positives: Interfaces are simpler to look at, and more efficient
too (no passing of guard references) Neutral: With both approaches its much more obvious (compared
to no enforcement) that lock hierarchies are inverted when independently
developed codes call callbacks against each other. We can also remove detection
logic from optimized builds. Andrew has also suggested macros that eliminate guard
argument passing from optimized builds as a 3rd alternative. Wadayathink? Jeff |