3 #include <Poco/Exception.h>
4 #include <Poco/SharedPtr.h>
38 template <
typename LockType,
typename ID,
typename Hash =
typename ID::Hash>
41 typedef LockType Lock;
42 typedef Poco::SharedPtr<HashedLock<Lock, ID, Hash>> Ptr;
66 Lock &
find(
const ID &
id);
71 Lock &
at(
const unsigned int index);
76 unsigned int size()
const;
79 void assureInitialized();
82 std::vector<Lock> m_lock;
85 template <
typename Lock,
typename ID,
typename Hash>
91 template <
typename Lock,
typename ID,
typename Hash>
97 template <
typename Lock,
typename ID,
typename Hash>
101 throw Poco::InvalidArgumentException(
102 "HashedLock must be initialized by non-zero count of locks");
105 if (m_lock.empty()) {
106 m_lock = std::vector<Lock>(count);
109 throw Poco::InvalidAccessException(
110 "delayedInit() can be called only once");
114 template <
typename Lock,
typename ID,
typename Hash>
120 const unsigned int index = hash(
id) % size();
124 template <
typename Lock,
typename ID,
typename Hash>
128 return m_lock[index];
131 template <
typename Lock,
typename ID,
typename Hash>
134 return m_lock.size();
137 template <
typename Lock,
typename ID,
typename Hash>
140 if (m_lock.empty()) {
141 throw Poco::IllegalStateException(
142 "HashedLock has not been initialized yet");
unsigned int size() const
Definition: HashedLock.h:132
Lock & at(const unsigned int index)
Definition: HashedLock.h:125
HashedLock()
Definition: HashedLock.h:86
Definition: HashedLock.h:39
Lock & find(const ID &id)
Definition: HashedLock.h:115
void delayedInit(unsigned int count)
Definition: HashedLock.h:98