1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-08-02 17:09:26 +02:00

Make const overload of ClientData::Site::ForEach usable

This commit is contained in:
Paul Licameli 2019-07-09 16:01:43 -04:00
parent 36cb2918be
commit d8b3d16554
2 changed files with 9 additions and 4 deletions

View File

@ -416,7 +416,12 @@ private:
{ {
return Locked< DataContainer >{ mData }; return Locked< DataContainer >{ mData };
} }
Locked<const DataContainer> GetData() const
{
return Locked< const DataContainer >{ mData };
}
static void EnsureIndex( Locked<DataContainer> &data, size_t index ) static void EnsureIndex( Locked<DataContainer> &data, size_t index )
{ {
if (data.mObject.size() <= index) if (data.mObject.size() <= index)

View File

@ -57,19 +57,19 @@ template< typename Object > struct Lockable< Object, NoLocking >
: Object { : Object {
// implement trivial non-locking policy // implement trivial non-locking policy
struct Lock{}; struct Lock{};
Lock lock() { return {}; } Lock lock() const { return {}; }
}; };
template< typename Object > struct Lockable< Object, NonrecursiveLocking > template< typename Object > struct Lockable< Object, NonrecursiveLocking >
: Object, std::mutex { : Object, std::mutex {
// implement real locking // implement real locking
using Lock = std::unique_lock< std::mutex >; using Lock = std::unique_lock< std::mutex >;
Lock lock() { return Lock{ *this }; } Lock lock() const { return Lock{ *this }; }
}; };
template< typename Object > struct Lockable< Object, RecursiveLocking > template< typename Object > struct Lockable< Object, RecursiveLocking >
: Object, std::recursive_mutex { : Object, std::recursive_mutex {
// implement real locking // implement real locking
using Lock = std::unique_lock< std::recursive_mutex >; using Lock = std::unique_lock< std::recursive_mutex >;
Lock lock() { return Lock{ *this }; } Lock lock() const { return Lock{ *this }; }
}; };
// Pairing of a reference to a Lockable and a lock on it // Pairing of a reference to a Lockable and a lock on it