[Lldb-commits] [lldb] r252031 - Add a few useful methods to ThreadSafeDense{Map, Set}. Not used yet.
Jim Ingham via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 3 17:48:39 PST 2015
We had a few uses of it back before it actually had any mutex at all and that only caused very infrequent crashes - usually on teardown. So not very much contended, and probably a RWMutex is overkill.
But it might be useful for the general class. I'm in the middle of other things right now, and don't want to get side-tracked.
Jim
> On Nov 3, 2015, at 5:43 PM, Zachary Turner <zturner at google.com> wrote:
>
> Seems like this class would be a good candidate for using an RWMutex. Any reason you can think of why that wouldn't work?
>
> On Tue, Nov 3, 2015 at 5:41 PM Jim Ingham via lldb-commits <lldb-commits at lists.llvm.org> wrote:
> Author: jingham
> Date: Tue Nov 3 19:39:05 2015
> New Revision: 252031
>
> URL: http://llvm.org/viewvc/llvm-project?rev=252031&view=rev
> Log:
> Add a few useful methods to ThreadSafeDense{Map,Set}. Not used yet.
>
> Modified:
> lldb/trunk/include/lldb/Core/ThreadSafeDenseMap.h
> lldb/trunk/include/lldb/Core/ThreadSafeDenseSet.h
>
> Modified: lldb/trunk/include/lldb/Core/ThreadSafeDenseMap.h
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ThreadSafeDenseMap.h?rev=252031&r1=252030&r2=252031&view=diff
> ==============================================================================
> --- lldb/trunk/include/lldb/Core/ThreadSafeDenseMap.h (original)
> +++ lldb/trunk/include/lldb/Core/ThreadSafeDenseMap.h Tue Nov 3 19:39:05 2015
> @@ -54,7 +54,27 @@ public:
> Mutex::Locker locker(m_mutex);
> return m_map.lookup(k);
> }
> -
> +
> + bool
> + Lookup (_KeyType k,
> + _ValueType& v)
> + {
> + Mutex::Locker locker(m_mutex);
> + auto iter = m_map.find(k),
> + end = m_map.end();
> + if (iter == end)
> + return false;
> + v = iter->second;
> + return true;
> + }
> +
> + void
> + Clear ()
> + {
> + Mutex::Locker locker(m_mutex);
> + m_map.clear();
> + }
> +
> protected:
> LLVMMapType m_map;
> Mutex m_mutex;
>
> Modified: lldb/trunk/include/lldb/Core/ThreadSafeDenseSet.h
> URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Core/ThreadSafeDenseSet.h?rev=252031&r1=252030&r2=252031&view=diff
> ==============================================================================
> --- lldb/trunk/include/lldb/Core/ThreadSafeDenseSet.h (original)
> +++ lldb/trunk/include/lldb/Core/ThreadSafeDenseSet.h Tue Nov 3 19:39:05 2015
> @@ -55,6 +55,13 @@ namespace lldb_private {
> return (m_set.count(e) > 0);
> }
>
> + void
> + Clear ()
> + {
> + Mutex::Locker locker(m_mutex);
> + m_set.clear();
> + }
> +
> protected:
> LLVMSetType m_set;
> Mutex m_mutex;
>
>
> _______________________________________________
> lldb-commits mailing list
> lldb-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
More information about the lldb-commits
mailing list